Follow me on Twitter Receive/Transmit

Silverlight Cross Domain Requests

Mar.14, 2010, under Random

I’ve been playing with a little Silverlight app which requests data from an XML webservice on a remote server. Ths is the first time I’ve done this and like most people I fell into the trap of not setting up my crossdomainrequest.xml file. This is a file you need to put on the remote server in the root directory, and it basically permits Silverlight to access the data on the server. If you haven’t set this up correctly you will be seeing a lot of the dreaded System.Security.SecurityException

There is a lot of info out on Google about this which has sample xml files, however none of them were working for me and I spent quite a bit of time scratching my head. I eventually came across this document which gave me a clue as to what I was doing wrong – basically my silverlight app was running on http but the site I was pulling data from was https. In order for this to work you need an extra line in the xml to permit ‘cross-scheme’ access, ie an http site accessing an https one. The xml which got me up and running was this:

<?xml version="1.0" encoding="utf-8"?>
<access-policy>
 <cross-domain-access>
  <policy>
   <allow-from http-request-headers="*">
    <domain uri="*"/>
    <domain uri="http://*"/>
   </allow-from>
   <grant-to>
    <resource path="/" include-subpaths="true"/>
   </grant-to>
  </policy>
 </cross-domain-access>
</access-policy>

Save this as crossdomainrequest.xml at the root of your web server, but bear in mind that this allows full access and so you might want to edit it to lock it down (again, lots of other turorials on this). Its annoying that I had to spend a good couple of hours sorting this. Looking around its a very common issue and the error messages could be a lot more helpful in pointing you in the right direction

:, , ,

Leave a Reply