developers.de
daenet's .NET Community

Silverlight 4: InvalidOperationException (SecurityException) WCF DataServices

Damir Dobric Posts

 

Damir@Phone    



My upcoming sessions:

AppFabric Applications at
NRW Conf 2011
09.Sept.2011 Wuppertal

HTML5 widgets in WP7+
Monodroid
Mobility Day
21.Sept.2011 - Zagreb

AppFabric and WCF sessions at
Advanced Developer Conference
26.-27. Oktober 2011 in Frankenthal

AppFabric Applications, queues, topics and more at
Prio Conference
02. - 03. November 2011 in Meistersingerhalle Nürnberg

AppFabric Applications deep dive hosted by
.NET User Group Frankfurt
17.Nov.2011 18.30-22.30 Microsoft - Bad Homburg 

 

 

When migrating Silverlight 3 Project to Silverlight 4 you might experience following exception:

InvalidOperationException (InnerException: SecurityException)

image

This error occurs when the SIlverlight application has been downloaded from one site like

http://host1/app/default.aspx

and WCF DataService invokes operation from service which is hosted on another site like:

http://host2/app/service.svc/

To make this working you need to deploy clientaccesspolicy.xml file.

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

This policy file works in Silverlight 3. However Silverlight 4 is more clever and obviously can differentiate between real SOAPAction header, which is not sent in a case of DataService. DataServices uses REST pattern and not SOAP.

Here is the required change in the policy file:

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

Posted Apr 22 2010, 02:57 PM by Damir Dobric
Filed under: ,

Comments

Worked GREAT!!! wrote re: Silverlight 4: InvalidOperationException (SecurityException) WCF DataServices
on 02-03-2011 9:58

After near a month of strugglin with that error, I found that I missed this xml file...

Thanks A LOT!

Kirikamal wrote re: Silverlight 4: InvalidOperationException (SecurityException) WCF DataServices
on 11-10-2011 7:52

Hi,

I'm looking for this.. now my app working nicely...

Thank you.

- Kirikamal

Add a Comment

(required)  
(optional)
(required)  
Remember Me?
daenet GmbH