Monday, January 21, 2013

How to send SOAP headers in BizTalk

How to send SOAP headers in BizTalk

Here are the steps to set SOAP headers in a web service request using BizTalk Server 2004 (BTS).

1. Make sure your web reference in your BTS project is up to date.

2. Open the Reference.xsd for the wsdl of the web service. Look for the name of the root node for their Soap Header. Here is the example I'm using...

<AuthenticationHeader xmlns="">

3. Copy the name. Close the file.

4. Create a new item for the BTS project. Select "Property Schema" NOT the regular schema.
- In the properties for <schema>,
Change the target NameSpace to
- In the properties for the root node,
Rename the root node the same as the one is step 2 ("AuthenticationHeader")
Change the Property Schema Base drop-down to "MessageContextPropertyBase"

5. Save the file as "SoapHeader.xsd" and Close the file. (Update: It doesn't matter what the name is as long as the TYPE NAME property of the xsd file is not the same as the root node name. Otherwise, you'll run into a compilation error)

6. Go to your orchestration. There should be a Construct Message shape that creates the web service request. There should be a shape inside of it - either a Transform or a Message Assignment.
If it is a Transform, add a Message Assignment below that in the SAME Construct Message shape.
If it is a Message Assignment, do nothing as we will reuse the existing one.

7. Edit the Message Assignment from step 6 and add the following as one line....

SampleWS_Request_Msg(MyBizTalkProject.AuthenticationHeader) =
"<ns0:AuthenticationHeader xmlns:ns0=\"\">

- "SampleWS_Request_Msg" is the message variable name in the Orchestration for the external web service.
- "MyBizTalkProject" is your project name
- "AuthenticationHeader" is the name of the property schema

Note: Once you type the message name and the first parentheses "SampleWS_Request_Msg(" an intellisense drop-down list appears and the property schema you are looking for should appear.

Note 2: There is another option to use an existing SOAP header from another message, but I had to use this approach as the incoming message was a Flat File.
Note 3: If you are using SOAP over standard HTTP, please keep in mind that the above message contents (including SOAP Header) can be clearly viewed by others monitoring internet traffic. I don't advocate this as a security measure

No comments:

Post a Comment