1

I am using RestSharp in Silverlight 4 application and it doesn't seems to be working.. It always return me ERROR with System.Security.SecurityException.

    try
    {
        client.ExecuteAsync(request, (response) =>
        {
            if (response.ResponseStatus == ResponseStatus.Error)
            {
                Debug.WriteLine(response.ResponseStatus);
            }
            else if (response.ResponseStatus == ResponseStatus.Completed)
            {
               Debug.WriteLine(response.Content);
            }
        });
    }
    catch(System.Security.SecurityException e)
    {
        Debug.WriteLine("Exception : " + e.Message);
    }
Timm
  • 2,652
  • 2
  • 25
  • 34
thetnswe
  • 53
  • 4

2 Answers2

2

Silverlight needs a clientaccesspolicy.xml file in the root directory of all servers you want to communicate with.

If you just want to allow communication from any client, you may use the following example:

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

Since every other non-Silverlight client can access your service anyway, I wouldn't waste time on configurating this any further and just go with the generic one.

Timm
  • 2,652
  • 2
  • 25
  • 34
1

Had the same problem - adding the clientaccesspolicy.xml work.

I added the file to my WCF project in VS in the same folder where the .SVC files are stored.

j0k
  • 22,600
  • 28
  • 79
  • 90