title: Could not create SSL/TLS secure channel works on winforms but not in asp.net
body: <p>I have a web service which I have registered via "add service reference" that requires HTTPS and a certificate. Below is my code for instantiating my service:</p>
  
  <pre><code>        service = new MyReferencedWebService();
  
          X509Certificate2 cert = new X509Certificate2();
  
          var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Mycert.cer");
          var bytes = new byte[stream.Length];
  
          stream.Read(bytes, 0, bytes.Length);
  
          cert.Import(bytes, MYPASSWORD, X509KeyStorageFlags.DefaultKeySet);
  
          service.ClientCredentials.ClientCertificate.Certificate = cert;
  </code></pre>
  
  <p>and my config looks like this:</p>
  
  <pre><code>&lt;system.serviceModel&gt;
      &lt;bindings&gt;
          &lt;basicHttpBinding&gt;
              &lt;binding name="RecordGeneratorWebServiceSoapHttp"&gt;
                  &lt;security mode="Transport"&gt;
                      &lt;transport clientCredentialType="Certificate" /&gt;
                  &lt;/security&gt;
              &lt;/binding&gt;
          &lt;/basicHttpBinding&gt;
      &lt;/bindings&gt;
      &lt;client&gt;
          &lt;endpoint address="https://mywebserviceurl"
              binding="basicHttpBinding" bindingConfiguration="RecordGeneratorWebServiceSoapHttp"
              contract="MyService.RecordGeneratorWebServiceInterface"
              name="RecordGeneratorWebServicePort" /&gt;
      &lt;/client&gt;
  &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p>If I create a simple winforms .exe and use the above code I get a response from my web service. However, if I put this same code in ASP.NET I get the following:</p>
  
  <p><strong>The request was aborted: Could not create SSL/TLS secure channel.</strong></p>
  
  <p>How do I make this work in ASP.NET?</p>
  
  <p><strong>EDIT:</strong>
  I should add. The client certificate that I am using is tied to a smart card and requires a PIN to be entered for use. Not sure if that makes any difference or not.</p>
  
  <p>When a client logs into the application it prompts them for their certificate PIN. In this case they have a CAC card inserted into a CAC reader. So maybe I can somehow use the Request.ClientCertificate?</p>