Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 246
Smithy Avatar asked Aug 02 '26 00:08

Smithy


2 Answers

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.

like image 197
Leigh Avatar answered Aug 04 '26 18:08

Leigh


In the <protocolMapping> section of Web.Config, add a <remove scheme="http" /> element.

like image 21
Randy Holland Avatar answered Aug 04 '26 16:08

Randy Holland



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!