title: The message with To '...' cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher
body: <p>I'm trying to implement a WCF Rest service without modifying the <strong>App.config</strong> file.</p>
  
  <p>My Service Interface looks like so:</p>
  
  <pre><code>[ServiceContract]
  public interface IService
  {
      [OperationContract]
      [WebInvoke(Method = "POST",
          ResponseFormat = WebMessageFormat.Json,
          RequestFormat = WebMessageFormat.Json,
          BodyStyle = WebMessageBodyStyle.Bare,
          UriTemplate = "/teststr/?string={aStr}")]
      string TestString(string aStr);
  }
  </code></pre>
  
  <p>The Service implementation is very basic:</p>
  
  <pre><code>public class TestService : IService
  {
      public string TestString(string aStr = null)
      {
          Console.WriteLine("The Test() method was called at {0}"
              + "\n\rThe given string was {1}\n\r"
              , DateTime.Now.ToString("H:mm:ss")
              , aStr);
  
          return aStr;
      }
  }
  </code></pre>
  
  <p>And my main Program that runs everything:</p>
  
  <pre><code>// Step 1 Create a URI to serve as the base address.
  Uri baseAddress = new Uri("http://localhost:8000/ServiceSample/");
  
  // Step 2 Create a ServiceHost instance
  ServiceHost selfHost = new ServiceHost(typeof(TestService), baseAddress);
  
  try
  {
      // Step 3 Add a service endpoint.
      selfHost.AddServiceEndpoint(typeof(IService), new WebHttpBinding(), 
          "TestService");
  
      // Step 4 Enable metadata exchange.
      ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
      smb.HttpGetEnabled = true;
      selfHost.Description.Behaviors.Add(smb);
  
      // Step 5 Start the service.
      selfHost.Open();
      Console.WriteLine("The service is ready.");
      Console.WriteLine("Press &lt;ENTER&gt; to terminate service.");
      Console.ReadLine();
  
      // Close the ServiceHostBase to shutdown the service.
      selfHost.Close();
  }
  catch (CommunicationException ce)
  {
      Console.WriteLine("An exception occurred: {0}", ce.Message);
      selfHost.Abort();
  }
  </code></pre>
  
  <p>When I run this and enter the following url:</p>
  
  <pre><code>http://localhost:8000/ServiceSample/TestService/teststr/?string=thisisatest
  </code></pre>
  
  <p>I get this message:</p>
  
  <pre><code>// The message with To '...' cannot be processed at the receiver, due to an 
  // AddressFilter mismatch at the EndpointDispatcher. Check that the sender
  // and receiver's EndpointAddresses agree.
  </code></pre>
  
  <p>I've looked at similar SO questions suggesting <a href="https://stackoverflow.com/a/14415809/1972457">I add the <code>&lt;webHttp/&gt;</code> behavour</a> (but isn't <code>Step 4</code> doing that already?), others said <a href="https://stackoverflow.com/questions/9293721/addressfilter-mismatch-at-the-endpointdispatcher-the-msg-with-to">adding [ServiceBehavior..]</a>. None of these worked and I didnt find related SO questions useful.</p>
  
  <p>Do I need to modify the App.config file? What am I doing wrong here?</p>