Sometimes there may arise a need where some of the custom headers that are specified in the WCF message are needed for routing purposes in BizTalk. Lets take an example, Say the client sends a message with a custom header which specifies the node in a ring to which the message has to be routed to. Let this header be ‘RingRouteTo’. Now if you want to enable routing based on this header, this has to be promoted to the BizTalk message context.
Some background on how headers & properties are dealt with in WCF adapter:
1. All headers are written to the BTS message context.
2. Some of the well-known headers are always promoted. e.g. “To”, “Action”
3. All the properties with ‘http://schemas.microsoft.com/BizTalk/2006/01/Adapters/WCF-properties/Promote’ namespace are promoted.
To promote custom headers to BTS message context, we will make use of point (3). In a custom message inspector, we will read the specified header and then add it as a property with the namespace specified above. We will also need to deploy the custom property schema which has the promoted
properties in BizTalk.
Of course, you will need to use WCF-Custom adapter in order to use this behavior.
Attached is the code to achieve the same.
PS : Once you build and deploy the attached BizTalk project, the property appears as ‘Microsoft.BizTalk.Adapter.Wcf.CustomPromotedProperty.PropertySchema.RingRouteTo’ in BizTalk.\
When adding the header while sending the message using client, you can use any namespace for ‘RingRouteTo’.