How to change HostName in WSDL for an IIS-hosted service?

If you have a web-hosted service “simple.svc” under the virtual application “/simple”, you would probably get the following service address in the WSDL:

<wsdl:service name="SimpleService">

  <wsdl:port name="BasicHttpBinding_ISimpleContract" binding="tns:BasicHttpBinding_ISimpleContract">

    <soap:address location="**https://mycomputer.private.mydomain.com/simple/Simple.svc**" />

  </wsdl:port>

</wsdl:service>

The host name “mycomputer.private.mydomain.com” is automatically picked up by WCF. In the real production environment, you would want to use a public host name or even an IP address in the address. Here are a few steps that can help you to make the change:

1) Change IIS Site Binding

WCF populates service base addresses based on IIS site bindings. The format of a site binding looks like “<ip>:<port>:<hostname>”. For HTTP, the default site binding for the default web site is “:80:”. This means that the service can receive messages from any IP addresses for the host and it uses “weak” wildcard for address registration. You need to change it to be an “exact” host name for the site so that it shows up in your service base address. You can use the IIS utility tool adsutil.vbs (or appcmd.exe on IIS7) to achieve that.

You can query your current site bindings for the default web site as following:

cscript //nologo %systemdrive%\inetpub\adminscripts\adsutil.vbs get W3SVC/1/ServerBindings

Here is the command to change it:

cscript //nologo %systemdrive%\inetpub\adminscripts\adsutil.vbs set W3SVC/1/ServerBindings “:80:www.fancydomain.com”

You can also change it from IIS Manager UI. For HTTPS, the following command would work:

cscript //nologo %systemdrive%\inetpub\adminscripts\adsutil.vbs set W3SVC/1/SecureBindings “:443:www.fancydomain.com”

2) Recycle the AppDomain

Once you changed IIS settings, WCF does not automatically pick up the changes from IIS Metabase. You have to recycle the current AppDomain for the virtual application. There are a few different ways to do that:

· Change web.config file for the virtual application

· Kill w3wp.exe process

· Run “iisreset.exe”

3) Query the WSDL

Now when you query the WSDL of your service, you will see the new addresses:

<wsdl:service name="SimpleService">

  <wsdl:port name="BasicHttpBinding_ISimpleContract" binding="tns:BasicHttpBinding_ISimpleContract">

    <soap:address location="https://www.fancydomain.com /simple/Simple.svc" />

  </wsdl:port>

</wsdl:service>