我正在尝试让 Silverlight 使用快速示例应用程序,并在另一台计算机上调用休息服务。拥有其余服务的服务器有一个 clientaccesspolicy.xml,如下所示:
<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>
并且正在被拾取(至少根据我运行的网络跟踪),并且没有对 crossdomain.xml 的请求。C# 代码如下所示:
public Page()
{
InitializeComponent();
string restUrl = "http://example.com/rest_service.html?action=test_result";
WebClient testService = new WebClient();
testService.DownloadStringCompleted += new DownloadStringCompletedEventHandler(testService_DownloadStringCompleted);
testService.DownloadStringAsync(new Uri(restUrl, UriKind.Absolute));
}
void testService_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
LoadTreeViewWithData(e.Result);
}
}
但是,我总是收到以下安全错误:
{System.Security.SecurityException ---> System.Security.SecurityException:安全错误。 在 System.Net.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) 在 System.Net.BrowserHttpWebRequest.c__DisplayClass5.b__4(对象 sendState) 在 System.Net.AsyncHelper.c__DisplayClass2.b__0(对象 sendState) --- 内部异常堆栈跟踪结束 --- 在 System.Net.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod,对象状态) 在 System.Net.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult) 在 System.Net.WebClient.GetWebResponse(WebRequest 请求,IAsyncResult 结果) 在 System.Net.WebClient.DownloadBitsResponseCallback(IAsyncResult 结果)}
我究竟做错了什么?为什么安全错误没有告诉我一些更有用的信息?