Ralph Romero

Blog

Adding Custom WCF Headers Outbound from Biztalk

Posted at — Dec 11, 2020

You may have written a WCF client calling a SOAP service with some custom headers and are wondering how to the same thing in Biztalk. I’ll explain how to map what you would do in C# with how to implement it in Biztalk.

Starting with a sample C# client

var xmlns = "http://www.myns.com";
var usn = "myusername";
var pw = "mypassword";
var userHeader = MessageHeader.CreateHeader("Username", ns: xmlns, value: usn);
var pwHeader = MessageHeader.CreateHeader("Password", ns: xmlns, value: pw);
OperationContext.Current.OutgoingMessageHeaders.Add(userHeader);
OperationContext.Current.OutgoingMessageHeaders.Add(pwHeader);

Create the following XML

<headers>
    <Username xmlns="http://www.myns.com">myusername</Username>
    <Password xmlns="http://www.myns.com">mypassword</Password>
</headers>

The headers element is static and case sensitive so don’t touch it. If you compare the C# code with the XML, you can see how you need to create an XML element per call to CreateHeader.

Then in your Biztalk orchestration within a message assignment shape where you construct your message request, assign this XML to the following written property like this.

RequestMessage(WCF.OutboundCustomHeaders) = "<headers><Username xmlns=\"http://www.myns.com\">myusername</Username><Password xmlns=\"http://www.myns.com\">mypassword</Password></headers>";

You should now have the correct headers in the outbound message. If you still encounter any problems, you can use Fiddler to inspect the message.