Cross-domain policy files, web services, and Silverlight

I was deploying a Silverlight site recently, and I’ve learned a lot about it, including how unprepared I was the first time to do it successfully. Live and learn.

One of the issue I ran across was accessing a web service from the Silverlight file. When I deployed my service to the remote system (they don’t work so well when trying to connect from the Internet to the localhost), I got this message:

“An error occurred while trying to make a request to URI ‘http://www.scottscoolsite.com/Service.svc’. This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place, or a policy that is unsuitable for SOAP services. You may need to contact the owner of the service to publish a cross-domain policy file and to ensure it allows SOAP-related HTTP headers to be sent. This error may also be caused by using internal types in the web service proxy without using the InternalsVisibleToAttribute attribute. Please see the inner exception for more details.”

Bang, bang, bang goes my forehead…

So I was off to find out what the heck they were talking about. I found at article on MSDN title Network Security Access Restrictions in Silverlight that seemed to be what I needed. I then typed in this XML code in the policy file, but it didn’t work.

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

Then I tried this policy file, and it worked. Can you spot the difference?

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

It’s this line:

 <domain uri="http://scottscoolsite.com" />

In the first policy file, it started with www. In the one that works, I excluded it. Tricky.

Advertisements
  1. ssl certificate

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: