WCF WSDL location address Issue resolved when hosted over HTTPS with basicHTTPBinding
Recently I was working on a WCF web service which needs SSL implementation using basicHttpBinding, so that the service remains inter-operable and cater to native clients.
Everything was going well, I was able to host my web service over HTTPS (I will detail out the configuration for the same in section below).
But when I deployed on Server, following errors were received when proxy is generated:
The issue lies with the WSDL which generates the location url with client machine name, which restricts generation of appropriate proxy over Internet because it will never be able to resolve machine name over internet.
Here is what the Soap Address location and WSDL Import location look like in my WSDL:
<soap:address location="https://MachineName.mydomain.com/MyService/Service.svc" />
<wsdl:import location="https://MachineName.mydomain.com/MyService/Service.svc?wsdl=wsdl0" />
We will tackle this WSDL Location URL issue later but first I would like to tell how basicHTTPBinding works with SSL.
Steps to get the basicHttpBinding workind on HTTPS
Modify basicHttpBinding to allow security mode = Transport
Everything was going well, I was able to host my web service over HTTPS (I will detail out the configuration for the same in section below).
But when I deployed on Server, following errors were received when proxy is generated:
"Metadata contains a reference that cannot be resolved: "
"The WSDL document contains links that could not be resolved."
The issue lies with the WSDL which generates the location url with client machine name, which restricts generation of appropriate proxy over Internet because it will never be able to resolve machine name over internet.
Here is what the Soap Address location and WSDL Import location look like in my WSDL:
<soap:address location="https://MachineName.mydomain.com/MyService/Service.svc" />
<wsdl:import location="https://MachineName.mydomain.com/MyService/Service.svc?wsdl=wsdl0" />
We will tackle this WSDL Location URL issue later but first I would like to tell how basicHTTPBinding works with SSL.
Steps to get the basicHttpBinding workind on HTTPS
Modify basicHttpBinding to allow security mode = Transport
For end point
Also make httpsGetEnabled to true in serviceMetadata tag
Changing location name in WSDL to make web service proxy generated over HTTPS
All good at this point, WCF web service with above configuration working fine on HTTPS. Said WSDL is also accessible over HTTPS but proxy not getting created.
On investigating the errors and taking a deep dive on WSDL it was found that I have machine names in URL in WSDL, the proxy is trying to reach to these location which will not be accessible over internet. This works fine on Intranet but over internet 'No Way'.
<soap:address location="https://MachineName.mydomain.com/MyService/Service.svc" />
<wsdl:import location="https://MachineName.mydomain.com/MyService/Service.svc?wsdl=wsdl0" />
The host name “MachineName.mydomain.com” is automatically picked up by WCF. In the real production environment, we would want to use a public host name or even an IP address in the address.
Following steps that can help you to make the change:
- Change IIS Site Binding
WCF populates service base addresses based on IIS site bindings. The format of a site binding looks like “::”. 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.mysitename.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.mysitename.com”
- 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:
· Run “iisreset.exe”
- Query the WSDL
Now you will see that
<soap:address location="https://www.mysitename.com/MyService/Service.svc" />
<wsdl:import location="https://www.mysitename.com/MyService/Service.svc?wsdl=wsdl0" />
That's it!! Everything is in place now and proxy is generated as expected using the WSDL.
Comments
Post a Comment