![](/img/trans.png)
[英]The request was aborted: Could not create SSL/TLS secure channel - SecurityProtocol behavior
[英]The request was aborted: Could not create SSL/TLS secure channel Exception
让我解释一下我的情况。
我创建了一个自签名证书,并将其安装在MMC的“ 受信任的根证书颁发机构”部分中。
然后,我使用自签名证书创建了两个证书:
然后我将这两个证书安装到MMC的个人证书部分。
然后,我在IIS中部署了一个Web服务作为HTTPS(具有接受客户端证书的SSL)。 用于部署Web服务的证书是主题名称为“localhost”的证书。
现在,我有一个想要连接到Web服务的客户端。 我成功添加了该服务的Web引用。 这是代码:
ClientServices web_service = new ClientServices();
X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly);
X509Certificate2Collection col = store.Certificates.Find(X509FindType.FindBySubjectName, "test.com", true);
if (col.Count == 1)
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls;
web_service.ClientCertificates.Add(col[0]);
try
{
string hello = web_service.HelloWorld();
int add = web_service.add(4, 31);
int sub = web_service.subtract(30, 10);
Console.WriteLine(hello);
Console.WriteLine(add);
Console.WriteLine(sub);
}
catch (WebException e)
{
Console.WriteLine(e.Message.ToString());
}
}
else
{
Console.WriteLine("The certificate was not found!");
}
Console.ReadKey();
如您所见,我正在发送“test.com”证书以及Web服务请求。 不幸的是,我得到了这个例外:
The request was aborted: Could not create SSL/TLS secure channel
我怎么解决这个问题? 我已经在这个问题上浪费了3个小时。 请帮我。
private void Somewhere() {
ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(AllwaysGoodCertificate);
}
private static bool AllwaysGoodCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors policyErrors) {
return true;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.