Kri*_*son 13 c# rest silverlight
我试图让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>
Run Code Online (Sandbox Code Playgroud)
并且正在被选中(至少根据我运行的网络跟踪),并且没有对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);
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我总是得到以下安全错误:
{System.Security.SecurityException ---> System.Security.SecurityException: Security error.
at System.Net.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
at System.Net.BrowserHttpWebRequest.c__DisplayClass5.b__4(Object sendState)
at System.Net.AsyncHelper.c__DisplayClass2.b__0(Object sendState)
--- End of inner exception stack trace ---
at System.Net.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
at System.Net.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result)
at System.Net.WebClient.DownloadBitsResponseCallback(IAsyncResult result)}
我究竟做错了什么?为什么安全性错误没有告诉我一些更有用的信息?
如果您还没有这样做,我首先尝试将restUrl更改为更简单的东西,如同一台服务器上的静态HTML页面(或者如果需要在您自己的服务器上),只是为了验证您的主代码是否正常工作.
假设安全性异常特定于该REST URL(或站点),您可以查看Silverlight 2文章中的URL访问限制.除了更为人熟知的跨域规则之外,还有一些涉及文件类型和"互联网区域"的非显而易见的安全规则.
我对Silverlight中许多异常消息的抱怨不是很有帮助.上面引用的MSDN文章包含一个有趣的注释:
当用户因违反其中一个访问策略而导致错误时,错误可能无法指明确切原因.
| 归档时间: |
|
| 查看次数: |
12438 次 |
| 最近记录: |