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.

Thursday, October 29, 2009

Hosting WCF services in Partial Trust Environment of GoDaddy

When I tried to deploy my WCF web services in GoDaddy’s normal account, I got the below three errors:

  1. There is no build provider registered for the extension '.svc' error.
  2. This collection already contains an address with scheme http error
  3. WSHttpBinding would not work

Below are the resolutions:

1. There is no build provider registered for the extension '.svc' error.

Below error is thrown:

There is no build provider registered for the extension '.svc'. You can register one in the <compilation><buildProviders> section in machine.config or web.config. Make sure is has a BuildProviderAppliesToAttribute attribute which includes the value 'Web' or 'All'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: There is no build provider registered for the extension '.svc'. You can register one in the <compilation><buildProviders> section in machine.config or web.config. Make sure is has a BuildProviderAppliesToAttribute attribute which includes the value 'Web' or 'All'.

clip_image002

In the web.Config, make the below changes under <System.web> element:

clip_image004

<buildProviders>

<remove extension=".svc" />

<add extension=".svc" type="System.ServiceModel.Activation.ServiceBuildProvider,System.ServiceModel, Version=3.0.0.0, Culture=neutral,PublicKeyToken=b77a5c561934e089" />

</buildProviders>

2. This collection already contains an address with scheme http error

Below error is thrown:

This collection already contains an address with scheme http. There can be at most one address per scheme in this collection.

Parameter name: item

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: This collection already contains an address with scheme http. There can be at most one address per scheme in this collection.

Parameter name: item

Resolution:

clip_image006

<serviceHostingEnvironment>

<baseAddressPrefixFilters>

<add prefix="http://api.ajitsingh.net/ajit2/" />

</baseAddressPrefixFilters>

</serviceHostingEnvironment>

3. WSHttpBinding would not work

Change the binding to basicHttpBinding

Below error is thrown:

The WSHttpBinding with name WSHttpBinding failed validation because it contains a BindingElement with type System.ServiceModel.Channels.SymmetricSecurityBindingElement which is not supported in partial trust. Consider disabling the message security and reliable session options, using BasicHttpBinding, or hosting your application in a full-trust environment.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The WSHttpBinding with name WSHttpBinding failed validation because it contains a BindingElement with type System.ServiceModel.Channels.SymmetricSecurityBindingElement which is not supported in partial trust. Consider disabling the message security and reliable session options, using BasicHttpBinding, or hosting your application in a full-trust environment.

clip_image008

Change the binding to basicHttpBinding

clip_image010