I'm trying to use WCF 4 to set up a RESTful web service. I'd like the service to be accessible both using HTTP and HTTPS. By default the service is created with the following configuration which works for http but not https:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior>
<webHttp helpEnabled="true" />
</behavior>
</endpointBehaviors>
</behaviors>
<protocolMapping>
<add scheme="http" binding="webHttpBinding" />
</protocolMapping>
</system.serviceModel>
I can then turn on HTTPS for the service by changing the configuration slightly to this:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior>
<webHttp helpEnabled="true" />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<webHttpBinding >
<binding name="SecureWebBinding" >
<security mode="Transport"></security>
</binding>
</webHttpBinding>
</bindings>
<protocolMapping>
<add scheme="http" binding="webHttpBinding" bindingConfiguration="SecureWebBinding"/>
</protocolMapping>
</system.serviceModel>
My question is how do I get the service working with both?
To enable the WCF Web HTTP Help page in code, add a service endpoint and add a WebHttpBehavior to the endpoint setting HelpEnabled to true .
All bindings have a default configuration, and basicHttpsBinding is just basicHttpBinding with security mode set to Transport by default (basicHttpBinding's default is None). This security configuration ensures message privacy, integrity and authenticates the service.
You should try to create two separate end-points. For example,
<system.serviceModel>
<services>
<service name="MyNameSpace.MyService">
<endpoint address="https://www.example.com/MyService.svc"
binding="wsHttpBinding" bindingConfiguration="SecureWebBinding"
contract="MyNameSpace.IMyContract" />
<endpoint address="http://www.example.com/MyService.svc"
binding="basicHttpBinding"
contract="MyNameSpace.IMyContract" />
</service>
<bindings>
<webHttpBinding >
<binding name="SecureWebBinding" >
<security mode="Transport"></security>
</binding>
</webHttpBinding>
</bindings>
</services>
</system.serviceModel>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With