大家好,我正在尝试访问启用了 https/ssl 的 soap 网络服务。但是我收到了这个错误:
System.Net.WebException was unhandled
The request was aborted: Could not create SSL/TLS secure channel.
下面是我用来打电话的代码。
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim url As String = "https://10.31.171.199:8443/emc-dfs/services/core/ObjectService?WSDL"
System.Net.ServicePointManager.ServerCertificateValidationCallback = New System.Net.Security.RemoteCertificateValidationCallback(AddressOf ValidateRemoteCertificate)
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls Or SecurityProtocolType.Ssl3
Dim responsestring As String = ""
Dim myReq As HttpWebRequest = WebRequest.Create(url)
Dim proxy As IWebProxy = CType(myReq.Proxy, IWebProxy)
Dim proxyaddress As String
Dim myProxy As New WebProxy()
Dim response As String
myReq.AllowWriteStreamBuffering = False
myReq.Method = "GET"
myReq.ContentType = "application/soap+xml; charset=utf-8"
myReq.PreAuthenticate = True
proxyaddress = proxy.GetProxy(myReq.RequestUri).ToString
Dim newUri As New Uri(proxyaddress)
myProxy.Address = newUri
Dim myResponse As HttpWebResponse = myReq.GetResponse
Dim responsedata As Stream = myResponse.GetResponseStream
Dim responsereader As New StreamReader(responsedata)
response = responsereader.ReadToEnd
End Sub
我在“Dim myResponse As HttpWebResponse = myReq.GetResponse”行收到此错误。
请帮助我解决问题,以及如何调用此服务。请帮助我提供 SSL soap 服务的任何有效示例代码。
谢谢。
最佳答案
可能服务器上的 TLS 版本 不是 1.0?尝试:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls Or SecurityProtocolType.Ssl3 Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls12
除此之外,查看是否设置证书验证委托(delegate)以绕过检查是否有效,即,就在调用请求方法之前:
ServicePointManager.ServerCertificateValidationCallback = Function() 返回 True
关于c# - 如何从 VB.net 或 C# 调用启用 SSL 的 soap webservice,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37907528/