1

I'm trying to configure a WCF REST service to be accessible using HTTP as well as using HTTPS.

Since this is an in production service I would like to minimize the changes required to get HTTPS up and running. I would like to achieve a solution in which the admin only needs to replace the http:// with https://. According to this Wcf HTTP and HTTPS on the same host/port it should be possible to achieve this but I'm struggling with the configuration.

<services>
    <service name="My.Server">      
        <!-- HTTP services -->
        <endpoint address="/Common/"
                  behaviorConfiguration="restEndpointBehavior"
                  binding="webHttpBinding"
                  contract="My.IServer" />      
        <!-- HTTPS services -->
        <endpoint address="/Common/"
                  behaviorConfiguration="restEndpointBehavior"
                  binding="webHttpBinding"
                  bindingConfiguration="httpsBindingConfiguration"
                  contract="My.IServer" />
        <host>
            <baseAddresses>
                <add baseAddress="http://localhost:8732/MyService" />
                <add baseAddress="https://localhost:8732/MyService" />
            </baseAddresses>
        </host>
    </service>
</services>

Everything works fine as long as I'm just using either the HTTP or the HTTPS binding (tested using Postman) but as soon as I activate both endpoints the service startup fails stating:

Service cannot be started. System.ServiceModel.AddressAlreadyInUseException: HTTP could not register URL https://+:8732/MyService/Common/. Another application has already registered this URL with HTTP.SYS. ---> System.Net.HttpListenerException: Failed to listen on prefix 'https://+:8732/MyService/Common/' because it conflicts with an existing registration on the machine.

I'm aware of all the netsh http urlacl|sslcert stuff and can confirm that those should not be an issue since using only one endpoint (either HTTP or HTTPS) or changing the port for HTTPS e.g. :8733 fixes the issue and the service reponds as expected but as stated earlier I would like to use the same ports.

After researching and trying for quite some time now my guess is that such a configuration is not supported. Can anybody confirm my guess or does know a way to achieve the desired result?

slator
  • 33
  • 3

1 Answers1

0

You know those endpoints should uses different bindingConfiguration as you have done it, I setup http and https for a service on port 80 and they are working nice but before anything I defined the configuration like below:

<webHttpBinding>
  <binding allowCookies="true" openTimeout="00:00:10" maxReceivedMessageSize="20000000">
    <readerQuotas maxDepth="32" maxArrayLength="200000000" maxStringContentLength="200000000" />
    <security mode="None" />
  </binding>
  <binding name="secureWebHttpBinding">
    <security mode="Transport">
      <transport clientCredentialType="None" />
    </security>
  </binding>
</webHttpBinding>

and then defining endpoints like:

<service behaviorConfiguration="Commom2.Behavior" name="name"> 
  <endpoint address="rest" behaviorConfiguration="Rest.Behavior" binding="webHttpBinding"  contract="x">
    <identity>
      <dns value="localhost" />
    </identity>
  </endpoint>
  <endpoint address="rest" behaviorConfiguration="Rest.Behavior" binding="webHttpBinding" bindingConfiguration="secureHttpBinding" contract="x">
    <identity>
      <dns value="localhost" />
    </identity>
  </endpoint>
  <host>
    <baseAddresses>
      <add baseAddress="http://localhost/serviceName.svc" />
    </baseAddresses>
  </host>
</service>

Note:
I enabled https binding and uploaded valid certificate there and I have configur-ed one baseAddresses on http as you can see in config but that service is accessible on http://localhost/serviceName.svc/rest and https://localhost/serviceName.svc/rest

Your problem may because of having two baseAddresses and wrong port registered for https.

Aria
  • 3,724
  • 1
  • 20
  • 51
  • 1
    Thanks for your answer Aria. You are running your service through IIS right? Unfortunately I'm running the service in a Self-Hosted scenario (Windows service) so I do not have a webserver in front of WCF. – slator Jan 22 '19 at 10:07
  • Did you check this https://stackoverflow.com/questions/3688342/windows-service-hosted-wcf-over-https – Aria Jan 22 '19 at 10:10
  • Just checked your link but it does not really relay to my problem since I try to accomplish a port sharing (in my example :8732) whereas Rob tries to run a service using the HTTPS protocol. I've got HTTPS up and running but I need to use another port e.g :8733 – slator Jan 22 '19 at 10:45