Saturday, March 29, 2008

Can't add web reference in VS 2008 due to computer name being used for schemaLocation

Description:
You can’t add a web reference using Visual Studio 2008 for a WCF service since the WSDL is using the computer name rather than the service address. If you develop using "localhost" as the service name this is NOT an issue.

Context:
You have a computer/website with more than one IP address and are developing a WCF web service on one of the extra IP addresses (Site A).

Issue:
When you use Visual Studio 2008 to add a reference to a web service on Site A, you will get an error something like:

The document at the url http://192.168.0.54:8000/abcService.svc was not
recognized as a known document type.
The error message from each known type may help you fix the problem:
- Report from 'WSDL Document' is 'The document format is not recognized (the
content type is 'text/html; charset=utf-8').'.
- Report from 'DISCO Document' is 'There was an error downloading
'http://192.168.0.54:8000/abcService.svc?disco'.'.
- The request failed with HTTP status 404: Not Found.
- Report from 'XML Schema' is 'The document format is not recognized (the
content type is 'text/html; charset=utf-8').'.

If you look manually enter the service url in a browser for the service at the IP address (e.g. 192.168.0.54), you will see in the XML WSDL that it is trying to import schemas (schemaLocation) using the computer name, not the service address (192.168.0.54).

Fix:
I fixed this by just making sure I entered the IP address as the host header in IIS. Then the IP address was used rather than the computer name for all WSDL url references.

No comments:

Can't RDP? How to enable / disable virtual machine firewall for Azure VM

Oh no!  I accidentally blocked the RDP port on an Azure virtual machine which resulted in not being able to log into the VM anymore.  I did ...