我有以下代码可以使用客户端证书访问 Web 服务。当我在控制台应用程序中运行此代码时,一切似乎都运行良好。如果我尝试从在 IIS 7 中运行的 Web 应用程序运行它。我收到错误消息“请求已中止:无法创建 SSL/TLS 安全通道。”
这是代码:
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3 | System.Net.SecurityProtocolType.Tls; //from other stackoverflow case
System.Net.ServicePointManager.Expect100Continue = true; //from other stackoverflow case
db2wsService service = new db2wsService();
service.Url = this.WebserviceUrl;
HttpServerUtility server = HttpContext.Current.Server;
X509Certificate certificate = new X509Certificate(server.MapPath(this.CertificatePath), this.CertificatePassword);
service.ClientCertificates.Add(certificate);
service.PreAuthenticate = true;
//do some stuff here to call webservices