Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF over IIS through load balancer reports wrong base address

Tags:

iis

https

wcf

I'm trying to launch a WCF service over SSL on IIS 6 through a load balancer. My initial problem was an obvious and pretty well discussed one - the address shown on the WSDL page pointed to https://SERVERNAME/WebServices/mydomainws.svc instead of www.mydomain.com. The answer to this problem is to add a host header value in IIS. I did that and it worked... sort of. I now get http://www.mydomain.com/WebServices/mydomainws.svc when viewing the wsdl in a browser. If I click on that link (the non-ssl link) I get a service definition that again references the server name.

The next oft recommended remedy is to use WCF Extras which provides an extension that allows you to specify a base address. But setting that config entry only updated the soap12:address. The EndPointReference address is still using the machine name.

To summarize: WSDL as viewed in web browser at https://www.mydomain.com/WebServices/mydomainws.svc: http://www.mydomain.com/WebServices/mydomainws.scv

Clicking the above link brings me to an actual wsdl file with the following service entry:

https://ServerName/WebServices/mydomainws.svc

My server config file has the following serviceModel entries:

<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>

Can anyone point me in the right direction?
Thanks, George

like image 234
GeorgeBarker Avatar asked Oct 22 '10 21:10

GeorgeBarker


1 Answers

This should be handeled by new behavior useRequestHeadersForMetadataAddress. Try to add this to your service behavior:

  <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>

This behavior is availabel in WCF 4.0 and should be available as KB for WCF 3.x.

like image 146
Ladislav Mrnka Avatar answered Nov 16 '22 01:11

Ladislav Mrnka