Monday, August 30, 2010

Web service cross domain policy

Hm.. Now I hosted my web services for my Silverlight application and everything working fine there in Client server. Meanwhile I just tried to connect the hosted webservice from my development environment(From visual studio project). Nothing unusual, cool.. it throws the error once again to test my patience. It goes like... " This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place "

This time workaround is not in the code its there in the Web service hosted server. In order to enable cross domain policy you have to add a "crossdomain.xml" file in the root of the application host. That is, either in your "wwwroot" or the folder where the root URL points (like if your application hosted in "http://myapplications.com/Webservice1", the cross domain policy xml file you have to locate is "http://myapplications.com/crossdomain.xml". Not inside of any the sub application folders ). Here is the plain simple crossdomain.xml content.

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-http-request-headers-from domain="*" headers="SOAPAction,Content-Type"/>
</cross-domain-policy>

This MSDN reference makes it authenticated :)

Thats it!. Simple cool. So enjoy coding :)

No comments: