Silverlight WCF Returns HTTP 404
Silverlight WCF Returns HTTP 404
Today I ran into something weird. I created a WCF Service and tested it with simple .Net client application and it worked fine. Than, I build a Silverlight application and tried to call the same service, but kept getting: System.ServiceModel.ProtocolException: "The remote server returned an unexpected response: (404) Not Found."
What I found out was that since the WCF call was made to a service that is not under the same domain as my Silverlight application (or different ports in local development machine). This situation turns out to be a cross domain call, and Silverlight required the domain that hosts the WCF service to allow such calls. This can be done by placing a file called clientaccesspolicy.xml in the root directory of that domain.
So, in order to get your Silverlight make a successful call to a WCF service without getting HTTP 404 back, you should put the clientaccesspolicy.xml in c:\inetpub\wwwroot\.
The file should look like:
<?xml version="1.0" encoding="utf-8"?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="*">
<domain uri="*"/>
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
Of course, you should customize it according to your settings.
This is all it takes to get rid of Silverlight application WCF calls that returns HTTP 404…
Enjoy!