title: WCF: Programmatically enable both https and http on same ip/port
body: <p>I have read <a href="https://stackoverflow.com/questions/22992136/wcf-http-and-https-on-the-same-host-port">some posts</a> here, claiming that WCF can allow http and https on the same endpoint/port, but that sounds a bit wrong to me. I tried to set it up but I cannot figure out how to enable both https and http listening on the same port/ip, <em>programmtically</em>.</p>
  
  <p>I get the following error when I try to add https:</p>
  
  <blockquote>
    <p>'System.ServiceModel.AddressAlreadyInUseException' in
    System.ServiceModel.dll HTTP could not register URL
    <a href="https://+:10901/Service/" rel="nofollow noreferrer">https://+:10901/Service/</a>. Another application has already
    registered this URL with HTTP.SYS.</p>
  </blockquote>
  
  <p>It works fine if I add just one of them.</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>Uri httpsUri = new Uri("https://" + localIp.ToString() + ":" + settings._WebservicePort.ToString() + "/Service/");
  Uri httpUri = new Uri("http://" + localIp.ToString() + ":" + settings._WebservicePort.ToString() + "/Service/");
  
  host = new WebServiceHost(typeof(Service), httpUri, httpsUri);
  
  WebHttpBinding whbHttp = new WebHttpBinding
  {
      CrossDomainScriptAccessEnabled = true,
      Security = { Mode = WebHttpSecurityMode.None },
      MaxReceivedMessageSize = 10000000
  };
  
  WebHttpBinding whbHttps = new WebHttpBinding
  {
      CrossDomainScriptAccessEnabled = true,
      Security = { Mode = WebHttpSecurityMode.Transport },
      MaxReceivedMessageSize = 10000000
  };
  ServiceEndpoint seHttp = host.AddServiceEndpoint(typeof(IService), whbHttp, httpUri);
  seHttp.Behaviors.Add(new WebHttpBehavior());
  
  ServiceEndpoint seHttps = host.AddServiceEndpoint(typeof(IService), whbHttps, httpsUri);
  seHttps.Behaviors.Add(new WebHttpBehavior());
  
  ServiceDebugBehavior stp = host.Description.Behaviors.Find&lt;ServiceDebugBehavior&gt;();
  stp.HttpHelpPageEnabled = true;
  
  host.Open(); // &lt;-- Exception: 'System.ServiceModel.AddressAlreadyInUseException' in System.ServiceModel.dll HTTP could not register URL https://+:10901/Service/. Another application has already registered this URL with HTTP.SYS.
  </code></pre>
  
  <p>I realize that web http is port 80 and https is normally 443, but why am I then reading that http and https can be hosted on the same port? Am i misreading, and its actually not possible? =)</p>