Monday, October 27, 2008

Wrong URL:s in WSDL for Web Service implemented with WCF

If You expose a WCF web service in the following way:

  • The external name (on the public Internet) is webserver1.mycompany.com
  • The internal machine name (in my company’s internal network) is www_1.mycompany.local
  • The service path on the server is  /MyService/MyService.svc
  • The web site that the service resides in does not have any host headers defined.

If You browse (using a web browser) to the URL

http://webserver1.mycompany.com/MyService/MyService.svc,

You will see that the suggested URL to the WSDL is

http://www_1.mycompany.local/MyService/MyService.svc?wsdl .

If You ignore the incorrect URL and browse to

http://webserver1.mycompany.com/MyService/MyService.svc?wsdl (the correct URL for the WSDL), You will see that also the WSDL says that the web service is located at http://www_1.mycompany.local/MyService/MyService.svc.

The problem is that WCF does not realize that the URL of the web service is the external address.

The solution is pretty simple: set correct host header for the web site:

webserver1.mycompany.com for port 80 (and port 443 if You are about to expose the web service using SSL, which You should).

Restart the application pool and reload the service page in Your browser and everything should be fine.

No comments: