title: WCF Configuration Hell?
body: <p>I hate WCF setup with endpoints, behaviors etc. I believe all these things should be performed automatically. All I want to do is to return JSON result from my WCF service. Here is my configuration: </p>
  
  <pre><code>&lt;system.serviceModel&gt;
  &lt;bindings&gt;
    &lt;webHttpBinding&gt;
      &lt;binding name="default"/&gt;
    &lt;/webHttpBinding&gt;
  &lt;/bindings&gt;
  &lt;services&gt;
    &lt;service name="HighOnCodingWebApps.ZombieService"
       behaviorConfiguration="MyServiceTypeBehaviors"&gt;
      &lt;endpoint address="" binding="webHttpBinding"
        bindingConfiguration="default"
        contract="HighOnCodingWebApps.IZombieService"
        behaviorConfiguration="webScriptEnablingBehavior"/&gt;
    &lt;/service&gt;
  &lt;/services&gt;
  
  &lt;behaviors&gt;
    &lt;endpointBehaviors&gt;
      &lt;behavior name="webScriptEnablingBehavior"&gt;
        &lt;enableWebScript/&gt;
      &lt;/behavior&gt;
    &lt;/endpointBehaviors&gt;
  
    &lt;serviceBehaviors&gt;
      &lt;behavior name="MyServiceTypeBehaviors"&gt;
        &lt;serviceMetadata httpGetEnabled="true"/&gt;
  
  
      &lt;/behavior&gt;
    &lt;/serviceBehaviors&gt;
  &lt;/behaviors&gt;
  
  &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="false"/&gt;
  </code></pre>
  
  <p></p>
  
  <p>And I have the following service implementation: </p>
  
  <pre><code>public class ZombieService : IZombieService
      {
          [WebInvoke(Method = "GET",
                      ResponseFormat = WebMessageFormat.Json,
                      UriTemplate = "KnownZombies")]
          public Zombie GetZombie()
          {
             return new Zombie() { Name = "Mohammad Azam"};
          }
      }
  
      public class Zombie
      {
          public string Name { get; set; }
      }
  </code></pre>
  
  <p>When I visit <code>http://localhost:22059/ZombieService/KnownZombies</code> says the following message: </p>
  
  <p>Endpoints using 'UriTemplate' cannot be used with 'System.ServiceModel.Description.WebScriptEnablingBehavior'.</p>
  
  <p>If I remove the WebScriptEnablingBehavior from the web.config I get the following error: </p>
  
  <blockquote>
    <p>The message with To
    'http://localhost:22059/ZombieService.svc/KnownZombies' cannot be
    processed at the receiver, due to an AddressFilter mismatch at the
    EndpointDispatcher.  Check that the sender and receiver's
    EndpointAddresses agree.</p>
  </blockquote>
  
  <p>UPDATE 1: </p>
  
  <p>I updated the configuration to this: </p>
  
  <pre><code> &lt;system.serviceModel&gt;
      &lt;bindings&gt;
        &lt;webHttpBinding&gt;
          &lt;binding name="default"/&gt;
        &lt;/webHttpBinding&gt;
      &lt;/bindings&gt;
      &lt;services&gt;
        &lt;service name="HighOnCodingWebApps.ZombieService"
           behaviorConfiguration="MyServiceTypeBehaviors"&gt;
          &lt;endpoint address="http://localhost:22059/ZombieService.svc" binding="webHttpBinding"
            bindingConfiguration="default"
            contract="HighOnCodingWebApps.IZombieService"
            /&gt;
        &lt;/service&gt;
      &lt;/services&gt;
  
      &lt;behaviors&gt;
        &lt;endpointBehaviors&gt;
          &lt;behavior name="SomeBehavior"&gt;
            &lt;webHttp /&gt;
          &lt;/behavior&gt;
        &lt;/endpointBehaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior name="MyServiceTypeBehaviors"&gt;
  
            &lt;serviceMetadata httpGetEnabled="true"/&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
  
    &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p>Now when I visit <code>http://localhost:22059/ZombieService.svc/KnownZombies</code> I get the following message in the browser: </p>
  
  <blockquote>
    <p>The message with To
    'http://localhost:22059/ZombieService.svc/KnownZombies' cannot be
    processed at the receiver, due to an AddressFilter mismatch at the
    EndpointDispatcher.  Check that the sender and receiver's
    EndpointAddresses agree.</p>
  </blockquote>