WCF WSDL & xsd:import schemaLocations link to local machine name not domain name while hosted in IIS

By admin - Last updated: Saturday, February 21, 2009 - Save & Share - 3 Comments

When WCF svc web services hosted in IIS, the links within WSDL for xsd schemaLocations uses local machine name, the will cause issues when 3rd parties try to obtain the complete WSDL reference from the server unless they modify the main WSDL file to change those schemaLocations links to use domain name for the xsd:import. (An example of IIS hosted services can be found in my previous blog entry WCF SOAP, JSON, POX Coexists if interested).

To use domain name e.g. http://www.example.com/yourService.svc?wsdl across your WSDL references,
firstly, you need to find out the website id of your IIS website that hosting the WCF web services. Run this VBS script to find out the id, ListWebSiteId.vbs Thanks to Chris Crowe’s blog

Once you get the id of the hosting website in IIS, you can open command prompt a.k.a. cmd and run ( run it as in one line!) command below to display all the properties of the website.

%systemroot%\system32\cscript.exe //nologo 
%systemdrive%\inetpub\adminscripts\adsutil.vbs  enum w3svc/WebsiteId

e.g. the result would look like,

KeyType                         : (STRING) "IIsWebServer"
ServerState                    : (INTEGER) 2
ServerComment               : (STRING) "Default Website"
ServerAutoStart               : (BOOLEAN) True
ServerSize                      : (INTEGER) 1
ServerBindings                 : (LIST) (1 Items)
  ":80:"

SecureBindings                : (LIST) (1 Items)
  ":443:"
.....
.....

ServerBindings and SecureBindings are the parameters we are going to configure.

Run the following line ( run it as in one line!) to configure ServerBinding host header if the WCF allows non-HTTPS traffic. e.g. via port 80.

%systemroot%\system32\cscript.exe //nologo 
%systemdrive%\inetpub\adminscripts\adsutil.vbs 
set /w3svc/WebsiteId/ServerBindings ":80:www.example.com"

Or for HTTPS ( run it as in one line!) to configure SecureBindings host header if the WCF allows HTTPS traffic. e.g. via port 443

%systemroot%\system32\cscript.exe //nologo 
%systemdrive%\inetpub\adminscripts\adsutil.vbs 
set /w3svc/WebsiteId/SecureBindings ":443:www.example.com"

Lastly, restart the IIS by running iisreset in the same command prompt

iisreset

To test, browse your http(s)//www.example.com/yourService.svc and see if the WSDL link uses domain name www.example.com that you defined above, and
check out if xsd:import schemaLocations uses the same domain name to link the XSDs.




Posted in WCF • Tags: , , Top Of Page

3 Responses to “WCF WSDL & xsd:import schemaLocations link to local machine name not domain name while hosted in IIS”

Comment from Ohiostater
Time November 10, 2010 at 6:42 am

If I run this command and it doesn’t wokr, how do I revert?

Pingback from What is the difference between an IIS web site identification and ServerBindings? – Admins Goodies
Time August 22, 2011 at 6:35 pm

[...] some digging around I found some instructions on how to change the ServerBindings in IIS 6.0. I needed my app to be bound to an IP address, and [...]

Comment from Livesaved
Time February 3, 2012 at 9:57 am

Thanks, you’re a life saver! This totally saved the day.

Write a comment


Captcha: nine × 6 =