请求被中止:无法创建SSL/TLS安全通道异常

问题描述:

让我解释我的情况。请求被中止:无法创建SSL/TLS安全通道异常

我创建了自签名证书,并将其安装在MMC的受信任的根证书颁发机构部分。

我然后使用自签名证书创建两个证书:

  1. 与主题名称的证书“localhost”的
  2. 与主题名称“test.com”

我的证书然后将两个证书安装到MMC中的Personal证书部分。

然后,我在IIS中将HTTPS(具有接受客户端证书的SSL)部署为Web服务。用于部署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; 
} 

来源: The request was aborted: Could not create SSL/TLS secure channel

+0

感谢您的提示。我设法通过从头开始重新生成证书来解决问题。然后它完美地工作。我不知道为什么,但然后它的工作。 – 2013-04-25 19:31:36