1

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

2 回答 2

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 客户端无论如何都可以访问您的服务,因此我不会浪费时间进一步配置它,只需使用通用客户端即可。

于 2012-03-07T15:06:45.457 回答
1

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

我将该文件添加到我在 VS 中的 WCF 项目中存储文件的同一文件夹中.SVC

于 2012-09-05T04:19:05.580 回答