title: The message with Action cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher
body: <p>Thanks for stopping by. I thought I'd share a face-palm moment I experienced when building out a WCF service. And while I had eventually came to find the answer. It was so infuriatingly simple, but the I had lost hours over one misplaced character. So I figured, I'd 'pay-it-forward' and share how I had figured out the solution.</p>
  
  <p>The full error message: 
  The message with Action '<a href="http://Foo.bar.car/IPolicyService/GetPolicyData/" rel="noreferrer">http://Foo.bar.car/IPolicyService/GetPolicyData/</a>' 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)</p>
  
  <p>My client requirement was for sending SOAP messages w/out using a proxy class so that the payload always stayed in XML. </p>
  
  <pre><code>[ServiceContract(Namespace = "http://Foo.bar.car")]
  public interface IPolicyService
  {
      [OperationContract]
      PolicyResponse GetPolicyData(PolicyRequest request);
  }
  
  public class PolicyData : IPolicyService
  {
     public PolicyResponse GetPolicyData(PolicyRequest request)
     {
              var polNbr = request.REQ_POL_NBR;
              return GetFakePolicyData(polNbr);
      }
  }
  </code></pre>
  
  <p>This WebClient method worked:</p>
  
  <pre><code>using System.Net; 
  using System.Xml.Linq;
  
  public static class ClientHelper
  {
      public static string Post(string targetUrl, string action, string method, string key, string value)
      {
          var request = BuildEnvelope(method, key, value);
      using (var webClient = new WebClient())
      {
          webClient.Headers.Add("Accept-Header", "application/xml+");
          webClient.Headers.Add("Content-Type", "text/xml; charset=utf-8");
          webClient.Headers.Add("SOAPAction", action);
          var result = webClient.UploadString(targetUrl, "POST", request);
  
          return result;
      }
  }
  
  public static string BuildEnvelope(string method, string key, string value)
  {
      XNamespace s = "http://schemas.xmlsoap.org/soap/envelope/";
      XNamespace d = "d4p1";
      XNamespace tempUri = "http://tempuri.org/";
      XNamespace ns = "http://Foo.bar.car";
      XNamespace requestUri = "http://schemas.datacontract.org/2004/07/Foo.bar.car.Model.Policy";
      var xDoc = new XDocument(
                          new XElement(
                              s + "Envelope",
                              new XAttribute(XNamespace.Xmlns + "s", s),
                              new XElement(
                                  s + "Body",
                                  new XElement(
                                      ns + method,
                                      new XElement(requestUri + "request", 
                                          new XElement(tempUri + key, value))
                                  )
                              )
                          )
                      );
      // hack - finish XDoc construction later
      return xDoc.ToString().Replace("request xmlns=", "request xmlns:d4p1=").Replace(key, "d4p1:" + key);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>when called with:</p>
  
  <pre><code>return ClientHelper.Post("http://localhost:5050/PolicyService.svc", "http://Foo.bar.car/IPolicyService/GetPolicyData", "GetPolicyData", "REQ_POL_NBR", id);
  </code></pre>
  
  <p>But making the same call via a WCF message failed, giving me a frowny face...</p>
  
  <pre><code>    private static Message SendMessage(string id)
      {
          var body = new GetPolicyData {request =  new request{ REQ_POL_NBR = id }}; 
          var message = Message.CreateMessage(MessageVersion.Soap11, "http://Foo.bar.car/IPolicyService/GetPolicyData/", body);
  
          message.Headers.Add(MessageHeader.CreateHeader("Accept-Header", string.Empty, "application/xml+"));
          message.Headers.Add(MessageHeader.CreateHeader("Content-Type", string.Empty, "text/xml"));
          message.Headers.Add(MessageHeader.CreateHeader("FromSender", string.Empty, "DispatchMessage"));
          message.Headers.To = new System.Uri(@"http://localhost:5050/PolicyService.svc");
  
          var binding = new BasicHttpBinding(BasicHttpSecurityMode.None)
          {
               MessageEncoding = WSMessageEncoding.Text,
              MaxReceivedMessageSize = int.MaxValue,
              SendTimeout = new TimeSpan(1, 0, 0),
              ReaderQuotas = { MaxStringContentLength = int.MaxValue, MaxArrayLength = int.MaxValue, MaxDepth = int.MaxValue }
          };
          message.Properties.Add("Content-Type", "text/xml; charset=utf-8");
          message.Properties.Remove("Accept-Encoding");
          message.Properties.Add("Accept-Header", "application/xml+");
  
          var cf = new ChannelFactory&lt;IRequestChannel&gt;(binding, new EndpointAddress(new Uri("http://localhost:5050/PolicyService.svc")));
  
          cf.Open();
          var channel = cf.CreateChannel();
          channel.Open();
  
          var result = channel.Request(message);
  
          channel.Close();
          cf.Close();
          return result;
      }
  
  
  [DataContract(Namespace = "http://Foo.bar.car")]
  public class GetPolicyData
  {
      [DataMember]
      public request request { get; set; }
  }
  
  [DataContract(Namespace = "http://schemas.datacontract.org/2004/07/Foo.bar.car.Model.Policy")]
  public class request
  {
      ///&lt;summary&gt;
      /// Define request parameter for SOAP API to retrieve selective Policy level data
      /// &lt;/summary&gt;
      [DataMember]
      public string REQ_POL_NBR { get; set; }
  }
  </code></pre>
  
  <p>Checking the web_messages.log only provided a red herring that sent me down the wrong rabbit hole.
  The version of the call that worked stored the action as 
  [HttpRequest] SOAPAction    <a href="http://Foo.bar.car/IPolicyService/GetPolicyData" rel="noreferrer">http://Foo.bar.car/IPolicyService/GetPolicyData</a></p>
  
  <p>whereas the failing call recorded that action in quotes as 
  [HttpRequest] SOAPAction    "<a href="http://Foo.bar.car/IPolicyService/GetPolicyData/" rel="noreferrer">http://Foo.bar.car/IPolicyService/GetPolicyData/</a>" </p>
  
  <p>Finding the solution required two things.</p>
  
  <p>Recreating the client call using fiddler and getting that to work...</p>
  
  <pre><code>Post action:    http://localhost:5050/PolicyService.svc
  Header:
  User-Agent: Fiddler
  SOAPAction: http://Foo.bar.car/IPolicyService/GetPolicyData
  Content-type: text/xml
  Host: localhost:5050
  Content-Length: 381
  
  Body:
  
      &lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt;
        &lt;s:Body&gt;
      &lt;GetPolicyData xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://Foo.bar.car"&gt;
      &lt;request xmlns:d4p1="http://schemas.datacontract.org/2004/07/Foo.bar.car.Model.Policy"&gt;
      &lt;d4p1:REQ_POL_NBR&gt;1&lt;/d4p1:REQ_POL_NBR&gt;
      &lt;/request&gt;
      &lt;/GetPolicyData&gt;
        &lt;/s:Body&gt;
      &lt;/s:Envelope&gt;
  </code></pre>
  
  <p>And probably more importantly
  Stepping away for an while to clear my head and eat something and look at the problem with a fresh pair of eyes.</p>
  
  <p>I'll post the answer on Monday, but happily credit the person who finds that one character that had stumped me for longer than I'd care to admit... </p>