【问题标题】:The provided URI scheme 'https' is invalid; expected 'http'. Parameter name: via for HTTPS提供的 URI 方案“https”无效;预期的“http”。参数名称:通过 HTTPS
【发布时间】:2015-11-19 06:51:10
【问题描述】:

以下是场景。

我们有 F5 负载均衡器,传入的请求以 HTTP 的形式进入 F5 负载均衡器,然后它们以 HTTP 的形式重定向到 WCF 服务服务器。

我已经尝试了几乎所有可能的配置组合,但它总是给出两个不同的错误。例如,根据一些建议,我尝试将安全模式更改为“传输”,然后错误变为如下:“无法为 SSL/TLS 建立安全通道,权限为 'xxx.xxx.xxx.xxx:XXXX' 。”

服务器配置:

<system.serviceModel>
    <services>
      <service behaviorConfiguration="NameofServiceBehaviour" name="NameOfServices">
        <endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsHttpEndPointBinding" name="wsHttpEndPoint" contract="Name.IContractName" />
      </service>
    </services>
    <bindings>
      <wsHttpBinding>
        <binding name="wsHttpEndPointBinding">
          <security mode="None"> 
        <!-- <transport clientCredentialType="Certificate" /> -->
      </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehaviourName">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
          <!-- <serviceCredentials>
            <serviceCertificate findValue="CN=CertificateName" storeLocation="LocalMachine" />
          </serviceCredentials> -->
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="false" />
  </system.serviceModel>

客户端配置:

<system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="wsHttpEndPoint">
                    <security mode="None" />
                </binding>
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="https://URL.svc"
                binding="wsHttpBinding" bindingConfiguration="wsHttpEndPoint"
                contract="Name.IContractName" name="wsHttpEndPoint" />
        </client>
    </system.serviceModel>

问候, 纳西尔

【问题讨论】:

  • 在这个链接中抢夺,它可以帮助你:codeproject.com/Articles/36705/…
  • Ricardo - 此链接仅在不涉及负载平衡器的情况下有效。我试过这个。如果我删除负载均衡器并直接调用我的 WCF 服务器,那么它工作正常。但是使用负载均衡器就不行了。
  • 如果您的负载均衡器配置为卸载 SSL,并且负载均衡器和您的 WCF 服务(托管服务器)之间的流量通过 http,您可以将绑定更改为 basichttp。对于这种情况,您不需要 wshttpbindingbinding。

标签: wcf https wcf-hosting


【解决方案1】:

在负载均衡器下我遇到了这个问题,修复是在客户端这样的:

<system.serviceModel>        
    <bindings>
      <customBinding>
        <binding name="MyBindingConfig">
          <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16" messageVersion="Soap11" writeEncoding="utf-8">
          </textMessageEncoding>
          <httpsTransport  authenticationScheme="Anonymous" bypassProxyOnLocal="false" proxyAuthenticationScheme="Anonymous"/>
        </binding>
      </customBinding>
    </bindings> 
    <client>
        <endpoint address="https://YOUR-END-POINTURL-WITH-HTTPS"
            binding="customBinding" bindingConfiguration="MyBindingConfig"
            contract="ServiceReference.YOURCONTRACT" name="TEST" />
    </client>
</system.serviceModel>

您还可以看到,当您在 VisualStudio 上添加 Web 服务引用并使用 HTTPS 放置 URL 时,它将自动在没有 S 的客户端端点子节点(客户端 app.config)上添加 URL(HTTP 因为loadbalancer),那么您可以继续使用 HTTPS 更新它,就像我在上面的示例中所做的那样。 希望对您有所帮助。

【讨论】:

  • 这就是我要找的,顺便说一句,这可以在 c# 代码上完成,无需配置文件,var encodingElement = new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8); var transportElement = new HttpsTransportBindingElement(){ AuthenticationScheme = System.Net.AuthenticationSchemes.Anonymous, BypassProxyOnLocal = false, ProxyAuthenticationScheme = System.Net.AuthenticationSchemes.Anonymous }; var customBinding = new CustomBinding(encodingElement, transportElement); var client = new Client(customBinding, new EndpointAddress("https://ENDPOINT"));
  • @PabloRecalde 很高兴它对你有用。是的,我们可以选择最好的方式来做到这一点。
【解决方案2】:

我通过this link 找到了答案。关键是在自定义绑定中设置以下参数:

<security allowInsecureTransport="true" enableUnsecuredResponse="true">

【讨论】:

  • 如果您允许 InsecureTranport 和响应,那么 SSL 的意义何在?
  • 它可能有效,但从安全角度来看这不是一个好的解决方案
  • 我不认为这里的反对票是完全公平的。如果您将 http 绑定更改为 https,您将遇到此问题。显然,不安全的通道否定了 https 的好处,但它可能是正确保护通道的中间步骤。
猜你喜欢
  • 2012-02-19
  • 1970-01-01
  • 2011-01-27
  • 1970-01-01
  • 2021-11-03
  • 2010-12-14
  • 1970-01-01
  • 1970-01-01
  • 2012-04-09
相关资源
最近更新 更多