通过负载均衡器在IIS上的WCF报告错误的基址

时间:2010-10-22 21:49:48

标签: wcf iis https

我正在尝试通过负载均衡器在IIS 6上通过SSL启动WCF服务。我最初的问题是一个明显且相当讨论的问题 - WSDL页面上显示的地址指向https://SERVERNAME/WebServices/mydomainws.svc而不是www.mydomain.com。此问题的答案是在IIS中添加主机头值。我这样做了,它起作用了......在浏览器中查看wsdl时,我现在可以获得 http ://www.mydomain.com/WebServices/mydomainws.svc。如果我点击该链接(非ssl链接),我会得到一个再次引用服务器名称的服务定义。

下一个建议的补救措施是使用WCF Extras,它提供了一个允许您指定基址的扩展名。但是设置该配置条目只更新了soap12:地址。 EndPointReference地址仍在使用计算机名称。

总结:在https://www.mydomain.com/WebServices/mydomainws.svc的网络浏览器中查看的WSDL: http ://www.mydomain.com/WebServices/mydomainws.scv

单击上面的链接会将我带到一个包含以下服务条目的实际wsdl文件:

           的                的         https://ServerName/WebServices/mydomainws.svc               

我的服务器配置文件包含以下serviceModel条目:

<system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="TransportSecurity">
                <security mode="Transport">
                    <message clientCredentialType="None"/>
                    <transport clientCredentialType="None"/>
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <services>
        <service name="mydomain.ws.mydomainws" behaviorConfiguration="mydomainwsBehavior">
            <!-- Service Endpoints -->
            <endpoint address="" **behaviorConfiguration="CorrectEndPoint"** binding="wsHttpBinding" bindingConfiguration="TransportSecurity" contract="mydomain.ws.Imydomainws"/>
            <endpoint address="mex" **behaviorConfiguration="CorrectEndPoint"** binding="mexHttpsBinding" contract="IMetadataExchange"/>
        </service>
    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="mydomainwsBehavior">
                <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                <serviceMetadata httpGetEnabled="true" />
                <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
        </serviceBehaviors>
        <endpointBehaviors>
            **<behavior name="CorrectEndPoint">
                <wsdlExtensions location="https://www.mydomain.com/WebServices/mydomainws.svc" singleFile="true"/>
            </behavior>**
        </endpointBehaviors>
    </behaviors>

    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

    <extensions>
        <behaviorExtensions>
            <add name="wsdlExtensions" type="WCFExtras.Wsdl.WsdlExtensionsConfig, WCFExtras, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
        </behaviorExtensions>
    </extensions>

</system.serviceModel>

有人能指出我正确的方向吗? 谢谢, 乔治

1 个答案:

答案 0 :(得分:6)

这应该由新行为useRequestHeadersForMetadataAddress处理。尝试将此添加到您的服务行为中:

  <serviceBehaviors>
    <behavior name="LoadBalancedBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <useRequestHeadersForMetadataAddress>
        <defaultPorts>
          <add scheme="http" port="80" />
          <add scheme="https" port="443" />
        </defaultPorts>
      </useRequestHeadersForMetadataAddress>

      <!-- Other service behaviors as necesary -->

    </behavior>
  </serviceBehaviors>

此行为在WCF 4.0中可用,并且应作为WCF 3.x的KB提供。