请求已中止:无法创建SSL/TLS安全通道的.Net 4.5.2

请求已中止:无法创建SSL/TLS安全通道的.Net 4.5.2

问题描述:

请帮助我的人, 当调用第三方Web服务,它表明:请求已中止:无法创建SSL/TLS安全通道的.Net 4.5.2

Initializing 
Generating WSDL 
System.InvalidOperationException: General Error https://xxx ---> System.Net.WebException: There was an error downloading 'https:/xxx'. ---> System.Net.WebException: The request was aborted: Could not create 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.Discovery.DiscoveryClientProtocol.Download(String& url, String& contentType) 
    --- End of inner exception stack trace --- 
    at System.Web.Services.Discovery.DiscoveryClientProtocol.Download(String& url, String& contentType) 
    at System.Web.Services.Discovery.DiscoveryClientProtocol.DiscoverAny(String url) 
    at WebServiceStudio.Wsdl.ProcessRemoteUrls(DiscoveryClientProtocol client, StringCollection urls, XmlSchemas schemas, ServiceDescriptionCollection descriptions) 
    --- End of inner exception stack trace --- 
    at WebServiceStudio.Wsdl.ProcessRemoteUrls(DiscoveryClientProtocol client, StringCollection urls, XmlSchemas schemas, ServiceDescriptionCollection descriptions) 
    at WebServiceStudio.Wsdl.Generate() 

我已经尝试使用X509证书,给予用户全部权限。

+0

1)检查事件日志。 2)你可以在浏览器中访问端点吗? – Ben

+0

我无法访问端点,因为无法从浏览器(https)访问web服务。我该怎么办 ? –

+0

如果端点根本无法访问*这不是一个编程问题。与供应商交谈:服务是否已启动?你有没有正确的网址?与您的网络管理员联系。防火墙是否阻止了它? – Ben

当Web服务的SSL证书无效时可能会发生这种情况。

要解决该问题,请尝试以下代码:

System.Net.ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(delegate 
{ 
    return true; 
}); 

如果这能解决您的问题,那么你应该检查你的机器上的证书。

正如@ dman2306所说,这只是为了检查证书是否是问题的原因。 请勿在任何生产代码中使用此项。

+2

我觉得澄清你的意思很重要:这个代码不应该在生产环境中使用。 @plusheen建议你使用它来测试你是否有证书问题,而不是解决方法。 – dman2306

+0

@ dman2306好点,补充说明。 – plusheen

+0

我已经尝试了这种解决方法,仍然没有线索 –