title: WCF Routing service error - ContractFilter mismatch at the EndpointDispatcher
body: <p>The situation is as follows: I have an internal server running some WCF services, and I want them to be accessible from the internet at large. To this end, I have written a routing service that is running on our public facing web-server. </p>
  
  <p>This routing service appears to work, however when I attempt to invoke a method, I always get the following error. </p>
  
  <p>The message with Action 'http://tempuri.org/IProcessManagementService/ListProcesses' 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>I have attempted to remove all security requirements from the services, and used both wsHTTP and basicHTTP endpoints. Nothing appears to do the trick. The routing service is properly passing on the mex services, however, so svcutil is able to build client classes. </p>
  
  <p>I am configuring the router though code. The routing service is given a list of service names to provide routing for, and the router and server addresses. </p>
  
  <p>Here is the config for the routing service:</p>
  
  <pre><code>&lt;MES.RoutingService.Properties.Settings&gt;
     &lt;setting name="RouterAddress" serializeAs="String"&gt;
      &lt;value&gt;http://localhost:8781/&lt;/value&gt;
     &lt;/setting&gt;
     &lt;setting name="ServerAddress" serializeAs="String"&gt;
      &lt;value&gt;http://10.4.1.117:8781/&lt;/value&gt;
     &lt;/setting&gt;
     &lt;setting name="Services" serializeAs="Xml"&gt;
      &lt;value&gt;
       &lt;ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
        &lt;string&gt;ProcessManagementService&lt;/string&gt;
        &lt;string&gt;TestProcessService&lt;/string&gt;
        &lt;string&gt;ProcessDataEntryService&lt;/string&gt;
        &lt;string&gt;ProcessReportingService&lt;/string&gt;
       &lt;/ArrayOfString&gt;
      &lt;/value&gt;
     &lt;/setting&gt;
    &lt;/MES.RoutingService.Properties.Settings&gt;
  </code></pre>
  
  <p>It calls a function with the following code, providing the router address, server address, and service names from the config file. </p>
  
  <pre><code>var routers = new List&lt;ServiceHost&gt;();
          foreach (var service in _services)
          {
              var routerType = typeof(IRequestReplyRouter);
              var routerContract = ContractDescription.GetContract(routerType);
              var serviceHost = new ServiceHost(typeof (System.ServiceModel.Routing.RoutingService));             
              var serverEndpoints = new List&lt;ServiceEndpoint&gt;();              
  
              //Configure Mex endpoints
              serviceHost.AddServiceEndpoint(routerType, MetadataExchangeBindings.CreateMexHttpBinding(), _routerAddress + service + "/mex");
              serverEndpoints.Add(new ServiceEndpoint(routerContract, MetadataExchangeBindings.CreateMexHttpBinding(), new EndpointAddress(_serverAddress + service + "/mex")));
  
              //RAR SECURITY SMASH.
              var binding = new WSHttpBinding(SecurityMode.None);
              binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
              binding.Security.Message.EstablishSecurityContext = false;
              binding.Security.Message.NegotiateServiceCredential = false;
              binding.Security.Message.ClientCredentialType = MessageCredentialType.None;
  
              //Configure WsHttp endpoints
              serviceHost.AddServiceEndpoint(routerType, binding, _routerAddress + service);              
              serverEndpoints.Add(new ServiceEndpoint(routerContract, binding, new EndpointAddress(_serverAddress + service)));
  
              var basicBinding = new BasicHttpBinding();
              serviceHost.AddServiceEndpoint(routerType, basicBinding, _routerAddress + service + "/basic");
              serverEndpoints.Add(new ServiceEndpoint(routerContract, basicBinding, new EndpointAddress(_serverAddress + service + "/basic")));
  
              //Set Routing Tables
              var configuration = new RoutingConfiguration();
              configuration.FilterTable.Add(new MatchAllMessageFilter(), serverEndpoints);
              serviceHost.Description.Behaviors.Add(new RoutingBehavior(configuration));
  
              routers.Add(serviceHost);
          }
          return routers;
  </code></pre>
  
  <p>The service calls this function on start, and then opens each of the service hosts returned in the routers list. </p>
  
  <p>The server itself is configured via the following app.config </p>
  
  <pre><code>&lt;system.serviceModel&gt;
    &lt;bindings&gt;
     &lt;wsHttpBinding&gt;
      &lt;binding name="noSecurityBinding"&gt;
       &lt;security mode="None"&gt;
        &lt;transport clientCredentialType="None" /&gt;
        &lt;message establishSecurityContext="false" /&gt;
       &lt;/security&gt;
      &lt;/binding&gt;
     &lt;/wsHttpBinding&gt;   
    &lt;/bindings&gt;
    &lt;services&gt;
     &lt;service name="MES.ProcessManagerServiceLibrary.ProcessManagementService"&gt;
      &lt;endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /&gt;
      &lt;endpoint binding="wsHttpBinding" bindingConfiguration="noSecurityBinding"
       contract="MES.ProcessManagerServiceLibrary.IProcessManagementService" /&gt;
      &lt;endpoint address="basic" binding="basicHttpBinding" bindingConfiguration=""
       contract="MES.ProcessManagerServiceLibrary.IProcessManagementService" /&gt;
      &lt;host&gt;
       &lt;baseAddresses&gt;
        &lt;add baseAddress="http://localhost:8781/ProcessManagementService/" /&gt;
       &lt;/baseAddresses&gt;
      &lt;/host&gt;
     &lt;/service&gt;
     &lt;service name="MES.ProcessManagerServiceLibrary.TestProcessService"&gt;
      &lt;endpoint address="" binding="wsHttpBinding" bindingConfiguration="noSecurityBinding"
       contract="MES.ProcessManagerServiceLibrary.ITestProcessService" /&gt;
      &lt;endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /&gt;
      &lt;endpoint address="basic" binding="basicHttpBinding" bindingConfiguration=""
       contract="MES.ProcessManagerServiceLibrary.ITestProcessService" /&gt;    
      &lt;host&gt;
       &lt;baseAddresses&gt;
        &lt;add baseAddress="http://localhost:8781/TestProcessService/" /&gt;
       &lt;/baseAddresses&gt;
      &lt;/host&gt;
     &lt;/service&gt;
     &lt;service name="MES.ProcessManagerServiceLibrary.ProcessDataEntryService"&gt;
      &lt;endpoint address="" binding="wsHttpBinding" bindingConfiguration="noSecurityBinding"
       contract="MES.ProcessManagerServiceLibrary.IProcessDataEntryService" /&gt;
      &lt;endpoint address="basic" binding="basicHttpBinding" bindingConfiguration=""
      contract="MES.ProcessManagerServiceLibrary.IProcessDataEntryService" /&gt;
      &lt;endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /&gt;
      &lt;host&gt;
       &lt;baseAddresses&gt;
        &lt;add baseAddress="http://localhost:8781/ProcessDataEntryService/" /&gt;
       &lt;/baseAddresses&gt;
      &lt;/host&gt;
     &lt;/service&gt;
     &lt;service name="MES.ProcessManagerServiceLibrary.ProcessReportingService"&gt;
      &lt;endpoint address="" binding="wsHttpBinding" bindingConfiguration="noSecurityBinding"
       contract="MES.ProcessManagerServiceLibrary.IProcessReportingService" /&gt;
      &lt;endpoint address="basic" binding="basicHttpBinding" bindingConfiguration=""
      contract="MES.ProcessManagerServiceLibrary.IProcessReportingService" /&gt;
      &lt;endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /&gt;
      &lt;host&gt;
       &lt;baseAddresses&gt;
        &lt;add baseAddress="http://localhost:8781/ProcessReportingService/" /&gt;
       &lt;/baseAddresses&gt;
      &lt;/host&gt;
     &lt;/service&gt;
    &lt;/services&gt;
    &lt;behaviors&gt;
     &lt;serviceBehaviors&gt;
      &lt;behavior&gt;
       &lt;!-- To avoid disclosing metadata information, 
       set the value below to false and remove the metadata endpoint above before deployment --&gt;
       &lt;serviceMetadata httpGetEnabled="True"/&gt;
       &lt;!-- To receive exception details in faults for debugging purposes, 
       set the value below to true. Set to false before deployment 
       to avoid disclosing exception information --&gt;
       &lt;serviceDebug includeExceptionDetailInFaults="True"/&gt;
      &lt;/behavior&gt;
     &lt;/serviceBehaviors&gt;
    &lt;/behaviors&gt;
   &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p>What am I missing?</p>
  
  <p>Edit: I think I found the problem- the routing service was returning this configuration for the services-</p>
  
  <pre><code>&lt;client&gt;
     &lt;endpoint address="http://shco-appsrv1.us.shepherd.ad:8781/ProcessManagementService/"
      binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IProcessManagementService"
      contract="IProcessManagementService" name="WSHttpBinding_IProcessManagementService" /&gt;
     &lt;endpoint address="http://shco-appsrv1.us.shepherd.ad:8781/ProcessManagementService/basic"
      binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IProcessManagementService"
      contract="IProcessManagementService" name="BasicHttpBinding_IProcessManagementService" /&gt;
   &lt;/client&gt;
  </code></pre>
  
  <p>This points to the internal server, not the external server. No idea if this is standard behavior for a Routing service, or if it is overridable behavior. </p>