Skip to main content
Home Forums Silverlight Programming Report a Silverlight Bug WebClient/HttpRequest not working under a .XAP running from a non-relative URL
2 replies. Latest Post by ahopper on July 3, 2008.
(0)
ahopper
Member
2 points
6 Posts
07-01-2008 11:52 PM |
This may very well be related to a bug I posted earlier (http://silverlight.net/forums/p/19109/65118.aspx).
When running a Silverlight B2 app from a URL other than a relative URL, the WebClient and HttpRequest objects don't raise any events (although oddly enough, I see the requests going out when running Fiddler...), which prevents you from doing things like background-loading of image/media resources. It may very well affect requests to Web Services, etc although I haven't tried that yet.
Here's the steps to repro:1. Create a new Silverlight B2 application ("MyApp") and select the option to use a Web to test it.2. Add a zip file named Resource.zip to the root of your Web site3. Add a TextBlock to the Grid in Page.xaml and name it "downloadStatus"4. In the constructor of the Page class, add the following code after the call to InitializeComponent():
... WebClient webClient = new WebClient(); webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(this.DownloadProgress); webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(this.DownloadCompleted); webClient.OpenReadAsync(new Uri("../Resource.zip", UriKind.Relative)); // <- Could be anything, really... this.downloadStatus.Text = "Started download...";...
5. Add two methods: DownloadProgress, and DownloadCompleted
private void ImageDownloadProgress(Object sender, DownloadProgressChangedEventArgs e) { this.downloadStatus.Text = e.ProgressPercentage.ToString(); }
private void DownloadCompleted(Object sender, OpenReadCompletedEventArgs e) { this.downloadStatus.Text = "Completed download."; }
6. Run the application using the standard test page and verify that the TextBlock cycles through the various states.7. Copy the .XAP to a web server other than the Web in your project (IIS comes in handy here - you can simply place it in wwwroot for the purpose of this repro).8. Change the Source attribute of the Silverlight control in the test .aspx page to point to the new location (eg: http://localhost/SomeFolder/MyApp.xap)9. Run the project again. Note that the TextBlock never changes from the "Started" message and no exceptions are thrown. You may also see in Fiddler that the request actually goes out and is served with a 200 result.
Yi-Lun L...
All-Star
25052 points
2,747 Posts
07-03-2008 1:05 AM |
Hello, thanks for reporting this issue. I've verified the problem is: An InvalidOperationExeption is thrown with the message: "Scriptable access is disabled." I think it is due to a cross domain script access problem, which can't be solved by a cross domain policy file. But actually we already support this scenario in Beta 2. You need to modify the xap's manifest. Rename the xap file to a zip file and extract the AppMenifest.xaml. Modify the root tag: Deployment, and add a property as shown below:
<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" EntryPointAssembly="AbsoluteXap" ExternalCallersFromCrossDomain="FullAccess" EntryPointType="AbsoluteXap.App" RuntimeVersion="2.0.30523.6">...</Deployment>
Then reconstruct the xap file, and test it again with your scenario, and it should work fine.
07-03-2008 3:29 PM |
That does indeed seem to resolve the issue, although I'm puzzled as to why it's considered to be cross-domain; the zip file is being served from the same site as the .XAP.
Thanks for your help!