Reputation:
I am trying to get client certificate in web service.
I add client certificate in proxy object and call web method Verify
.
private void button2_Click(object sender, EventArgs e)
{
string certPath = "D:\\test.pfx";
cert = new X509Certificate2(certPath,"pass");
Service1 obj = new Service1();
obj.ClientCertificates.Add(cert);
textBox2.Text = obj.Verify();
}
Web Method in Web Service:
[WebMethod]
public string Verify()
{
X509Certificate2 cert = new X509Certificate2(Context.Request.ClientCertificate.Certificate);
bool test = cert.Verify();
return test.ToString();
}
In finish with this error:
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Security.Cryptography.CryptographicException: m_safeCertContext is an invalid handle.
I don't know why. I used this sample.
I test web service and client on localhost.
Upvotes: 1
Views: 3653
Reputation: 4828
Have you tried to follow this guide?
- Host the project from IIS - not the thin web server that is bundled with VS2005.
- From within VS2005 select File - New Web Site.
- Select the Location of HTTP then enter the path eg: http://localhost/MyWebSite. Note that you don't have to use HTTPS just yet (I find it easier for development to use HTTP then when deploying to UAT or Production to use HTTPS).
- Code up a test form.
- Go into IIS Admin - right click on the new app (MyWebSite) and select Properties.
- On the Directory Security tab, click Edit... under 'Secure communications'.
- Make sure 'Accept client certificates' is checked.
- When you run your app - make sure you use HTTPS in the url eg: https://localhost/MyWebSite
Upvotes: 1