So here is the alternate solution, Access RSS Feed using WCF Service from a Silverlight application. For that we need have a WCF Service and a Silverlight Client.
WCF service will fetch the data from the feed URL and passed to the client.
Steps:
Create a new Silverlight Application using VS2008, Select “Add a new web to the solution for hosting the control’ Option.
Then Right click the Web project, select Add New Item and add WCF service.
Now WCF Service will be added to the Web.
Add a reference System.ServiceModel.Syndication to the service
Create a custom class for Feed data in to the service. Something like below :
//
/// Feeed Data List
///
[DataContract]
public class FeedData
{
public FeedData()
{
}
private string _LastUpdatedTime;
private string _PublishDate;
private string _Title;
private string _Summary;
[DataMember]
public string PublishDate
{
get { return _PublishDate; }
set { _PublishDate = value; }
}
[DataMember]
public string Summary
{
get { return _Summary; }
set { _Summary = value; }
}
[DataMember]
public string Title
{
get { return _Title; }
set { _Title = value; }
}
[DataMember]
public string LastUpdatedTime
{
get { return _LastUpdatedTime; }
set { _LastUpdatedTime = value; }
}
Add Service contact :
///
/// Summary description for IFeedAPI
///
[ServiceContract]
public interface IFeedAPI
{
[OperationContract]
List
}
Implement the interface
///
/// Fetched the RSS data from the current RSS Feed
///
///
public List
{
List
SyndicationFeed feed = null;
// Get the current feed and load into an XMLReader
using (XmlReader reader = XmlReader.Create(FeedURL))
{
Rss20FeedFormatter feedFormatter = new Rss20FeedFormatter();
// Read the contents of the XMLReader into the FeedFormatter
feedFormatter.ReadFrom(reader);
// Get the current feed.
feed = feedFormatter.Feed;
}
foreach (SyndicationItem dataItem in feed.Items)
{
//Adding Feed Items to FeedData List
feedData.Add(new FeedData { LastUpdatedTime = dataItem.LastUpdatedTime.ToString(), PublishDate = dataItem.PublishDate.ToString(), Summary = dataItem.Summary.Text, Title = dataItem.Title.Text });
}
return feedData;
}
Then in the silverlight application, add the service reference, create the proxy instance of the service, call the GetRSSDataAsync method by passing the Feed URL, in the completed of GetRSSDataCompleted, we will get a data list type FeedData.
No comments:
Post a Comment