c# - 如何从 VB.net 或 C# 调用启用 SSL 的 soap webservice

标签 c# vb.net web-services ssl soap

大家好,我正在尝试访问启用了 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/

相关文章:

c# - 如何显示/隐藏另一个应用程序的窗口?

c# - 如何以编程方式提供凭据以在 c# 或 vb.net 中使用 google drive api?

java - 在 REST 服务中创建 Jersey 客户端

jQuery .ajax() POST 请求在 RESTful WCF 上抛出 405(方法不允许)

c# - Entity Framework 记录重复项

c# - 读NDS游戏头?

c# - JsonValueProviderFactory : System. ArgumentException:已添加具有相同键的项目

c# - nHibernate - 定义类(和表)时何时使用对象

vb.net - 在 TeamCity 中构建 Web 部署项目时出现 "Incorrect Format"引用错误

java - @AroundInvoke 拦截器在@WebService 类上被调用两次