![](/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.