WebHttpBinding with Http and Https

不问归期 提交于 2019-12-04 00:37:38

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.

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

Add This Code.

<protocolMapping>
  <add scheme="http"  binding="webHttpBinding" bindingConfiguration="httpWebBinding"/>
  <add scheme="https" binding="webHttpBinding" bindingConfiguration="httpsWebBinding"/>
</protocolMapping>

If you update your endpoint configs like such:

        <endpoint address="http://myserver/services/Lookups.svc" behaviorConfiguration="AjaxBehavior"
          binding="webHttpBinding" bindingConfiguration="httpWebBinding" contract="MyService.Lookups" >         
        </endpoint>
        <endpoint address="https://myserver/services/Lookups.svc" behaviorConfiguration="AjaxBehavior"
          binding="webHttpBinding" bindingConfiguration="httpsWebBinding" contract="MyService.Lookups" >          
        </endpoint>

I have done a similar dance with a prod system, and this was my solution. Hope it works for you as well.

user11151787

I dont't know this query is still active or not but as i checked Please

Add binding="mexHttpsBinding" also with binding="mexHttpBinding" with different endpoint

This helps me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!