我正在尝试在Web服务中获取客户端证书。
我在代理对象中添加客户端证书并调用Web方法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服务中的Web方法:
[WebMethod]
public string Verify()
{
X509Certificate2 cert = new X509Certificate2(Context.Request.ClientCertificate.Certificate);
bool test = cert.Verify();
return test.ToString();
}
完成此错误:
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Security.Cryptography.CryptographicException: m_safeCertContext is an invalid handle.
我不知道为什么。我使用了this sample。
我在localhost上测试Web服务和客户端。
答案 0 :(得分:1)
您是否尝试过关注this guide?
- 从IIS托管项目 - 而不是捆绑的瘦Web服务器 VS2005。
- 从VS2005中选择文件 - 新网站。
- 选择HTTP的位置,然后输入路径,例如: http://localhost/MyWebSite。注意 您还不必使用HTTPS (我觉得开发更容易 在部署到UAT时使用HTTP 生产使用HTTPS)。
- 编写测试表格。
- 进入IIS管理员 - 右键单击新应用程序(MyWebSite)并选择 属性。
- 在“目录安全性”选项卡上,单击“安全通信”下的“编辑...”。
- 确保选中“接受客户端证书”。
- 运行应用时 - 请确保在网址中使用HTTPS,例如: https://localhost/MyWebSite