Turning mustUnderstand validation off in BizTalk WCF Adapters

select_ext.png
Specifying a behavior extension in WCF-CustomIsolated adapter

On a recent project I worked on we had to relay some SOAP messages between two systems using BizTalk Server 2006 R2. These messages had some custom SOAP headers with the mustUnderstand attribute set to "1". This poses a problem for BizTalk when using the WCF adapters. The WCF-BasicHttp receive adapter raises a System.ServiceModel.MustUnderstandSoapException exception and the processing of the message in BizTalk halts.

After a bit of looking around online I managed to find a decent workaround for this problem by the usage of custom WCF behavior extensions. There is an article in MSDN about using them in BizTalk. The idea was to write a behavior extension that disables mustUnderstand validation in the ports where the extension is specified to be used.



The code for the needed behavior extension element is very simple:

using System;
using System.ServiceModel.Configuration;
using System.ServiceModel.Description;

namespace TTO.WCFBehaviorExtensions
{
    public class MustUnderstandValidationOffElement : BehaviorExtensionElement
    {
        protected override object CreateBehavior()
        {
            return new MustUnderstandBehavior(false);
        }

        public override Type BehaviorType
        {
            get
            {
                return typeof(MustUnderstandBehavior);
            }
        }
    }
}
The point where the mustUnderstand validation is turned off is when a new MustUnderstandBehavior object is returned from the CreateBehavior() method. The boolean argument given to the constructor of the MustUnderstandBehavior class specifies whether the validation takes place.
 
The behavior extension element is installed by first signing the assembly containing the class and installing it to GAC. Next, you have to add a line to the machine.config file (in \Microsoft.NET\Framework\\CONFIG), under the behaviorExtensions part of the configuration:
    ... 
The "name" attribute will be visible in the BizTalk Administration console. The "type" attribute is the strong name of the assembly containing the extension class. You may have to restart the process running the receive location or send port to make the new extension visible in the port configuration.
 
The behavior extension can be used with WCF-Custom adapters. In the Behavior tab of the adapter configuration right-click EndpointBehavior, select "Add extension..." and select the right extension from the list. Now the headers with the mustUnderstand attribute set to "1" should flow through BizTalk with no problems.
 
2010-07-07 Kalle Huttunen

 

 
BizTalk® is a registered trademark of Microsoft Corporation.