Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Problem with WebClient
12 replies. Latest Post by scottgurvey on May 25, 2008.
(0)
jwilson11
Member
4 points
3 Posts
03-07-2008 9:29 PM |
Ok so I am having a problem with WebClient (also having a similar problem, I think, with HttpWebRequest).
I'll just paste the relevant parts of my code:
This is the code I use to start the download (which in this case is an xml file on a remote server). I should mention that I am not getting a security exception that seems to occur when the server isn't setup for cross domain calls.
This call eventually is completed but I get a 'download failure' error.
System.Reflection.TargetInvocationException: [Async_ExceptionOccured]
Arguments:
Debugging resource string unavailable......Async_ExceptionOccured ---> System.Exception: Download Failure
--- End of inner exception stack trace ---
at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()
at System.Net.DownloadStringCompletedEventArgs.get_Result()
at testClient.Search._client_DownloadGroupListingCompleted(Object sender, DownloadStringCompletedEventArgs e)
Anyone have any thoughts on this?
I have disabled the Windows Firewall, and I recreated the functionality using HttpWebRequest but I get a null response (I believe the StatusCode and StatusDescription are NotFound and Not Found respectively). I am also running Vista x64.\
Any help would be greatly appreciated.
Josh
chad.cam...
Participant
1918 points
332 Posts
03-07-2008 10:45 PM |
Hi Josh,
By default, the WebClient can only request data within the same file scheme (i.e. http://, https://) and the same domain. The only way you can use the WebClient to do a cross domain request is if the other domain allows you to access it. The other domain can do this by setting up a policy file.
It looks like the URL you are trying to reference is a RSS feed. Have you tried reading this feed by using the System.ServiceModel.Syndication namespace?
03-07-2008 11:04 PM |
Hi Chad,
Yes I had read that in another posting but originally I was using the URL that Scott Guthrie had used in his example on his blog and the error hasn't changed (and his example seemed to be working). And I am not actually going to consume that rss file, utlimately it is just an xml file that I deal with later, but again I am getting that same error.
Its totally possible that the Digg url has been changed or disabled I haven't signed up for one myself. Any error that I have seen with the cross domain error has involved a security exception of some kind (the name of it escapes me at the moment).
Let me know if I am way off based here. Thanks for the help.
03-08-2008 1:04 AM |
I figured I'd give an update, I decided to point WebClient back to my site to load an xml file that way (new URI("../file.xml", UriKind.Relative)) and I am still getting that erro above (System.Reflection.TargetInvocationException).
If anyone has any theories or anything that would be great.
03-08-2008 9:13 AM |
Josh,
Where is the .xml file located? Is it in your Silverlight project or your Web Application project?
factor
8 points
5 Posts
03-09-2008 10:49 PM |
chad.campbell:By default, the WebClient can only request data within the same file scheme (i.e. http://, https://) and the same domain. The only way you can use the WebClient to do a cross domain request is if the other domain allows you to access it. The other domain can do this by setting up a policy file.
Is it possible to make an arbitrary cross domain request to a domain without a policy file? Not necessarily with WebClient, but in general, how would you do that?
Yi-Lun L...
All-Star
25052 points
2,747 Posts
03-10-2008 4:48 AM |
Unfortunately currently Silverlight doesn't support relative net URL. You have to use something like this to get the absolute URL:
url = url.Substring(0, index) +
kanwar
16 points
19 Posts
04-02-2008 3:45 AM |
Thanks Yi-Lun-Luo . I don't know wilson's problem is solved or not. But my problem is solved by your post.
Thanks.
scottgurvey
6 points
05-23-2008 12:40 PM |
Hi Chad Campbell et al...
I am also trying to reference an RSS feed from Silverlight, and will try your suggestion. But could you help me understand this situation? I don't see why Silverlight, or Flash for that matter, would require that their client programs have the server's permission to retrieve data the server routinly serves up to other clients on request, like an RSS feed to web page.
Thanks,
Scott
Jim Mangaly
Contributor
2622 points
381 Posts
05-23-2008 2:45 PM |
scottgurvey:I don't see why Silverlight, or Flash for that matter, would require that their client programs have the server's permission
This is to avoid cross-site forgery: http://en.wikipedia.org/wiki/Cross-site_request_forgery
Hope this helps,Jim (http://jimmangaly.blogspot.com/)
Please MARK the replies as answers if they answered your question
05-24-2008 10:27 AM |
Jim Mangaly: scottgurvey:I don't see why Silverlight, or Flash for that matter, would require that their client programs have the server's permission This is to avoid cross-site forgery: http://en.wikipedia.org/wiki/Cross-site_request_forgery Hope this helps,Jim (http://jimmangaly.blogspot.com/) Please MARK the replies as answers if they answered your question
Thanks for the reference. I am trying to understand it! And figure out how I'm going to create a Silverlight application which displays rss feeds from sites outside my hosting demain.
Regards,
05-24-2008 1:05 PM |
scottgurvey:Thanks for the reference. I am trying to understand it! And figure out how I'm going to create a Silverlight application which displays rss feeds from sites outside my hosting demain. Regards, Scott
I came across this exact same problem. It's pretty stupid that the example projects hosted on this site don't work when you compile them yourself due to this issue. Anyway, I solved the issue in this thread: http://silverlight.net/forums/p/11286/36037.aspx#36037
05-25-2008 10:53 AM |
Thanks, this is very helpful.
I think they have some conflict in terms of what they are defining as security needs and the utility to fetch data cross domain desired for many applications. Hopefully, they'll figure out a policy on this and issue some best practices when Silverlight 2 is released.