WebHttpBinding with Http and Https

17,357

Solution 1

I've recreated your scenario and used your web.config to configure endpoints for my test service. Your configuration is ok and works correctly. The part that don't works for you is probably your https configuration in IIS. Make sure you have enabled https access to your service. If you test it with IISExpress from Visual Studio then left click on your project and in the properties window (View -> Properties Window ) select for SSL Enabled = True.

Solution 2

As @Lesmian pointed out in his answer, the issue is in your IIS configuration. More specifically in:

Note: In IIS, it is two web sites one listen on http and another on https. Both sharing same code in physical folder

The reason is that IIS can not handle endpoints on a schema which it does not support.

You have two sites, and one of them has HTTP binding but does not has HTTPS, and the other has HTTPS but not HTTP.

So when you browse to http:// URL, IIS directs you to the (surprise!) http-enabled site, reads web.config, sees that it registers https endpoint (which is not supported by the site) and throws the exception telling that there is no https scheme support on the http-enabled-only site.

When you browse to the https:// URL the situation is similar - IIS does not allow you to use http endpoint on the https-enabled-only site.

To handle the issue you better use a single site with two bindings.

Another (and more complex) option would be using different web.configs for sites: set up separate sites (pointed to separate folders) and use the publishing and web.config transforming tools of the Visual Studio

Share:
17,357
Billa
Author by

Billa

Updated on June 06, 2022

Comments

  • Billa
    Billa almost 2 years

    I am trying to use https & http for the website. The website has .svc files which act as REST service and called from JavaScript.

    My Config:

    <system.serviceModel>
        <behaviors>
          <endpointBehaviors>
            <behavior name="AjaxBehavior">
              <webHttp />
            </behavior>
          </endpointBehaviors>
          <serviceBehaviors>
            <behavior name="MyServiceBehaviour">
              <serviceDebug includeExceptionDetailInFaults="true" />
              <serviceMetadata httpGetEnabled="True" httpsGetEnabled="true"/>         
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
        <services>
          <service behaviorConfiguration="MyServiceBehaviour" name="MyService.Lookups">
            <endpoint address="" behaviorConfiguration="AjaxBehavior"
              binding="webHttpBinding" bindingConfiguration="httpWebBinding" contract="MyService.Lookups" >         
            </endpoint>
            <endpoint address="" behaviorConfiguration="AjaxBehavior"
              binding="webHttpBinding" bindingConfiguration="httpsWebBinding" contract="MyService.Lookups" >          
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
          </service>
        </services>
        <bindings>      
          <webHttpBinding>
            <binding name="httpsWebBinding">
              <security mode="Transport">
                <transport clientCredentialType="None" proxyCredentialType="None" />
              </security>
            </binding>
            <binding name="httpWebBinding">
              <security mode="None">
                <transport clientCredentialType="None" proxyCredentialType="None" />
              </security>
            </binding>
          </webHttpBinding>
        </bindings>   
      </system.serviceModel>
    

    Browsing https://myserver/services/Lookups.svc/Hello gives

    Could not find a base address that matches scheme http for the endpoint with binding WebHttpBinding. Registered base address schemes are [https]

    Browsing http://myserver/services/Lookups.svc/Hello gives

    Could not find a base address that matches scheme https for the endpoint with binding WebHttpBinding. Registered base address schemes are [http]

    If I remove any one endpoint it works. Example removing endpoint configured with bindingConfiguration="httpWebBinding" works for HTTPS ,

    How can I make it work with HTTP and HTTPS? As of now, I can able to use either http or https by removing one endpoint.

    Referred How can I combine the WCF services config for both http and https in one web.config? and How do you setup HTTP and HTTPS WCF 4 RESTful services?

    Note: In IIS, it is two web sites one listen on http and another on https. Both sharing same code in physical folder

    UPDATE: As of now, I removed endpoints and it works. But my concern is removing endpoing configured with behaviourConfiguration doesnt look great solution to me.

    This works for both http & https

      <services>
          <service behaviorConfiguration="MyServiceBehaviour" name="MyService.Lookups">
    
          </service>
        </services>
    
  • Billa
    Billa about 8 years
    Yes. In server, we have created https binding and placed a self signed certificate. As we are not using Mutual authentication we did not enable RequireSSL flag in SSL settings in IIS 8.5