BizTalk and WCF SOAP Action

I have been seeing this error haunting some developers in WCF service with BizTalk. Someone has posted this error again in BizTalk forum recently.

When you send message to a WCF service from BizTalk, if the send port or orchestration is not configured properly you may get this error.

<s:Envelope xmlns:s=”http://schemas.xmlsoap.org/soap/envelope/”><s:Body><s:Fault><faultcode xmlns:a=”http://schemas.microsoft.com/ws/2005/05/addressing/none”>a:ActionNotSupported</faultcode><faultstring xml:lang=”en-GB”>The message with Action ‘<<Your SOAP Action Header>>’ cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver.  Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).</faultstring></s:Fault></s:Body></s:Envelope>

As mentioned in the error, it is due to either a contract mismatch or a binding/security mismatch for SOAP action.

What is WCF SOAP Action, why and how it’s used/configured in BizTalk:

Typically a WCF service will have many methods/OperationContracts. If you want to invoke a particular method, you have to instruct the WCF service to  which method you want to invoke. SOAP Action is this instruction to WCF service.

Let me illustrate this with an example. If you defined a service’s interface as below:

    [ServiceContract]
    public interface IHelloWorld
    {
        [OperationContract]
        string SayHello();
    }

SOAP Action for the OperationContract SayHello() is http://tempuri.org/IHelloWorld/SayHello

If you change the ServiceContract attribute with a namespace, like this..

    [ServiceContract(Namespace="http://abc.com")]
    public interface IHelloWorld
    {
        [OperationContract]
        string SayHello();
    }

Then the SOAP Action for the OperationContract SayHello() change to http://abc.com/IHelloWorld/SayHello

As you can see SOAP Action is the combination of “ServiceContract-Namespace, name of the interface where ServiceContract is defined and the method with OperationContract attribute is decorated”.

You can find the SOAP action in theWSDL description file of your WCF service.

WCF SOAP Action

From Biztalk, if you want to send a message to a WCF service, we have to instruct the WCF service application/target system to know which method to invoke or serialize this message/request to. In BizTalk, this instruction (SOAP Action) is set by assigning a value to WCF.Action context property.

You can specify WCF.Action property in two ways:

  1. Single Action Format
  2. Action Mapping Format

Single Action Format:

Single action format is generally used when you want to use the send port to invoke one method/OperationContract of the WCF service. It can also be used in the case of content-based-routing (messaging only).

WCF.Action in single action format can be set in Orchestration’s expression shape as


OutboundMessage(WCF.Action) = “http://abc.com/IHelloWorld/SayHello”

Or in Send port’s adapter, configure–> General tab –> SOAP Action Header’s Action section

Single Action Format

Action Mapping Format:

In Action Mapping Format, you need to specify the WCF.Action in send port like this.

Action Mapping Format

In Action Mapping Format, as name suggest WCF.Action is “mapped”/resolved from another context property BTS.Operation.

Action Mapping Format in Orchestration:

When you use Orchestration, BTS.Operation context property is set by Orchestration’s logical send port which you use to send the request to WCF Service.

Action Mapping Format in Orchestration logical Send Port

BTS.Operation

So when the WCF based send port receive a message, it will match the value of BTS.Operation context property to one of the Operation’s Name attributes. If match found, then WCF.Action would be resolved to Operation’s Action value.

In the image above, value of BTS.Operation context property is “SayHello”. If you have SOAP Action header with multiple operations like this..

SOAP Action Header with multiple operations

then based on the above BTS.Context, it will match to the Operation’s Name SayHello and WCF.Action would be resolved to http://abc.com/IHelloWorld/SayHello

Now you might ask a question that why do we need to give multiple operations in SOAP Action header ?  This is because, it enable us to use a same Send port to invoke multiple operationContracts in a WCF Service.

You might ask another question that why shouldn’t we directly set the WCF.Action, rather than indirectly setting it through BTS.Operation?  This is due to the best practice that in Orchestration, logical send port should not have any bindings that tightly bound to the transport.

Action Mapping Format in content-based routing/Message-only:

If you have used Action mapping format for specifying the SOAP Action and to set the BTS.Operation you have to use custom send pipeline. And in the custom pipeline component you can promote BTS.Operation like this..


inmsg.Context.Promote("Operation", "http://schemas.microsoft.com/BizTalk/2003/system-properties",”SayHello”);

Why do you get this error:

Going back to error message of “ActionNotSupported. The message with Action cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher”.

As already mentioned, this error is due to either a contract mismatch or a binding/security mismatch for SOAP action. Now we know about SOAP Action and we know what to check in BizTalk. People are cautious enough in giving the SOAP Action header in send port, either they get it by importing the auto-generated binding (you get both binding for WCF-Basic and WCF-Custom adapter, when you “Consume WCF Service” for “Add Generated Items”) or from the WSDL description of WCF Service. There is also another place to check, when you use Orchestration – Operation name of the logical send port in Orchestration.

Hope this blog post is useful to someone who wants to know more about SOAP Actions.

Posted in: BizTalk, WCF 2 Comments October 16, 2013

About M.R.ASHWINPRABHU

M.R.ASHWINPRABHU is the founder and CEO of Fortuvis Systems Limited, a consulting company specialised in Microsoft technologies. Ashwin is a highly experienced integration consultant who works with clients to deliver high quality solutions. He works as technical lead developer, application architect and consultant, specializing in custom applications, enterprise application integration (BizTalk), Web services and Windows Azure.

Comments (2)

  • Praveen behara October 7, 2014 - 8:55 pm Reply

    Bang on. Spent my whole day debugging this.shame,I cou open ur blog from my company.

  • Siddharth June 17, 2015 - 7:47 pm Reply

    I don’t usually comment like this, but I found this really interesting given that there are few to none sites which gave me clarity like this.
    Kudos!

    Please do more with SQL binding in Biztalk… Perhaps a mini project?

Leave a Reply

Your email address will not be published. Required fields are marked *