Friday, January 27, 2012

Silverlight, WCF, and the clientaccesspolicy...

This is just a quick post because I found it painfully difficult to find the answer to this, without jumping through hoops.

I have 2 solutions in seperate visual studio instances.  One solution is the WCF service that is running.  The other solution is my Silverlight application, which is also running.  When attempting to make a service call, I get a wonderful error about security policies and cross domain issues.  There is a simple fix.

1) Create a notepad file on your desktop.
2) Place this into that file:
<?xml version="1.0" encoding="utf-8"?>
      <allow-from http-request-headers="*">
        <domain uri="*"/>
        <resource path="/" include-subpaths="true"/>

3) Save the file with this filename:  "clientaccesspolicy.xml" (minus the quotes)
4) Copy the file to your project folder that is running the service.  So for example, in my wcf solution, i Have a project called IISHost that is my startup project to run my services on the dev server while I am developing.  Simply drop the "clientaccesspolicy.xml" into that folder (that folder will contain the web.config for that project also).
5) Run your service project again and you should be good to go...
6) Now to figure out how to do "cross domain" step in debugging from the client project...

No comments:

Post a Comment