title: Getting HTTPS to Work with WCF and a Windows Service
body: <p>I tried updating the App.config files for the client and service for the MS sample applications in WF_WCF_Samples\WCF\Basic\Services\Hosting\WindowsService\CS\WindowsService.sln so that secure bindings were used but when the client makes the call to the service method an exception is thrown</p>
  
  <p>"An error occurred while making the HTTP request to https:// .... /servicemodelsamples/service. This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the server."</p>
  
  <p>Inner exception "The underlying connection was closed: An unexpected error occurred on a send"</p>
  
  <p>As far as I can see both the server and client configs match and use Transport security mode and the mex endpoint now uses mexHttpsBinding rather than mexHttpBinding with the service behaviour appropriately enabled.</p>
  
  <p>Can someone tell me what is missing or incorrect as I have tried numerous tweaks with no success?</p>
  
  <p>Thanks</p>
  
  <p>The server and client configs are</p>
  
  <pre><code>    &lt;?xml version="1.0"?&gt;
  &lt;!--Copyright (c) Microsoft Corporation.  All Rights Reserved.--&gt;
  &lt;configuration&gt;
  
    &lt;system.serviceModel&gt;
  
      &lt;services&gt;
        &lt;service name="Microsoft.Samples.WindowsService.WcfCalculatorService"&gt;
          &lt;host&gt;
            &lt;baseAddresses&gt;
              &lt;add baseAddress="https://localhost:8000/ServiceModelSamples/service"/&gt;
            &lt;/baseAddresses&gt;
          &lt;/host&gt;
          &lt;!-- This endpoint is exposed at the base address provided by host: https://localhost:8000/ServiceModelSamples/service --&gt;
          &lt;endpoint address="" binding="basicHttpBinding" bindingConfiguration="https" contract="Microsoft.Samples.WindowsService.ICalculator"/&gt;
          &lt;!-- The mex endpoint is exposed at https://localhost:8000/ServiceModelSamples/service/mex --&gt;
          &lt;endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/&gt;
        &lt;/service&gt;
      &lt;/services&gt;
  
      &lt;bindings&gt;
        &lt;basicHttpBinding&gt;
          &lt;!-- Configure BasicHttp binding with Transport security mode and clientCredentialType as None --&gt;
          &lt;binding name="https"&gt;
            &lt;security mode="Transport"&gt;
              &lt;transport clientCredentialType="None"/&gt;
            &lt;/security&gt;
          &lt;/binding&gt;
        &lt;/basicHttpBinding&gt;
      &lt;/bindings&gt;
  
      &lt;!-- For debugging purposes set the includeExceptionDetailInFaults attribute to true --&gt;
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior&gt;
            &lt;serviceMetadata httpsGetEnabled="true"/&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="true"/&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
  
    &lt;/system.serviceModel&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>and </p>
  
  <pre><code>    &lt;?xml version="1.0"?&gt;
  &lt;!--Copyright (c) Microsoft Corporation.  All Rights Reserved.--&gt;
  &lt;configuration&gt;
    &lt;system.serviceModel&gt;
  
      &lt;client&gt;
        &lt;endpoint name="" address="https://localhost:8000/servicemodelsamples/service" binding="basicHttpBinding" bindingConfiguration="Binding1" contract="Microsoft.Samples.WindowsService.ICalculator"/&gt;
      &lt;/client&gt;
  
      &lt;bindings&gt;
        &lt;basicHttpBinding&gt;
          &lt;!-- Configure BasicHttp binding with Transport security mode and clientCredentialType as None --&gt;
          &lt;binding name="Binding1"&gt;
            &lt;security mode="Transport"&gt;
              &lt;transport clientCredentialType="None"/&gt;
            &lt;/security&gt;
          &lt;/binding&gt;
        &lt;/basicHttpBinding&gt;
      &lt;/bindings&gt;
  
    &lt;/system.serviceModel&gt;
  
  &lt;startup&gt;&lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/&gt;&lt;/startup&gt;&lt;/configuration&gt;
  </code></pre>