【问题标题】:VB.NET WCF using HTTP and HTTPS, detecting 302VB.NET WCF 使用 HTTP 和 HTTPS,检测 302
【发布时间】:2019-01-18 16:38:22
【问题描述】:

我有一个可通过 HTTP 和 HTTPS 使用的 WCF 服务。 我们已经加入了 HTTP 支持以允许本地测试,既可以用于http://localhost/,也可以使用 WireShark 在网络上运行以进行流量分析。 我们想通过 HTTPS 在野外部署代码。 我们制定了 URL 重写规则,因此如果有人选择 http://foo.example.org,他们将通过 302 重定向到 https://foo.example.org,这很有效。 过去,.NET 会对 302 感到不满并发送错误 - 现在它喜欢将其从您身上抽象出来,然后继续工作。这意味着当我们被重定向时我们现在遇到了一个问题,因为我们必须在使用 HTTP 时将绑定安全模式更改为 None,在使用 HTTPS 时将绑定安全模式更改为 Transport

有没有一种方法可以根据连接实际执行的操作来检测我们需要使用哪种安全模式,而不是我们目前拥有的幼稚方法?

Public Sub DeterminineBindingSecurity(ByRef MyBinding As BasicHttpBinding, EndpointAddress As String)
    Select Case EndpointAddress.Split(":").First
        Case "https"
            MyBinding.Security.Mode = BasicHttpSecurityMode.Transport
            MyBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None
        Case Else
            MyBinding.Security.Mode = BasicHttpSecurityMode.None
            MyBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None
    End Select
End Sub

谢谢

【问题讨论】:

    标签: vb.net web-services http wcf https


    【解决方案1】:

    我解决了。 在我做这一步之前,我使用System.Net.Http.HttpClient 来询问端点 URL 并更新 URL

    URL = (Await (New Net.Http.HttpClient()).GetAsync(URL)).RequestMessage.RequestUri.ToString
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-31
      • 2023-03-25
      • 1970-01-01
      • 2022-08-16
      相关资源
      最近更新 更多