6

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?

1 Answer 1

7

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>
1
  • 1
    I guess it should be https://ww.xyz.com/MyService.svc for the endpoint defined first in your example.
    – Jim Aho
    Mar 4, 2016 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.