Neuron ESB User Network

The Service Bus for the Connected Business

Generate SOAP request with authentication info in SOAP header

This may be a basic obvious question, but what is the best approach to building a new SOAP request to send to a service connector built from an imported service?

For example, I would typically just import the service into a WCF project and call the methods generated in the reference api to build a request. Does anything similarly get generated within Neuron, or would we manually construct the message in a process step setting the http and soap headers and body? 

thanks.

Marc

Views: 624

Reply to This

Replies to This Discussion

Hi Marc,

you don't "create" a soap request.  you just set the body of the esb message. its pretty rare when you need to manually set the esb message's SOAP properties.  usually you only do that if you want to read or write custom soap headers. The configuration of the service connector sets all the necessary soap headers for the WS* standards...

you can use the import wizard and import the service into Neuron to create the service connector....then its your responsibility to send in the correct message and set the correct action property to call the method you want.

you should've been taught this during training that was conducted.  you should go through the web service tutorial found here: http://www.neuronesb.com/user-training/NeuronWebServices.zip

Thanks Marty.

yes, we were showed importing a service during the training - in this scenario I'm getting in a REST msg and sending out SOAP request with the REST msg body. I've looked over the RESTtoSOAP demo and it makes sense. - just wanted to be sure we didn't go down the wrong path if there were other ways to do it.

Only thing that's still fuzzy is setting multiple namespaces in the SOAP header for an authentication element we need to add (see below) - I don't quite understanding the syntax when adding with context.Data.Soap.Headers.Add(key, value) regarding namespaces, for example if I wanted to create the following:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Header>
       <h:UserCredentials
               xmlns:h="https://myendpoint.com/webapi/"
               xmlns="https://myendpoint.com/webapi/"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:xsd="http://www.w3.org/2001/XMLSchema">
             <Account>myaccountname</Account>
             <AccountPassword>mypassword</AccountPassword>
       </h:UserCredentials>
    </s:Header>

thanks.

Marc

I think you can pass only one.  Not sure if custom headers in SOAP support multiple namespaces...joe can find out though.  It looks like in your sample though that the elements only reference one of the namespaces

Marc,

This header should be syntactically the same:

   <s:Header>
       <UserCredentials xmlns="https://myendpoint.com/webapi/">
             <Account>myaccountname</Account>
             <AccountPassword>mypassword</AccountPassword>
       </UserCredentials>
    </s:Header>

The reason it's the same is because the namespace with prefix "h" is the same as the default namespace, and the other two namespace prefixes are not used at all.  Can you try this one?

Joe

Thanks Joe. I noticed that as well after, guessing my WCF test request is adding the other namespaces, but are unnecessary.  The only remaining issue I am having is passing the XML element nodes as children as my header key value. Having the same issue when I try the SOAP Header sample solution as well.

If I set the key/value as such:

string header = "https://dev.myendpoint.com/webapi/" + "/" + "UserCredentials";
string credentials = "<Account>myacconut</Account>";
context.Data.Soap.Headers.Add(header, credentials);

The XML element <Account> is ignored in this case:
<s:Header>

   <UserCredentials xmlns="https://dev.accumedic.com/accuwebapi/">myacconut</UserCredentials>


If I try to create the nodes using XmlDocument, and pass as it's toString as key value into Headers.Add( .. ),
the entire custom UserCredentials header element is ignored and not added.

the Sample shows passing it in as the first way, simply a string:

string header = "http://www.neuronesb.com/samples/soapheaders" + "/" + "NeuronMessageIdHeader";
string messageIdHeader = "<MessageId>" + context.Data.Header.MessageId + "</MessageId>";

context.Data.Soap.Headers.Add(header, messageIdHeader);



What is the correct syntax we should be using?


thanks.
Marc

Hi Joe,

Looks like my previous post got a bit garbled in format. The issue is basically creating child XML elements within the header element. When setting the value for the header key using the Context.Data.Soap.Headers.Add(key,value) method, as the Neuron SOAP Headers Sample solution shows, the XML nodes look like they are ignored when examining the resulting message.

So, 

string header = "https://dev.accumedic.com/accuwebapi/" + "/" + "UserCredentials";

string credentials = "<Account>myaccount</Account>";

context.Data.Soap.Headers.Add(header, credentials);

the resulting message is missing the <Account> nodes.

<UserCredentials xmlns="https://dev.accumedic.com/accuwebapi/">myaccount</UserCredentials>

Any ideas?

thanks

Marc

Marc,

You'll need to set the XML to the whole XML value.  Under the covers Neuron will replace whatever root value you provide with the last part of the namespace you use.  To make life easier I always make them the same :)

Your code should be (also, you had an extra forward slash in your namespace...)

string header = "https://dev.accumedic.com/accuwebapi" + "/" + "UserCredentials";

string credentials = <UserCredentials>"<Account>myaccount</Account></UserCredentials>";

context.Data.Soap.Headers.Add(header, credentials);

Thanks Joe!

Understood. I noticed though if I do not put 2 forward slashes the ending slash gets removed from the namespace. So I end up with:

<UserCredentials xmlns="https://dev.accumedic.com/accuwebapi">

apparently this web service I'm calling is looking for the trailing slash. With 2 slashes one remains and fixes it.

But, I did also notice that I need to explicitly set a default namespace for each child element, otherwise it sets a default namespace as blank and the child elements no longer inherit the default namespace.of the parent node. So I get:

<Account xmlns="">myaccount</Account>

Explicitly setting it for each child node fixes the issue though, just checking if this is intended functionality.

thanks

Marc

RSS

Neuron ESB Product Support Forums and Communities

Latest Activity

Anupama Nair posted a discussion

Marketo Adapter Invalid Token

Hi,We are using the Marketo adapter to push account updates to Marketo. It works well for some time then starts failing with Invalid Token unless restarted. Is there a configuration that can be done so it can auto refresh the token when required?Thanks!See More
Nov 6, 2023
Sayantini Basak posted a discussion

Maximum payload size(REST API) for requests interfacing to NeuronESB

I am new to Neuron ESB and in our current scenario,We need to process batch transactions comprising of ~1000 records and send them to Neuron ESB for further processing. I would like to understand what is the maximum size of payload that can be transferred using REST interface to Neuron ESB.See More
Jul 22, 2022
Profile IconRobert E Dunie and Sayantini Basak joined Neuron ESB User Network
Apr 28, 2022
Profile IconDayanand, Frederic C, Steffen Greve-Oksfeldt and 1 more joined Neuron ESB User Network
Mar 16, 2022
Profile IconCam Vong and Mitja Luznar joined Neuron ESB User Network
Jan 27, 2022
Profile IconWill Hitzges, Chad Parsons, michael larsen and 4 more joined Neuron ESB User Network
Jun 11, 2021
Anupama Nair posted a discussion

ODBC stored proc polling with temporary tables

We have set up an ODBC adapter to poll a stored proc.We found that if the stored proc has a temporary table defined the rows returned are always 0.Any idea why this would be and what we can do to get around it?See More
Dec 14, 2020
Prasanth Kharade is now a member of Neuron ESB User Network
Dec 30, 2019

Badge

Loading…

© 2024   Created by Neuron Admin.   Powered by

Badges  |  Report an Issue  |  Terms of Service