Saturday, July 24, 2010

Configuring WCF service work behind Load Balancer

http://support.microsoft.com/kb/971842/en-us

Consider the following scenario:

  • You host a WCF service on an instance behind a load-balancer.
  • You use the “Add Service Reference” command or the svcutil.exe command-line tool to download the metadata from the service.

In this scenario, when you try to generate a proxy from the metadata, the process fails because the metadata contains URIs that reference internal Web site instances.

To enable the hotfix after you installed it, you have to configure the WCF service to use the following service behavior:

<serviceBehaviors>

<behavior name="<name>">

<useRequestHeadersForMetadataAddress>

<defaultPorts>

<add scheme="http" port="81" />

<add scheme="https" port="444" />

</defaultPorts>

</useRequestHeadersForMetadataAddress>

</behavior>

</serviceBehaviors>

Note <name> is a placeholder that you should replace with the behavior name in your WCF service.
The hotfix causes WCF to generate the correct URI by using the "Host" HTTP header of the incoming metadata request. In this case, the "Host" header contains the load balancer address instead of the internal node address.
If a URI inside the WSDL document has a different scheme than the scheme of the "Host" header URI, for example, if a request for metadata comes over HTTPS but the metadata contains HTTP URIs, the hotfix will need the port number for that different scheme. The port number can be specified per scheme in the <defaultPorts> section.

No comments:

Post a Comment