c# - 错误 : The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel

标签 c# ssl system.net.webexception

我有使用网络服务的工具。我已经为 Web 服务生成了一个自签名证书,并使用证书管理器将其导出到本地路径。

我正在按照以下 msdn 代码将证书添加到 web 服务中。 https://support.microsoft.com/en-us/kb/901183

string certPath = @"C:\TestData\certificate.cer";
test.ClientCertificates.Add(X509Certificate.CreateFromCertFile(certPath));

上面是我的代码。

我收到以下错误。

The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.

堆栈跟踪:

at System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest request)
at System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse(WebRequest request)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at web_Client.testClient.testClassWebService.Add(Request request) in  C:\Workspace\Reference.cs:line 248
at web_Client.WebClient.Add() in C:\Workspace\WebClient.cs:line 227

我不知道发生了什么。我对网络和证书很陌生。请帮忙。

最佳答案

在过去的几天里,我遇到了一个以前运行良好的应用程序。我认为拥有服务器的人更新了一些东西,现在他们需要一个不同的协议(protocol)。我只是通过迁移到更高版本的框架来解决其中一个问题。对于第二个,我不得不转到更高版本 (4.5) 并将 ServicePointManager.SecurityProtocol 设置为不同的协议(protocol)。您可以使用智能感知来查看您的选项。

关于c# - 错误 : The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32608795/

相关文章:

c# - 是否有任何方法可以执行 Func<Foo> N 次并获取 IEnumerable<Foo>?

Qt OpenSSL 问题 - 在某些计算机上被阻止(?)

java - SSLHandshakeException : Certificate Unknown (Java Spring Boot & Android)

ssl - AWS CloudFront 托管 SSL 并转发到 sendgrid 不工作

c# - 使用 HtmlAgilityPack 下载网页时违反 HTTP 协议(protocol)

c# - 如何避免 403 Forbidden 响应的 WebException?

c# - 为什么我可以对不可变的 `struct` 执行此操作?

c# - 将 iTextSharp 文档加载到 MemoryStream

c# - 加载 SNI.dll 失败

c# - try 没有捕获 WebException