我有一段時間從silverlight中調用RESTful服務。我遇到了這個錯誤:在Silverlight中使用Web客戶端
{System.Security.SecurityException ---> System.Security.SecurityException: Security error.
at System.Net.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
at System.Net.BrowserHttpWebRequest.<>c__DisplayClass5.<EndGetResponse>b__4(Object sendState)
at System.Net.AsyncHelper.<>c__DisplayClass2.<BeginOnUI>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.OpenReadAsyncCallback(IAsyncResult result)}
這似乎是使用webclient時的流行錯誤。我已經建立了一個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和它確實對網站提出請求,也不得到一個200個狀態回來了。
public void login(string userName, string password)
{
WebClient client = new WebClient();
Uri uri = new Uri(serverURI + "/clientaccesspolicy.xml");
client.OpenReadCompleted += new OpenReadCompletedEventHandler(login_Complete);
client.OpenReadAsync(uri);
}
private void login_Complete(object sender, OpenReadCompletedEventArgs e)
{
byte[] buffer = new byte[e.Result.Length]; //crashes here with exception
...
}
我或多或少地沒有想法。有人知道我做錯了什麼?是否有直接從文件運行silverlight的問題:// uri?
更新:我刪除了clientaccesspolicy.xml文件,只保留了crossdomain.xml文件,並且賓果遊戲一切正常。這讓我相信這個錯誤發生在clientaccesspolicy文件中,但是我直接從microsoft複製了這個錯誤。是什麼賦予了?
這似乎是合乎邏輯的,但並不能真正解釋爲什麼刪除clientaccesspolicy.xml文件修復了它。 – stimms 2009-04-20 02:37:19