Dynamic WCF-HttpHeaders for WCF WebHttp adapter
This solution describe how dynamically we can change the WCF-HttpHeaders for WCF-WebHTTP adapter. In our project, there is a need to dynamically change the HttpHeaders content-type to "text/html" and "application/gzip". The response messages are send on the same port, so we need to construct the message with the proper content-type.
During investigation of why the WCF-WebHTTP adapter cannot dynamically switch content type we discovered and we found that BizTalk 2013 servers that have been upgraded from BizTalk 2010 are missing some of the new global properties. Look at the below screen of WCF.WCFPropertySchema the property HttpHeaders do not exist. While it is available in the Orchestration, but when we use it, it do not work. We cannot change the HttpHeaders on messages.
We have raised this with Microsoft already, we created WCF behavior extension as a work around to solve this problem.
This WCF behavior extension was made for the WCF-WebHTTP restful adapter. The adapter (receive location), the response message http header could only be set from the adapter and applied to all messages. The adapter ignored the system context property WCF.HttpHeaders. This behavior extension reads the WCF.HttpHeaders context and adds it to the response message.
From the below screen you can see the WCF.HttpHeaders, we assign "Content-Type=application/gzip\r\nuser-agent: BizTalk Server 2013"
There is no behavior extension
There is no HTTP Headers on the port.
The response from BizTalk is below, there is no "Content-Type=application/gzip\r\nuser-agent: BizTalk Server 2013". It is using the default values.
To fix this issue follow the below steps:
1- Download the WCF behavior extension code from
Compile and Gac the dll.
2- Change the machine.config (for both 32 and 64 bit) with the below:
<add name="AddHttpHeaderContextBehavior" type="BT.Common.Behaviors.AddHttpHeaderContext.AddHttpHeaderContextBehaviorExtensionElement, BT.Common.Behaviors.AddHttpHeaderContext, Version=22.214.171.124, Culture=neutral, PublicKeyToken=f122d7b786bb0156″/>
Also, you can create Wix installer package to GAC and change the machine.config file mention in here.
3- Go to the Receive/Send Port, open for WCF-WebHttp transport properties. Open Behavior Tab. Right click on EndPointBehavior, add the extension "AddHttpHeaderContextBehavior".
4- Run the test again, below is the response from BT.
The HttpHeaders "Content-Type=application/gzip\r\nuser-agent: BizTalk Server 2013" is added to the header response message.