Compartir a través de


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>

Comments

  • Anonymous
    August 22, 2007
    I tried to change the SSL hostname, but I get an error... On technet it seems that you cannot specify an host name (as you can do with the non SSL). Same behavior with IIS manager. Do you succeed on setting the host name in SecureBindings? Ciao Carlo

  • Anonymous
    August 27, 2007
    Yes, it should work. Carlo, what error did you? Did you restart IIS after that? Note, you need to update your certificate after changing the hostname. Check my other blog: http://blogs.msdn.com/wenlong/archive/2007/08/17/how-to-skip-server-certificate-validation-error-when-using-https.aspx

  • Anonymous
    August 29, 2007
    There are three steps you need to take to make it work. 1. Modify your hosts file under WindowsSystem32driversetchosts

  • Anonymous
    August 31, 2007
    If I change the SecureBindings via the script the web goes on stopped state. In  the event viewer I see The virtual site '1' has been invalidated and will be ignored because valid site bindings could not be constructed, or no site bindings exist. In the IIS manager there isn't a way to change it. Ciao Carlo

  • Anonymous
    August 31, 2007
    Is there any way of changing the location inside the wsdl in service level configuration or programming? I can not change the settings in IIS.

  • Anonymous
    September 17, 2008
    What if we want the clients to connect to an IP instead of a domain name?  I have not been able to get this setting to work.  I have only seen examples where people suggest changing the host header to a FQDN.