Supporting both HTTP and HTTPS for the same URL in WCF

WCF
Lets say we have a WCF service, with basicHttpBinding for a some endpoint, and we want to serve requests with two different binding configurations - one for http and one for https

For this to work, we need to add the protocol mapping section:

<protocolMapping>
    <add scheme="http"  binding="basicHttpBinding" bindingConfiguration="noSSL"/>
    <add scheme="https" binding="basicHttpBinding" bindingConfiguration="withSSL"/>      
</protocolMapping>

And configure the binding configurations

<basicHttpBinding>
    <binding name="noSSL">
          <security mode="None"/>
    </binding>
    <binding name="withSSL">
          <security mode="Transport"/>
    </binding>
</basicHttpBinding>

Use the same address for the service endpoint but a different binding configuration:

<services>
      <service name="WcfService1.Service1">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="noSSL" contract="MyApp.IMyService" />
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="withSSL" contract="MyApp.IMyService" />
      </service>
</services>

Post a Comment

Previous Post Next Post