title: WebHttpBinding with Http and Https
body: <p>I am trying to use https &amp; http for the website. The website has .svc files which act as REST service and called from JavaScript.</p>
  
  <p>My Config:</p>
  
  <pre><code>&lt;system.serviceModel&gt;
      &lt;behaviors&gt;
        &lt;endpointBehaviors&gt;
          &lt;behavior name="AjaxBehavior"&gt;
            &lt;webHttp /&gt;
          &lt;/behavior&gt;
        &lt;/endpointBehaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior name="MyServiceBehaviour"&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="true" /&gt;
            &lt;serviceMetadata httpGetEnabled="True" httpsGetEnabled="true"/&gt;         
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
      &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true" /&gt;
      &lt;services&gt;
        &lt;service behaviorConfiguration="MyServiceBehaviour" name="MyService.Lookups"&gt;
          &lt;endpoint address="" behaviorConfiguration="AjaxBehavior"
            binding="webHttpBinding" bindingConfiguration="httpWebBinding" contract="MyService.Lookups" &gt;         
          &lt;/endpoint&gt;
          &lt;endpoint address="" behaviorConfiguration="AjaxBehavior"
            binding="webHttpBinding" bindingConfiguration="httpsWebBinding" contract="MyService.Lookups" &gt;          
          &lt;/endpoint&gt;
          &lt;endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /&gt;
        &lt;/service&gt;
      &lt;/services&gt;
      &lt;bindings&gt;      
        &lt;webHttpBinding&gt;
          &lt;binding name="httpsWebBinding"&gt;
            &lt;security mode="Transport"&gt;
              &lt;transport clientCredentialType="None" proxyCredentialType="None" /&gt;
            &lt;/security&gt;
          &lt;/binding&gt;
          &lt;binding name="httpWebBinding"&gt;
            &lt;security mode="None"&gt;
              &lt;transport clientCredentialType="None" proxyCredentialType="None" /&gt;
            &lt;/security&gt;
          &lt;/binding&gt;
        &lt;/webHttpBinding&gt;
      &lt;/bindings&gt;   
    &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p>Browsing <a href="https://myserver/services/Lookups.svc/Hello" rel="noreferrer">https://myserver/services/Lookups.svc/Hello</a> gives</p>
  
  <p><strong>Could not find a base address that matches scheme http for the endpoint with binding WebHttpBinding. Registered base address schemes are [https]</strong></p>
  
  <p>Browsing <a href="http://myserver/services/Lookups.svc/Hello" rel="noreferrer">http://myserver/services/Lookups.svc/Hello</a> gives</p>
  
  <p><strong>Could not find a base address that matches scheme https for the endpoint with binding WebHttpBinding. Registered base address schemes are [http]</strong></p>
  
  <p>If I remove any one endpoint it works. Example removing endpoint configured with <code>bindingConfiguration="httpWebBinding"</code> works for HTTPS , </p>
  
  <p><strong>How can I make it work with HTTP and HTTPS?</strong> As of now, I can able to use either http or https by removing one endpoint.</p>
  
  <p>Referred <a href="https://stackoverflow.com/questions/4346926/how-can-i-combine-the-wcf-services-config-for-both-http-and-https-in-one-web-con">How can I combine the WCF services config for both http and https in one web.config?</a> and <a href="https://stackoverflow.com/questions/8059848/how-do-you-setup-http-and-https-wcf-4-restful-services">How do you setup HTTP and HTTPS WCF 4 RESTful services?</a> </p>
  
  <blockquote>
    <p><strong>Note</strong>: In IIS, it is two web sites one listen on http and another on
    https. Both sharing same code in physical folder</p>
  </blockquote>
  
  <p><strong>UPDATE:</strong> As of now, I removed endpoints and it works. But my concern is removing endpoing configured with behaviourConfiguration doesnt look great solution to me. </p>
  
  <p>This works for both http &amp; https</p>
  
  <pre><code>  &lt;services&gt;
        &lt;service behaviorConfiguration="MyServiceBehaviour" name="MyService.Lookups"&gt;
  
        &lt;/service&gt;
      &lt;/services&gt;
  </code></pre>