編輯:切換到Silverlight 4,這讓我更進一步。無法使用silverlight從sharepoint下載xml。
我有一個XML在分享點庫中存儲高分。該Sharepoint站點是https,我可以打到xml的「複製快捷方式」,它出現在瀏覽器中,所以我知道我可以做到。
我想拉如下在Silverlight中使用webclient這個xml。
Uri url = new Uri("https://server/HighScores.xml", UriKind.Absolute);
WebRequest.RegisterPrefix("https://",System.Net.Browser.WebRequestCreator.ClientHttp);
var client = new WebClient();
client.Credentials = new NetworkCredential("username", "password", "domain");
client.UseDefaultCredentials = false;
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
client.DownloadStringAsync(url);
void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
string xmlData = e.Result;
HtmlPage.Window.Alert(xmlData);
}
}
有了這段代碼,我的silverlight遊戲彈出,但窗口中的Windows憑據登錄出現immediatley。當我在這裏輸入正確的crdentials時,正如我在後面的代碼中所做的那樣,我得到了followig錯誤。
e.Error {System.Security.SecurityException ---> System.Security.SecurityException:安全性錯誤。 at System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) at System.Net.Browser.ClientHttpWebRequest。 <> c_ DisplayClass5.b _4(Object sendState) at System.Net.Browser.AsyncHelper。 <> C_ DisplayClass2.b _0(對象sendState)內部異常堆棧跟蹤的 --- ---結束在 System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod,對象狀態) 在System.Net。 Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult的asyncResult) 在System.Net.WebClient.GetWebResponse(WebRequest的請求,IAsyncResult的結果) 在System.Net.WebClient.DownloadBitsResponseCallback(IAsyncResult的結果)} {的System.Exception} System.Security.SecurityException
任何幫助?
您使用的是什麼版本的Silverlight? – DaveB 2011-01-12 01:10:45
現在我正在使用Silverlight 4,我將其切換。現在獲取安全異常而不是以前的異常。 – theDawckta 2011-01-12 02:33:20