WCF OutboundCustomHeaders and the BizTalk ServiceBus Adapter

For a hybrid scenario I’m currently working on, using onsite-WCF services and Azure Service Bus, it was necessary to have the WCF Headers from the original call available as Brokered Message Properties in Azure Service Bus.

We created a SB-Messaging port to send the message to Azure Service Bus and added the WCF Namespace (http://schemas.microsoft.com/BizTalk/2006/01/Adapters/WCF-properties) in the Brokered Message Properties window.

20140904_sb-messagin-transport-properties

We quickly ran into following issue:

The adapter failed to transmit message going to send port “SpBlog” with URL “sb://coditblogdemo.servicebus.windows.net/demo”. It will be retransmitted after the retry interval specified for this Send Port. Details:”System.InvalidOperationException: Envelope Version ‘EnvelopeNone ( http://schemas.microsoft.com/ws/2005/05/envelope/none)’ does not support adding Message Headers.

20140904_Exception_500x85.jpg

At first I tought this error was related to the fact that we added the WCF Namespace in the Brokered Message Properties window, but even if we removed the WCF namespace, the error still occurred.

In fact we noticed that from the moment the WCF.OutboundCustomHeaders is in the context of the message this error occurs on the SB-Messaging port.

Cause

Looking at the stack trace it seems that the SB-Messaging adapter is built on top of the BizTalk WCF Adapter runtime. Which makes perfect sense. The only downside here is that the SB-Messaging adapter acts the same as the WCF adapter when it comes to the OutboundCustomHeaders property.
When using the WCF adapter and adding the WCF.OutboundCustomHeaders to the context, the value of this property gets added to the SOAP:Header of the outgoing message and that is exactly what is also happening with the SB-Messaging adapter. Let’s call it a hidden feature in the SB-Messaging adapter.

Solution

The solution for this problem was fairly simple and straight forward. We created a custom pipeline component: ‘Context Copier” that copies the value of the OutboundCustomHeaders property to another context property. After assigning the value to the new context property we write null to the OutboundCustomHeaders context property. That way the OutBoundCustomHeaders is removed from the context.

Off course this is only the basic outline of the component. In our ‘Context Copier’ we added the possibility to add a source and destination list of properties that need to be copied. But the basic outline below will already solve the issue of the OutboundCustomHeaders when sending to Service Bus.

 

20140904_Solution_500x123.jpg

After adding this pipeline component to our Send Pipeline, the issue was resolved and we could happily continue integration with Service Bus!

Cheers,

Glenn

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s