如何使用负载均衡器在 IIS 中使用 WCF 服务 HTTPS 绑定和端点配置?

Mik*_*e G 8 iis-7 https load-balancing wcf

我们有一个 WCF 服务托管在一组 12 台机器上。有一个负载平衡器是这些机器的网关。

现在站点设置为 SSL;就像用户通过使用带有 https 的 URL 访问它一样。我知道这么多,该站点的 URL 是 https,但没有任何服务器具有 https 绑定或设置为需要 SSL。这让我相信负载平衡器处理 https 并且从平衡器到服务器的连接是未加密的(这发生在防火墙后面,所以没什么大不了的)。

我们遇到的问题是,当 Silverlight 客户端尝试访问 WCF 服务时,它会收到“未找到”错误。我已经与我们的开发人员机器一起建立了一个测试站点,并确保 web.config 中的绑定和端点与客户端一起工作。在生产环境中,我们收到此错误似乎就是这种情况。

下面的 web.config 有什么问题吗?我们应该设置如何以不同的方式处理 https 吗?

我们目前对此不知所措,因为我已经尝试了所有带有端点和绑定的程序化解决方案。我发现的所有解决方案都没有以我们处理的方式处理负载平衡器。

Web.config 服务模型信息:

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="TradePMR.OMS.Framework.Services.CRM.CRMServiceBehavior">
          <serviceMetadata httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
        <behavior name="TradePMR.OMS.Framework.Services.AccountAggregation.AccountAggregationBehavior">
          <serviceMetadata httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>          
      <customBinding>    
        <binding name="SecureCRMCustomBinding">
          <binaryMessageEncoding />
          <httpsTransport />
        </binding>

        <binding name="SecureAACustomBinding">
          <binaryMessageEncoding />
          <httpsTransport />
        </binding>
      </customBinding>
      <mexHttpsBinding>
        <binding name="SecureMex" />
      </mexHttpsBinding>
    </bindings>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />

    <!--Defines the services to be used in the application-->
    <services>
      <service behaviorConfiguration="TradePMR.OMS.Framework.Services.CRM.CRMServiceBehavior"
        name="TradePMR.OMS.Framework.Services.CRM.CRMService">

        <endpoint address="" binding="customBinding" bindingConfiguration="SecureCRMCustomBinding"
          contract="TradePMR.OMS.Framework.Services.CRM.CRMService" name="SecureCRMEndpoint" />

        <!--This is required in order to be able to use the "Update Service Reference" in the Silverlight application-->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>

      <service behaviorConfiguration="TradePMR.OMS.Framework.Services.AccountAggregation.AccountAggregationBehavior"
        name="TradePMR.OMS.Framework.Services.AccountAggregation.AccountAggregation">

        <endpoint address="" binding="customBinding" bindingConfiguration="SecureAACustomBinding"
          contract="TradePMR.OMS.Framework.Services.AccountAggregation.AccountAggregation" name="SecureAAEndpoint" />

        <!--This is required in order to be able to use the "Update Service Reference" in the Silverlight application-->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
  </system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)

ServiceReferences.ClientConfig 如下所示:

<configuration>
    <system.serviceModel>
        <bindings>
            <customBinding>
                <binding name="StandardAAEndpoint">
                    <binaryMessageEncoding />
                    <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
                </binding>
                <binding name="SecureAAEndpoint">
                    <binaryMessageEncoding />
                    <httpsTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
                </binding>
                <binding name="StandardCRMEndpoint">
                    <binaryMessageEncoding />
                    <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
                </binding>
                <binding name="SecureCRMEndpoint">
                    <binaryMessageEncoding />
                    <httpsTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
                </binding>
            </customBinding>
        </bindings>
        <client>
            <endpoint address="https://Service2.svc"
                binding="customBinding" bindingConfiguration="SecureAAEndpoint"
                contract="AccountAggregationService.AccountAggregation" name="SecureAAEndpoint" />
            <endpoint address="https://Service1.svc"
                binding="customBinding" bindingConfiguration="SecureCRMEndpoint"
                contract="CRMService.CRMService" name="SecureCRMEndpoint" />
        </client>
    </system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)

(地址无关紧要,因为它们是动态构建的,因此它们将指向开发人员的机器或生产服务器)

Mik*_*e G 3

我回答这个问题是因为一些知道该应用程序正在生产中的人问我,但在这里没有看到答案。

在上述场景中我们无法解决这个问题。从客户端到负载均衡器的 HTTPS 正常。问题是当负载均衡器获取该连接并将其指向未加密格式的 Web 服务器时。这似乎破坏了 WCF 协议。客户端正在发送 HTTPS 通信,但服务器正在获取未加密的通信。

我们通过传递所有 SSL 通信解决了该问题。

最好的“解决方案”是查看您的 WCF 服务是否未使用 HTTP 传输方法,并设置负载均衡器以不加更改地传递这些通信。然后,负载均衡器可以对网站生成的常规 HTTPS 流量执行其标准操作程序。

我没有对此进行测试,因为我们的应用场景需要 WCF 服务与 ASP.NET 兼容。

希望其他人可以通过更多信息来详细说明这一点。