title: Two endpoints in WCF 3.5 for SOAP and JSON
body: <p>I dont know what I am doing wrong. I have a WCF (.NET 3.5) service (JsonSoap.svc) that has two endpoints for soap and json content type. Both the endpoints refer to the same service. I am using only one Json endpoint in the client. My aim is to have the service method GetPerson() to return Json or soap depending on the endpoints used to connect to the service (hopefully this is possible in WCF?). I can see wsdl and was able to successfully ad the service reference in to the client side.</p>
  
  <p>I get the following error after I make a call to the GetPerson() - </p>
  
  <blockquote>
    <p>"An error occurred while receiving the
    HTTP response to
    <a href="http://localhost:80/JsonSoap/json/GetPerson" rel="nofollow">http://localhost:80/JsonSoap/json/GetPerson</a>.
    This could be due to the service
    endpoint binding not using the HTTP
    protocol.  This could also be due to
    an HTTP request context being aborted
    by the server (possibly due to the
    service shutting down).  See server
    logs for more details."</p>
  </blockquote>
  
  <p>WCF service config</p>
  
  <pre><code>&lt;!-- bindings --&gt;
  &lt;bindings&gt;
  
    &lt;basicHttpBinding&gt;
      &lt;binding name ="soapBinding"&gt;
        &lt;security mode="None"&gt;
        &lt;/security&gt;
      &lt;/binding&gt;
    &lt;/basicHttpBinding&gt;
  
    &lt;webHttpBinding&gt;
      &lt;binding name="webBinding"&gt;
      &lt;/binding&gt;
    &lt;/webHttpBinding&gt;
  &lt;/bindings&gt;
  
  &lt;!-- JSON behaviors --&gt;
  &lt;endpointBehaviors&gt;
    &lt;behavior name="jsonBehavior"&gt;
      &lt;enableWebScript  /&gt;
    &lt;/behavior&gt;
  &lt;/endpointBehaviors&gt;
  &lt;serviceBehaviors&gt;
    &lt;behavior name="defaultBehavior"&gt;
      &lt;serviceDebug includeExceptionDetailInFaults="true" /&gt;
      &lt;serviceMetadata httpGetEnabled="true" /&gt;
    &lt;/behavior&gt;
  &lt;/serviceBehaviors&gt;
  &lt;/behaviors&gt;
    &lt;services&gt;
      &lt;service name="TestService.IJsonSoap" behaviorConfiguration="defaultBehavior"&gt;
        &lt;host&gt;
          &lt;baseAddresses&gt;
            &lt;!-- note, choose an available port--&gt;
            &lt;add baseAddress="http://localhost:80/JsonSoap" /&gt;
          &lt;/baseAddresses&gt;
        &lt;/host&gt;
  
  &lt;endpoint address="soap" binding="basicHttpBinding"
            bindingConfiguration="soapBinding"
            contract="TestService.IJsonSoap" /&gt;
  
  &lt;endpoint address="json" binding="webHttpBinding"
            bindingConfiguration="webBinding"
            behaviorConfiguration="jsonBehavior"
            contract="TestService.IJsonSoap" /&gt;
  &lt;/service&gt;
  </code></pre>
  
  <p>WCF code:</p>
  
  <pre><code>[OperationContract]
  [WebGet]
  Person GetPerson(int ID);
  </code></pre>
  
  <p>WCF Client config:</p>
  
  <pre><code>&lt;endpoint address="http://localhost:80/JsonSoap/json" binding="webHttpBinding"
            bindingConfiguration="webBinding" behaviorConfiguration="jsonBehavior"
            contract="MyService.IJsonSoap" /&gt;
  </code></pre>
  
  <p>Client code:</p>
  
  <pre><code>MyService.JsonSoapClient service = new JsonSoapClient();
  MyService.Person person = service.GetPerson(10);
  </code></pre>