Search code examples
wcfhttpsweb-config

WCF Services need to be HTTPS only but only work on HTTP


I have some WCF services that have been working for a while now on HTTP.

I'm moving them to deployment server now and they need to be HTTPS only.

I got the certificate and when I initially set the up they worked over both HTTP and HTTPS.

...at this point I wanted to drop the non-secure access to the services.

So I'm trying to make amendments to my web.config to make this happen:

Service Behaviours:

  <serviceBehaviors>
    <behavior name="MetaEnabledBahavior">
      <serviceMetadata httpsGetEnabled="true"/>
    </behavior>
  </serviceBehaviors>

Service Endpoints:

  <service name="Services.BookingService" behaviorConfiguration="MetaEnabledBahavior">
    <!-- Service Endpoints -->
    <clear/>
    <endpoint address="https://website.com/services/BookingService.svc" binding="wsHttpBinding"
       bindingConfiguration="TransportSecurity" contract="Services.IBookingService"/>
    <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
  </service>

Bindings:

<bindings>
  <wsHttpBinding>
    <binding name="TransportSecurity" maxReceivedMessageSize="2000000">
      <security mode="Transport">
        <transport clientCredentialType="None"/>
      </security>
    </binding>
  </wsHttpBinding>
</bindings>

What I have ended up with at the moment is my HTTP services are still accessible, but the HTTPS access just sends a blank page.

I need HTTP to return an error/page must be viewed by secure channel and HTTPS to be the ones that work only.

How do I fix this?


Solution

  • Smithy try replacing your endpoint with the following:

    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="TransportSecurity" contract="Services.IBookingService"></endpoint>
    

    And your binding with a basicHttpBinding

      <basicHttpBinding>
        <binding name="TransportSecurity" maxReceivedMessageSize="2000000">
          <security mode="Transport">
            <transport clientCredentialType="None"/>
          </security>
        </binding>
      </basicHttpBinding>
    

    Hope this helps.