2013-04-25 49 views
0

讓我解釋我的情況。請求被中止:無法創建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個小時。請幫幫我。

回答

2
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

相關問題