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:
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; and my config looks like this:
<system.serviceModel> <bindings> <basicHttpBinding> <binding name="RecordGeneratorWebServiceSoapHttp"> <security mode="Transport"> <transport clientCredentialType="Certificate" /> </security> </binding> </basicHttpBinding> </bindings> <client> <endpoint address="https://mywebserviceurl" binding="basicHttpBinding" bindingConfiguration="RecordGeneratorWebServiceSoapHttp" contract="MyService.RecordGeneratorWebServiceInterface" name="RecordGeneratorWebServicePort" /> </client> </system.serviceModel> 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:
The request was aborted: Could not create SSL/TLS secure channel.
How do I make this work in ASP.NET?
EDIT: 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.
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?