Silverlight 2 Beta 2 and Services: ClientAccessPolicy file may need to be modified

In moving a Silverlight 2.0 app to use Beta2, I hit a wall when trying to access my WCF Service which was working perfectly fine in Beta1.

I was getting a 404 telling me that the service could not be found. While the exception itself told me nothing more than that a 404 had been returned (with no inner exception), thankfully the exception popup window had the critical info in the header: TargetInvocationException crossed a native/managed boundary. So I knew that the cross domain problem had returned with the new bits. It wasn't until I searched for "TargetInvocationException" and found this thread did I see exactly what was causing the problem and how to fix it.

It turns out that if you are using the ClientAccessPolicy.xml file in the service to overcome cross domain issues, the file needs to be modified from what was needed in Beta1. Here's the new version. What has changed is that I am now using the "http-request-headers" attribute in the allow-from element. I'm not sure why it worked without this in Beta1, but this works now, so I'm a happy camper.

<?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>

#1 John Hauppa on 6.24.2008 at 10:41 AM

Thanks for this post. It probably saved me several hours of debugging this morning.I have a bunch of WCF services and I am upgrading the Silverlight client from Beta 1 to Beta 2 and I had the same problem. I changed my policy file per your post and it fixed the problem.

#2 Reny Mathew on 7.02.2008 at 1:41 PM

Thanks A Lot for the post. It fixed my problem, which I was dealing with, for the past two days.