How to Configure the BAM WCF Interception

To configure BAM for WCF interception, you must modify the interceptor configuration file to access the proper assembly manifest for your event sources.

When you are configuring the events you must specify properly formatted XPath expressions for the actions.

You can create properly formatted XPath expressions to use in the interceptor configuration by enabling WCF tracing and running the application to produce a sample WCF log which contains the message. You can use the Microsoft Service Trace Viewer (SvcTraceViewer.exe) to view the log and extract the message. The viewer is included with the WCF SDK. The desired XPath expression can then be formed based on the message and applied to the interceptor configuration.

When configuring the BAM WCF interception, it is essential that the behavior extension used in the machine.config file matches the extension used in the custom behavior configuration of the receive location. Changing the extension name of a configured receive location in the machine.config file causes the behavior to fail to load. In addition, the configuration UI of the receive location will fail.

In case of a clustered scenario, since the custom behavior is configured only once, you must ensure that all the machine.config files on the computers in the cluster specify the same file name extension.

To set the manifest

  1. Set the manifest in the EventSource in the Interception Configuration to 'Microsoft.BizTalk.Adapter.Wcf.Runtime.ITwoWayAsyncVoid, Microsoft.BizTalk.Adapter.Wcf.Runtime, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

    Note

    The interface changes based on the type of service/receive port used. Change the manifest line to reflect the type of port you are using according to the table below.

    Port Type Use
    Two-way ports ITwoWayAsync
    One-way ports with binding that are inherently two 2 way (for example, HTTP). ITwoWayAsyncVoid
    One-way ports with binding that are inherently two two-way with transactions. ITwoWayAsyncVoidTxn
    Bindings that are one way (for example, MSMQ). IOneWayAsync
    Bindings that are one way with transactions. IOneWayAsyncTxn

    Important

    In the filter, instead of using the GetOperationName operation, use XPath operation as highlighted in the following sample. For generic contracts all messages arrive at some generic operation, at which point they get routed to specific operations based on the message itself (Action attribute).

  2. The operation name will always be the same at this point. In case of WCF adapters (which uses generic contracts) the method used is BizTalkSubmit. You can use an XPath for the Action node instead of GetOperationName to retrieve the operation name. You can then filter on the operation name.

Sample Interceptor Configurations

This sample shows the usage of ServiceRequest and ServiceReply for the WCF adapter. In the highlighted section an XPath expression on the Action is used to filter on the operation instead of using GetOperationName. You can filter on the reply as well, but only in the case of ITwoWayAsync. All other interfaces return nothing or void.

ServiceRequest

<ic:OnEvent IsBegin="true" IsEnd ="false" Name ="WCFServiceRequest" Source="WCFService">  
      <ic:Filter>  
        <ic:Expression>  
          <wcf:Operation Name="GetServiceContractCallPoint"/>  
          <ic:Operation Name ="Constant">  
            <ic:Argument>ServiceRequest</ic:Argument>  
          </ic:Operation>  
          <ic:Operation Name ="Equals" />  
          <wcf:Operation Name ="XPath">  
            <wcf:Argument>//s:Header/a:Action</wcf:Argument>  
          </wcf:Operation>  
          <ic:Operation Name ="Constant">  
            <ic:Argument>Operation1</ic:Argument>  
          </ic:Operation>  
          <ic:Operation Name ="Equals" />  
          <ic:Operation Name ="And" />  
        </ic:Expression>  
      </ic:Filter>  
  
      <ic:CorrelationID>  
        <ic:Expression>  
          <wcf:Operation Name="AutoGenerateCorrelationToken"/>  
        </ic:Expression>  
      </ic:CorrelationID>  
  
      <ic:Update DataItemName ="Activity Date" Type ="DATETIME">  
        <ic:Expression>  
          <wcf:Operation Name ="GetContextProperty">  
            <wcf:Argument>EventTime</wcf:Argument>  
          </wcf:Operation>  
        </ic:Expression>  
      </ic:Update>  
  
      <ic:Update DataItemName ="Source" Type ="NVARCHAR">  
        <ic:Expression>  
          <ic:Operation Name="Constant">  
            <ic:Argument>WcfAdapter_ServiceRequest</ic:Argument>  
          </ic:Operation>  
        </ic:Expression>  
      </ic:Update>  
  
    </ic:OnEvent>  

ServiceReply

<ic:OnEvent IsBegin="true" IsEnd ="false" Name ="WCFServiceReply" Source="WCFService">  
      <ic:Filter>  
        <ic:Expression>  
          <wcf:Operation Name="GetServiceContractCallPoint"/>  
          <ic:Operation Name ="Constant">  
            <ic:Argument>ServiceReply</ic:Argument>  
          </ic:Operation>  
          <ic:Operation Name ="Equals" />  
        </ic:Expression>  
      </ic:Filter>  
  
      <ic:CorrelationID>  
        <ic:Expression>  
          <wcf:Operation Name="AutoGenerateCorrelationToken"/>  
        </ic:Expression>  
      </ic:CorrelationID>  
  
      <ic:Update DataItemName ="Activity Date" Type ="DATETIME">  
        <ic:Expression>  
          <wcf:Operation Name ="GetContextProperty">  
            <wcf:Argument>EventTime</wcf:Argument>  
          </wcf:Operation>  
        </ic:Expression>  
      </ic:Update>  
  
      <ic:Update DataItemName ="Name" Type ="NVARCHAR">  
        <ic:Expression>  
          <ic:Operation Name="Constant">  
            <ic:Argument>WcfAdapter_ServiceReply</ic:Argument>  
          </ic:Operation>  
        </ic:Expression>  
      </ic:Update>  
  
    </ic:OnEvent>  

See Also

Configuring the WCF Adapter to Intercept BAM Data