title: jQuery Ajax call to WCF service returning "Method not allowed (405)"
body: <p>I created a WCF SOAP service using VS 2008 that works server side.  I tacked on the code below to call the same service/contract client side using jQuery/json (no ASP.NET scriptmanager).  When I put the service url into the browser, I get the correct service page and when I invoke the service from javascript and trace via Firebug, I get "405 method not allowed".</p>
  
  <p>The ajax() error function's statusText and and responseText contain nothing and the error function gets called twice for some strange reason.  I'm also invoking the service from an https page.</p>
  
  <p>The same ajax code works with a similar traditional webservice both server side and client side and also works with a page method.</p>
  
  <p>Any clues?  I also noticed my Windows Communication Foundation HTTP Activation and Non-HTTP Activation are not installed.  Do I need these?  My server side WCF service works though.</p>
  
  <p>Interface:</p>
  
  <pre><code>[ServiceContract]
  public interface ICust
  {
      [OperationContract]
      [WebInvoke(Method = "POST", 
          BodyStyle = WebMessageBodyStyle.Wrapped, 
          ResponseFormat = WebMessageFormat.Json,
          RequestFormat = WebMessageFormat.Json)]
      bool GetCust(string zzz);
  }
  </code></pre>
  
  <p>Class:</p>
  
  <pre><code>public class Cust: ICust
  {
      public bool GetCust(string zzz)
      {
          // Do Stuff
          // Return true/false; 
      }
   }
  </code></pre>
  
  <p>web.config:</p>
  
  <pre><code>&lt;behaviors&gt;
      &lt;serviceBehaviors&gt;
          &lt;behavior name="E.W.CustomerBehavior" &gt;
              &lt;serviceMetadata httpGetEnabled="true" /&gt;
          &lt;/behavior&gt;
      &lt;/serviceBehaviors&gt;
      &lt;endpointBehaviors&gt;
          &lt;behavior name="webCallable"&gt;
              &lt;webHttp /&gt;
          &lt;/behavior&gt;            
      &lt;/endpointBehaviors&gt;
  &lt;/behaviors&gt;
  
  &lt;services&gt;
      &lt;service behaviorConfiguration="E.W.CustomerBehavior"
          name="E.W.Customer"&gt;
          &lt;endpoint address="http://zzzz/Cust.svc" 
              binding="webHttpBinding" 
              contract="E.W.ICust" 
              behaviorConfiguration="webCallable"&gt;
              &lt;identity&gt;
                  &lt;dns value="localhost" /&gt;
              &lt;/identity&gt;
          &lt;/endpoint&gt;
          &lt;endpoint address="mex" 
              binding="mexHttpBinding" 
              contract="IMetadataExchange" /&gt;
      &lt;/service&gt;
  &lt;/services&gt;
  </code></pre>
  
  <p>jQuery:</p>
  
  <pre><code>$.ajax({
      cache: false,
      async: false,
      type: "POST",
      url: "http://zzzz/Cust.svc/GetCust",
      contentType: "application/json",
      dataType: "json",
      data: "{'zzz': '" + $("#ctl00_zz_zzz").val() + "'}",
      success: function(msg) {
          // do stuff
      },
      error: function(z) { alert(z.responseText); }
  });
  </code></pre>