Can't download xml from sharepoint with silverlight.
EDIT: Switched to Silverlight 4 and that got me a little further.
I have an xml that stores high scores in a sharepoint library. The sharepoint site is https and I can hit the "copy shortcut" of the xml an开发者_JAVA百科d it appears in a browser so I know I can get to it.
I am trying to pull this xml in using a webclient in silverlight as follows.
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);
}
}
With this code my silverlight game pops up but a windows credentials login in window comes up immediatley. When I enter my correct crdentials in here, as i did in the code behind I get the followig error.
e.Error {System.Security.SecurityException ---> System.Security.SecurityException: Security error. 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(Object sendState) --- End of inner exception stack trace --- at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state) at System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result) at System.Net.WebClient.DownloadBitsResponseCallback(IAsyncResult result)} System.Exception {System.Security.SecurityException}
Any help?
Credentials were not implemented for the WebClient until Silverlight 4. Are you using an earlier version perhaps?
Silverlight 4 – Credentials, we’ve got it! Mark Monster December 2nd, 2009
Edit: Since you are now getting security exceptions, there may be a problem with a cross domain access policy file. Here are couple of links that describe the two types of client access policy files that Silverlight/WebClient will look for.
URL Access Restrictions in Silverlight
Network Security Access Restrictions in Silverlight
If you have control of https://server/HighScores.xml you shouldn't have much trouble implementing a client access policy file.
精彩评论