Ricardo Marques from Codit wrote a fantastic blog post a few years ago about dynamically setting HTTP headers for the WCF-WebHttp adapter using dynamic send ports in BizTalk Server based on the WCF.HttpHeaders context property. At the end of the article he stated that static send ports would not respect this context property, and this statement is the topic of this blog post.

Let me start by saying that I personally dislike dynamic send ports. It’s not that I don’t like the idea behind them, it’s more that I dislike the implementation (I won’t go into my reasons today). Wherever possible I will seek a way to enforce dynamic behavior on a static send port instead, and I have found a way to do this for dynamic HTTP headers.

The trick is super easy. All you need to do is set the BTS.IsDynamicSend context property value to true on the message before it gets processed by your WCF-WebHttp send adapter in order for it to respect the values in your WCF.HttpHeaders context property without losing access to all the other configuration you have set up on the static send port. I’ve extended the example provided in Ricardo’s original post below to illustrate how you set the context properties.

    public Microsoft.BizTalk.Message.Interop.IBaseMessage Execute(IPipelineContext pContext, Microsoft.BizTalk.Message.Interop.IBaseMessage pInMsg)
        // Some non important logic here

        pInMsg.Context.Write("HttpHeaders", "http://schemas.microsoft.com/BizTalk/2006/01/Adapters/WCF-properties", "content-type: application/atom+xml");
        pInMsg.Context.Write("IsDynamicSend", "http://schemas.microsoft.com/BizTalk/2003/system-properties", true);
        return pInMsg;

The inspiration to try this context property came from my colleague James’ blog post. His post was written regarding BizTalk 2009 so it’s good to see that Microsoft have been consistent about the usage of this context property even with the latest adapters. Thanks to both Ricardo and James for your good write-ups 🙂