我有使用网络服务的工具。我已经为 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)。您可以使用智能感知来查看您的选项。
我是一名优秀的程序员,十分优秀!