Skip to main content

Microsoft Silverlight

Answered Question Problem with WebClientRSS Feed

(0)

jwilson11
jwilson11

Member

Member

4 points

3 Posts

Problem with WebClient

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.

 

string URL = "http://silverlight.net/blogs/microsoft/rss.aspx";

this._client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(_client_DownloadGroupListingCompleted);

this._client.DownloadStringAsync(new Uri(URL));

 

 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.campbell
chad.cam...

Participant

Participant

1918 points

332 Posts

Silverlight MVP

Re: Problem with WebClient

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?

If this answers your question, please select "mark as answer", otherwise, please post a follow up question. Thanks!
Chad Campbell

Author of Silverlight 2.0 in Action Blog: http://cornucopia30.blogspot.com

jwilson11
jwilson11

Member

Member

4 points

3 Posts

Re: Problem with WebClient

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.

Josh

jwilson11
jwilson11

Member

Member

4 points

3 Posts

Re: Problem with WebClient

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.

Josh

chad.campbell
chad.cam...

Participant

Participant

1918 points

332 Posts

Silverlight MVP

Re: Problem with WebClient

Josh,

Where is the .xml file located?  Is it in your Silverlight project or your Web Application project?

If this answers your question, please select "mark as answer", otherwise, please post a follow up question. Thanks!
Chad Campbell

Author of Silverlight 2.0 in Action Blog: http://cornucopia30.blogspot.com

factor
factor

Member

Member

8 points

5 Posts

Re: Problem with WebClient

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 Luo - MSFT
Yi-Lun L...

All-Star

All-Star

25052 points

2,747 Posts

Answered Question

Re: Problem with WebClient

Unfortunately currently Silverlight doesn't support relative net URL. You have to use something like this to get the absolute URL:

string url = App.Current.Host.Source.AbsoluteUri;

int index = url.IndexOf("/ClientBin");

url = url.Substring(0, index) + "/file.xml";

shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.

kanwar
kanwar

Member

Member

16 points

19 Posts

Re: Problem with WebClient

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
scottgurvey

Member

Member

6 points

3 Posts

Webclient and cross domain access reasoning

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
Jim Mangaly

Contributor

Contributor

2622 points

381 Posts

Re: Webclient and cross domain access reasoning

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

http://www.identitymine.com/

scottgurvey
scottgurvey

Member

Member

6 points

3 Posts

Re: Webclient and cross domain access reasoning

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,

Scott

factor
factor

Member

Member

8 points

5 Posts

Re: Webclient and cross domain access reasoning

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

scottgurvey
scottgurvey

Member

Member

6 points

3 Posts

Re: Re: Webclient and cross domain access reasoning

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.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities