Friday, January 21, 2005

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...

<soap:Header>
<AuthenticationHeader xmlns="http://www.acme.com/WebService/">
<strUserName>string</UserName>
<strPassword>string</Password>
</AuthenticationHeader>
</soap:Header>



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 http://schemas.microsoft.com/BizTalk/2003/SOAPHeader
- 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=\"http://www.acme.com/WebService/\">
<ns0:UserName>MyName</ns0:UserName>
<ns0:Password>NotSoSecretPassword</ns0:Password>
</ns0:AuthenticationHeader>";

Where
- "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 - but since this is not my web service, I have to play along.

4 comments:

Neal said...

In step 4, you say to rename the root node. I was following your example to learn more about SOAP Headers and property schemas, and from what I can see there is no root node in a property schema. You cannot create a hierarchy?

code.munki.9 said...

Thanks a lot, bro. You're the man! This little piece of info was the hardest to find - the MSDN articles on the same are so vague that they are almost completely useless!

muthuvel said...

Hai,
Its working fine.But I have to send soap header to webservice with out using orchestration.
can u tell me the steps for that.

Anonymous said...

Thanks for sharing the info.