我在寫一個需要通過GET/POST請求與服務器接口的Silverlight應用程序。我的代碼如下所示:有WebClient GET請求的System.Security.SecurityException
Uri serviceUri = new Uri(my_URI);
WebClient client = new WebClient();
client.OpenReadCompleted += new OpenReadCompletedEventHandler(OnRequestComplete);
client.OpenReadAsync(serviceUri);
但是,當調用回調函數時,我得到一個System.Security.SecurityException。我在這裏從具有類似錯誤的人那裏閱讀了許多問題,但是他們的所有問題似乎源於調試時的跨域問題。當我運行我的代碼時,它以http://localhost:...
作爲域運行,所以不應該成爲我不認爲的問題。以下是完整的錯誤,如果有所幫助:
{System.Security.SecurityException: Security error.
at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClassa.<EndGetResponse>b__9(Object sendState)
at System.Net.Browser.AsyncHelper.<>c__DisplayClass4.<BeginOnUI>b__0(Object sendState)}
感謝您的任何幫助。這是一個非常令人沮喪的問題。
UPDATE:
我搞砸與它周圍的很多,並最終得到了一切工作。不是100%...雖然我最終將clientaccesspolicy.xml和crossdomain.xml文件複製/粘貼到任何可以想象的位置,但創建了一個新的Silverlight項目並複製了所有內容以及其他一些內容。如果有其他人遇到這個問題,那就像我必須給出的建議一樣多:/
可能的重複http://stackoverflow.com/questions/766574/using-web-client-in-silverlight – aquaraga 2013-04-24 05:49:49
他從file:// URI運行。就像我上面所說的,我從localhost – Duncan 2013-04-24 05:53:55