112417_1021_Authenticat1.png

Setting custom SOAP headers in the WCF adapter

While browsing for the answer to the question: “How do I add SOAP-headers to a message sent using the WCF-custom or WCF-basicHttp adapter?” I never really found a good, short answer. So I thought I’d give it a go.

Setting SOAP headers

I assume you know what SOAP-headers are and why you might use them. If not, then back to basics.

In my case the client needed BizTalk to send requests with the WS-addressing SOAP header called “To”. I needed to know the easiest way to do this and preferably using configuration and no orchestrations.

To the best of my knowledge, this is the simplest way to do it.

Using a pipeline

Use a pipeline component to promote this property: http://schemas.microsoft.com/BizTalk/2006/01/Adapters/WCF-properties#OutboundCustomHeaders.

My guess is that your local BizTalk-code hub already have a pipeline component to promote arbitrary values. If you do not, the code for promoting the property is here.

The only thing to remember is that the value of the property is a bit special. You can hard code the values of your headers, even using xml-formatting; no problem, but you have to surround the value with a <headers> tag.

<headers> 
<h:To xmlns:h="http://www.w3.org/2005/08/addressing">rcvAddr</h:To>
</headers>

This will result in the WCF adapter serializing a SOAP envelope with SOAP headers that contains the value you give between the <headers> tag.

Here is the result in my environment:

image

Using an orchestration

If you already have an orchestration, and want to side-step the age old rule about not mixing the process (orchestration) from the communication (a port), you can set the headers from code. A bit more information can be found here.

What you basically do is setting the property from an assignment shape, much like you would access a FILE.RecieveFileName.

outboundMessageInstance(WCF.OutboundCustomHeaders) = 
"<headers><add:To xmlns:add="http://www.w3.org/2005/08/addressing">rcvAddr</h:To></headers>"

A limitation

Note that this is a promoted message property. This means that you can assign a string with the maximum length of 255. If you need to set a more elaborate header you need to use a message inspector and write your own code. It is a bit tricky but not that hard. Perhaps I will write a post about that some day.

112417_1021_Authenticat1.png

BtsWcfServicePublishing and support for .net Framework 4

I guess you, like me, use the BtsWcfServicePublishing.exe to automate the deployment process for your wcf-hosting needs in BizTalk. If you don’t I think you should, as it saves you a lot of time. For one you don’t have to regenerate your endpoint information using the BtsWcfServicePublishingWizard (note: not the same program as the BtsWcfServicePublishing) and all it’s tedious steps every single time you update a service.

The thing is that when you use the BtsWcfServicePublishing.exe on a BizTalk-assembly built using BizTalk 2010 you get an error like this:

Error publishing WCF service.
Could not load file or assembly ‘file:///C:\Windows\Microsoft.NET\assembly\GAC_MSIL\…’ or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

This is due to the fact that the BtsWcfServicePublishing tries to use version 2.0 of the .net framework. To make it work on BizTalk 2010 assemblies add the following info in the configuration file (just under the configuration-tag.

<startup>
   <supportedRuntime version=”v4.0″ />
</startup>

Just run it again and you’ll be happy as Larry.