Silverlight 4应用程序中的RestSharp不起作用

时间:2012-02-11 00:48:15

标签: silverlight restsharp clientaccesspolicy.xml

我在Silverlight 4应用程序中使用RestSharp,它似乎没有工作..它总是返回ERROR与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);
    }

2 个答案:

答案 0 :(得分:2)

Silverlight在您要与之通信的所有服务器的根目录中都需要一个clientaccesspolicy.xml文件。

如果您只想允许来自任何客户的通信,您可以使用以下示例:

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

由于所有其他非Silverlight客户端无论如何都可以访问您的服务,我不会浪费时间进一步配置它,只需使用通用的。

答案 1 :(得分:1)

有同样的问题 - 添加clientaccesspolicy.xml工作。

我将文件添加到VS中的WCF项目中,该文件位于存储.SVC文件的文件夹中。