.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> ASP.NET >> Post New Resource Bookmark and Share   

 Subscribe to Articles

RSS Feed Reader in Silverlight

Posted By:Dexterity Solutions       Posted Date: June 26, 2010    Points: 25    Category: ASP.NET    URL: http://www.dotnetspark.com  

Feed Reader in RSS
 

What is RSS?
 RSS (acronymic for Really Simple Syndication) is "a group of XML based web-content distribution and republication (Web syndication) formats primarily used by news sites and weblogs (blogs)." Essentially, an RSS feed is a hosted XML file from which your RSS newsreader pulls headlines, URLs, and other content as it is updated.

In Simple words you are trying to access a page from different domain from your's...Most of the time you'll see this exception when your Silverlight application is accessing a service not hosted on the same application domain.  This is considered cross-domain access and requires the service host to enable an opt-in policy file so rich client platforms are allowed to access the service.  In Silverlight we call that the clientaccesspolicy.xml file.

clientaccesspolicy.xml


 
   
     
        
     
     
       
     

   

 

So generally the sites like sun.com,oracle.com,cisco.com dont give permissions for crossdomain calls,they only allow you to subscribe for feeds.

So I have found two solutions.

1)Use a proxy.which grants you permission and has a clientaccesspolicy.xml file

2)Yahoo Pipes

Here we will be discussing this by using a proxy..

so lets start..

public partial class MainPage : UserControl
 {
  private Uri RSSUrl;
  private XmlReader reader; 
  public MainPage()
  {
   // Required to initialize variables
   InitializeComponent();
   
  RSSUrl = new Uri("http://al.cloudapp.net/proxy.ashx?http://www.sun.com/rss/news-rss.xml");

  LoadXMLFile();
       }
  private void LoadXMLFile()
   {
    WebClient xmlClient = new WebClient();
    xmlClient.DownloadStringCompleted +=new System.Net.DownloadStringCompletedEventHandler(xmlClient_DownloadStringCompleted);
    xmlClient.DownloadStringAsync(RSSUrl);
   }

   private void xmlClient_DownloadStringCompleted(object sender, System.Net.DownloadStringCompletedEventArgs e)
  {  
      string xmlString  = e.Result;
      XDocument xd = XDocument.Parse(xmlString);
      var v = from g in xd.Descendants("item")
        select new Feeds
        {
         Title = g.Element("title").Value,
         Link =g.Element("link").Value,  
        };       
     }  
  } 

WebClient Class->Provides common methods for sending data to and receiving data from a resource identified by a URI.I have used  Linq(Language Integrated Query)to read the xml file.

I have not put try catch block ,i leave that  upto you guys.and one more thing now you can bind the result "v" to the Listbox of silverlight to see the result.

For more information, you can contact me at : http://www.dexterity.co.in


 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply

    Read also another Resources from the same Author

Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend