title: JSON and SOAP WCF Service?
body: <p>I recently converted a WCF SOAP service into REST/JSON service. As detailed in the response <a href="https://stackoverflow.com/questions/10232509/can-i-generate-a-service-reference-automatically-for-a-rest-wcf-service">here</a>, the Add Service Reference feature of Visual Studio is incapable of generating code for a JSON service. The linked article in that question's answer alludes to the possibility of having a WCF exposed as both REST and SOAP to solve the issue, but it doesn't give any details how to do so. </p>
  
  <p>Does anyone know if this is possible and if so, how to set it up?</p>
  
  <p>There's always the alternative of writing a code generator myself, which reads the WSDL for the WCF REST service and generates C# classes, but it seems like there should be an easier solution than this.</p>
  
  <p>For reference,
  My web.config:</p>
  
  <pre><code>&lt;system.serviceModel&gt;
  &lt;behaviors&gt;
    &lt;endpointBehaviors&gt;
      &lt;behavior name="RestBehavior"&gt;
        &lt;webHttp /&gt;
      &lt;/behavior&gt;
    &lt;/endpointBehaviors&gt;
    &lt;serviceBehaviors&gt;
      &lt;behavior name="GetBehavior" &gt;
        &lt;serviceMetadata httpGetEnabled="true" /&gt;
        &lt;serviceDebug
           httpHelpPageEnabled="true"
           includeExceptionDetailInFaults="true"
        /&gt;
      &lt;/behavior&gt;
    &lt;/serviceBehaviors&gt;
  &lt;/behaviors&gt;
  &lt;bindings&gt;
    &lt;webHttpBinding&gt;
      &lt;binding name="WebHttpBinding"&gt;
        &lt;security mode="TransportCredentialOnly"&gt;
          &lt;transport clientCredentialType="None" /&gt;
        &lt;/security&gt;
      &lt;/binding&gt;
    &lt;/webHttpBinding&gt;
  &lt;/bindings&gt;
  &lt;services&gt;
    &lt;service name="Service" behaviorConfiguration="GetBehavior"&gt;
      &lt;endpoint address=""
        binding="webHttpBinding"
        behaviorConfiguration="RestBehavior"
        contract="IService"
        bindingConfiguration="WebHttpBinding"&gt;
      &lt;/endpoint&gt;
    &lt;/service&gt;
  &lt;/services&gt;
  &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p>My service methods all have the following attribute:</p>
  
  <pre><code>[WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
  </code></pre>