In it’s very basic form I have a WebClient request for some xml in a Page.xaml code behind. Something like:
public Page()
{
InitializeComponent();
Uri uri = new Uri("Dummy.xml", UriKind.Relative);
WebClient webClient = new WebClient();
webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted);
webClient.DownloadStringAsync(uri);
}
void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
//Do something
}
}
If I setup my Silverlight project to run through an asp.net hosted page, and then put Dummy.xml in the ClientBin folder (relative to the xap) it works fine.
If I setup the project using just the automatically generated test page option, and again put the xml relative to the xap, the request doesn’t work (although the completed event does fire).
My question is why? Is it a requirement that any Silverlight project that dynamically downloads has to be on a server?
Cheers
J
First up, try to avoid using the auto generated test page. It requires you to understand how the silverlight security by default model works when the xap is being accessed as a file.
To answer your question, you’re encountering the security designed to prevent unauthorised cross-domain access.