by David posted on 2005/03/09 |
|
I'm attempting to connect to a server that has issued a .p12 file using a HttpWebRequest.
I've used the following lines of code to get the certificate:
HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create("https://resource.com");
httpWReq.Method = "POST";
httpWReq.ContentType = "application/x-www-form-urlencoded";
CertificateStore certStore = CertificateStore.CreateFromPfxFile(@"C:\Key.p12","PASSWORD",false,KeysetLocation.CurrentUser);
Certificate[] certArray = certStore.EnumCertificates();
Certificate cert = certArray[2];
X509CertificateCollection x509 = httpWReq.ClientCertificates;
x509.Add (cert.ToX509());
X509CertificateCollection x509 = httpWReq.ClientCertificates;
x509.Add (cert.ToX509());
The code works for a windows form application, however when ported to a webservice, I get "Unable to import the PFX file! [error code = 2]" when the web service is called. I believe the keysetlocation must be the currentuser, since when KeysetLocation.LocalMachine is used, the httpWReq doesn't call the resource using the certificate. Any help would be appreciated! |