简体   繁体   English

.Net无法创建SSL / TLS安全通道

[英].Net could not create SSL/TLS secure channel

I am posting xml from a .net application to a third party web service but receive a "could not create SSL/TLS secure channel" error. 我正在将XML从.net应用程序发布到第三方Web服务,但收到“无法创建SSL / TLS安全通道”错误。 When I make the request with soapUI it works fine and i get a response. 当我用soapUI发出请求时,它可以正常工作,并且得到响应。 But cant seem to get it from my .net console app. 但是似乎无法从我的.net控制台应用程序中获取它。

I have tried setting the security to tls1 and tls12 but still no success. 我尝试将安全性设置为tls1和tls12,但仍然没有成功。 The certificate is installed on the server from which i am making these requests. 证书安装在我从中发出这些请求的服务器上。

Is there anyone who has managed to solve this issue? 是否有人设法解决了这个问题?

Here is a sample of my code 这是我的代码示例

 System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://thirdPartyURL/cgi-bin/XmlProc");
byte[] bytes;
             bytes = System.Text.Encoding.ASCII.GetBytes("myXML");
            request.ContentType = "text/xml; encoding='utf-8'"; 
            request.ContentLength = bytes.Length;
            request.Method = "POST";                
            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
            Stream requestStream = request.GetRequestStream();
            requestStream.Write(bytes, 0, bytes.Length);
            requestStream.Close();
            HttpWebResponse response;
            response = (HttpWebResponse)request.GetResponse();

Fixed this by doing the following: 通过执行以下操作解决此问题:

  1. Changing the .Net Framework to 4.5 将.Net Framework更改为4.5
  2. Installing the certificate in the "Third-Party Root Authorities" store 在“第三方根目录授权”存储中安装证书
  3. Added this line of code before making the request in my app 在我的应用中发出请求之前添加了此行代码

    System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; SecurityProtocolType.Tls12;

  4. Ran the application on a windows server 2012 instead of windows server 2008. It might be a case that windows server 2008 does not support TLS v1.2 在Windows Server 2012而不是Windows Server 2008上运行该应用程序。WindowsServer 2008可能不支持TLS v1.2的情况

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM