Fixing WSDL import errors with WCF services running on Windows Azure
Posted: (EET/GMT+2)
Developing WCF services with Visual Studio 2010 is a breeze, but sometimes when deploying your ready-made solution to Microsoft's cloud platform Azure can cause challenges. One challenge is when you are writing your client application for the WCF service running on Azure: when you try to add a service reference to your WCF service by point to its WSDL document, you will get an error.
The error message shown by Visual Studio is to the following effect:
An error (Details) occurred while attempting to find services at 'http://myapp.cloudapp.net/Service.svc'
And, if you click the Details hyperlink, your will get the following message:
The document at the url http://myapp.cloudapp.net/Service.svc was not recognized as a known document type.
Although this conclusion is not completely correct, the list following the error message points you to the right direction:
The remote name could not be resolved: 'rd00145d3706c7'
This is the true reason for this error. In fact if you take a look at the raw WSDL document, you will see that it contains references to addresses such as http://rd00145d3706c7:20000/. These are internal host addresses (server names) used by Azure. For the WSDL document to be correct to the outside world, you should instead use your public DNS name like http://myapp.cloudapp.net/. Technically speaking, this is the load-balancer address for your WCF service/Azure web application.
How then would you fix this problem with .NET 3.5? Firstly, you will need to install a hotfix to your development machine and/or the build computer used to create the published packages. Then, you will need to add a single element to your WCF service's web.config file.
The hotfix is discussed in Microsoft's Knowledge Base article 977420 and for example for Windows 7, the patch can be downloaded here. Once you have installed this hotfix, return to Visual Studio and open your project's web.config file. Look for the serviceBehaviors element (usually at the end of the file), and then add the following data:
<behaviors>
<serviceBehaviors>
<behavior name="MyWebRole.MyServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<useRequestHeadersForMetadataAddress>
<defaultPorts>
<add scheme="http" port="81" />
<add scheme="https" port="444" />
</defaultPorts>
</useRequestHeadersForMetadataAddress>
</behavior>
</serviceBehaviors>
</behaviors>
Here, the useRequestHeadersForMetadataAddress element and its subelements are the ones you should add. Shortly put, the hotfix enables the support for this element (Visual Studio doesn't know about it), and after you build and publish (deploy) your new version of the WCF service, the WSDL problem is gone.
The final step is of course to retry adding the service reference to your client project. This should now succeed just fine.
Good luck!