1) Write two endpoints for the service, one is for http and another for https.
<services>
<service behaviorConfiguration="MyServiceBehavior" name="JK.MyService">
<endpoint address="" behaviorConfiguration="WebBehavior" binding="webHttpBinding" bindingConfiguration="webBinding" contract="JK.IMyService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="" behaviorConfiguration="WebBehavior" binding="webHttpBinding" bindingConfiguration="webBindingHTTPS" contract="JK.IMyService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</service>
</services>
2) Enable both httpGetEnabled="True" httpsGetEnabled="true" in serviceBehaviors.
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="WebBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
3) Write two bindings configurations for http and https. For http give security mode="None" and for https give mode="Transport".
<bindings>
<webHttpBinding>
<binding name="webBinding">
<security mode="None">
<transport clientCredentialType="None" />
</security>
</binding>
<binding name="webBindingHTTPS">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</webHttpBinding>
</bindings>
Below are the complete configuration settings in web.config:
<system.serviceModel>
<services>
<service behaviorConfiguration="MyServiceBehavior" name="JK.MyService">
<endpoint address="" behaviorConfiguration="WebBehavior" binding="webHttpBinding" bindingConfiguration="webBinding" contract="JK.IMyService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="" behaviorConfiguration="WebBehavior" binding="webHttpBinding" bindingConfiguration="webBindingHTTPS" contract="JK.IMyService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="WebBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="webBinding">
<security mode="None">
<transport clientCredentialType="None" />
</security>
</binding>
<binding name="webBindingHTTPS">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>
37 comments:
This was a great help. Thank you!
Thanks. This helped!
Thanks brother.Thanks a lot.
Hi,
This is so good and easy to understand.
However, I tried doing the same way to make it work on one of our site, it is giving 404 not found error on Json postback.
The problem is, http has always been working, but gives error when we are on https.
Just FYI, we can get to the website with https and browse. Just that when this service is called it errors out.
Could you please address on this issue.
Thank you!
Thank you so much! You save my day.
Good stuff!
Thank you for this. When I try this out, I get the following error:
Could not find a base address that matches scheme https for the endpoint with binding . Registered base address schemes are [http]
If I comment out the https endpoint, the error disappears (understandably).
Will you be able to help. Thanks heaps! Sam.
GR8 Post..
worked really gud stuff ,thx
I have been looking for something like this for a day now. Great work!
Excellent post. It is really a time saver to me. Thanks a lot.
Good blog.
Good Post!!!
Great!!!
Hi jayakrishna,
I got the error below when I followed this approach.
Configuration binding extension 'system.serviceModel/bindings/true' could not be found. Verify that this binding extension is properly registered in system.serviceModel/extensions/bindingExtensions and that it is spelled correctly.
Here's my config file:
Done the same ...still showing the error:
Could not find a base address that matches scheme https for the endpoint with binding WebHttpBinding. Registered base address schemes are [http]
Any help would be appreciated...Thanks in advance
Great post!!!!!!!!!!
/Harpreet
Wonderful ! Thanks a lot !!!
Hi, thanks for the data but i do this and the http service is working but the https is getting SSL connection error "ERR_SSL_PROTOCOL_ERROR" any idea why?
Thank you!
u r awesome
Thankyou - this post helped me
Very nice... just works
Wonderful ! Thanks a lot !!!
Wow, very good, clean and clear thanks you so much, big helps.
It's worked on production, but don't work on debug mode. i can't run on visual studio.
Error:
Could not find a base address that matches scheme https for the endpoint with binding WebHttpBinding. Registered base address schemes are [http].
Thank you man, I tried many things but failed. I implement this according to your guideline, my problem resolved in couple of minutes. Thanx again
Thank you for a working solution!
Thanks you save my time alomst 2 days I was looking for that..
thanks Again
Thanks for Great Post
Great Post... Helped me a lot
yes, its helpful and working with http and https both
Thanks á´ ery nice blog!
Pretty! This has been an extremely wonderful post. Thanks for supplying this information.
Appreciate this post. Will try it out.
Extremely helpful! Thank you so much Jayakrishna!!
Post a Comment