title: Use JQuery AJAX to call WCF Service with multiple bindings
body: <p>I have a WCF service with three endpoints with different bindings (basicHttpBinding for soap clients, webHttpBinding for jquery ajax client, and mex).</p>
  
  <p>I can access the service via SOAP (by adding a Service Reference then):</p>
  
  <pre><code>        ServiceRef.IService service = new ServiceClient("BasicHttpBinding_IService");
          Response.Write(service.TestMethod("hi"));
  </code></pre>
  
  <p>But why I call from Jquery Ajax I get a 404 error.</p>
  
  <p>If I copy the service into a test project and define only one webHttpBinding, I can call the service via jquery.</p>
  
  <p><strong>IService.cs</strong></p>
  
  <pre><code>   [ServiceContract]
      public interface IService
      {
          [OperationContract]
          [WebInvoke(Method = "POST",
           ResponseFormat = WebMessageFormat.Json)]
           Response TestMethod(string Id);
  ....
  </code></pre>
  
  <p><strong>Service.cs</strong></p>
  
  <pre><code>[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
  [ServiceBehavior]
  public class Service : IService
  {
      [OperationBehavior]
      public Response TestMethod(string Id)
      {
          Response resp = new Response();
          resp.Message = "hello";
          return resp;
      }
  ....
  </code></pre>
  
  <p><strong>Web.Config</strong></p>
  
  <pre><code>  &lt;system.serviceModel&gt;
      &lt;serviceHostingEnvironment multipleSiteBindingsEnabled="false" aspNetCompatibilityEnabled="true" /&gt;
  &lt;services&gt;
    &lt;service
     name="eBooks.Presentation.Wcf.Service"
     behaviorConfiguration="eBooks.Presentation.Wcf.ServiceBehavior"&gt;
      &lt;!-- use base address provided by host --&gt;
      &lt;!-- specify BasicHttp binding and a binding configuration to use --&gt;
      &lt;endpoint address="soap"
                binding="basicHttpBinding"
                bindingConfiguration="Binding1"
                contract="eBooks.Presentation.Wcf.IService" /&gt;
      &lt;endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/&gt;
        &lt;endpoint address="" binding="webHttpBinding"
            contract="eBooks.Presentation.Wcf.IService" behaviorConfiguration="EndpBehavior"/&gt;
    &lt;/service&gt;
  &lt;/services&gt;
  &lt;bindings&gt;
    &lt;!-- 
        Following is the expanded configuration section for a BasicHttpBinding.
        Each property is configured with the default value.
        See the TransportSecurity, and MessageSecurity samples in the
        Basic directory to learn how to configure these features.
        --&gt;
    &lt;basicHttpBinding&gt;
      &lt;binding name="Binding1"
               hostNameComparisonMode="StrongWildcard"
               receiveTimeout="00:10:00"
               sendTimeout="00:10:00"
               openTimeout="00:10:00"
               closeTimeout="00:10:00"
               maxReceivedMessageSize="65536"
               maxBufferSize="65536"
               maxBufferPoolSize="524288"
               transferMode="Buffered"
               messageEncoding="Text"
               textEncoding="utf-8"
               bypassProxyOnLocal="false"
               useDefaultWebProxy="true" &gt;
        &lt;security mode="None" /&gt;
      &lt;/binding&gt;
    &lt;/basicHttpBinding&gt;
  &lt;/bindings&gt;
  &lt;behaviors&gt;
    &lt;serviceBehaviors&gt;
      &lt;behavior name="eBooks.Presentation.Wcf.ServiceBehavior"&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;endpointBehaviors&gt;
      &lt;behavior name="EndpBehavior"&gt;
        &lt;webHttp/&gt;
      &lt;/behavior&gt;
    &lt;/endpointBehaviors&gt;
  &lt;/behaviors&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>Jquery</strong></p>
  
  <pre><code>    function CallService() {
          $.ajax({
              type: "POST", //GET or POST or PUT or DELETE verb
              url: "http://localhost:888/Service.svc/TestMethod", // Location of the service
              data: '{"Id": "1"}', //Data sent to server
              contentType: "application/json; charset=utf-8", // content type sent to server
              dataType: "json", //Expected data format from server
              processdata: ProcessData, //True or False
              success: function (msg) {//On Successfull service call
                  ServiceSucceeded(msg);
              },
              error: ServiceFailed// When Service call fails
          });
      }
  </code></pre>
  
  <p>In my endpoint configuration I have set the address for the webHttp endpoint to be "" as I dont know how to select a specific endpoint when calling from jquery. </p>
  
  <p>Anyone have any ideas why I am getting this 404 error?</p>