Zulfiqar's weblog

Architecture, security & random .Net

Using Request Headers for Metadata Address

Posted by zamd on January 14, 2010

WCF by default adds the listen address of the endpoints in the WSDL so in a scenario where the private address of the server is different from the public address you get incorrect endpoint address in WSDL.

For example if a service is listening on http://localhost:7721/ and you access its metadata using a virtual IP, you get following:


Now this behavior might not work in certain scenarios and you want the metadata generation to dynamically pick the address from the request headers, similar to ASMX web services.

UseRequestHeadersForMetadataAddressBehavior enables exactly this. This opt-in behavior sets the address of endpoints dynamically, based on the request header.  

Like all other WCF behaviors, this behavior can be enabled either in the code or config.

sh.Description.Behaviors.Add(new UseRequestHeadersForMetadataAddressBehavior());










As part of this behavior, you can also specify default ports for different schemes (http,https etc..). These default ports come into action in following scenarios:

  • When metadata is accessed over http, all http based URIs are substitued with the Hostname and host port from the Host header
  • All https based URIs picks the default port registered against https scheme
  • Similarly when metadata is accessed over https, all https URIs pick up the host and port from the host header and http based URIs used the default port registered against http scheme

This behavior is added in .NET 4.0 and there is a QFE available for 3.5 SP1: http://support.microsoft.com/kb/971842

4 Responses to “Using Request Headers for Metadata Address”

  1. zamd said

    This options solve this problem http://social.msdn.microsoft.com/forums/en-US/wcf/thread/a32f8a7f-a854-466c-a59d-dc68455e3525/ ?

  2. zamd said


  3. One of several true tests of leadership is the capacity to recognize a difficulty before it becomes an emergency.
    While in doubt, mumble; when in trouble, delegate; a lot more charge, ponder.

  4. AJ said

    Thanks! Works like a charm. It is magic!!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: