Click here to Skip to main content
15,907,001 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i'm using the syndicationclient for the retreival of the rss feeds.

the peoblem is after running the app the tasks are working fine
no exceptions
but the feed items are null.

the feed items are : QuestionRss and ArticleRss

the links are :
http://www.codeproject.com/webservices/QuestionRSS.aspx
http://www.codeproject.com/webservices/ArticleRSS.aspx

the code i used to retrive is
private ObservableCollection<feedData> _feeds = new ObservableCollection<feedData>();
        public ObservableCollection<feedData> feeds
        {
            get { return _feeds; }
        }

        public async Task GetFeedsAsync()
        {
            Task<feedData> newArticles = GetFeedAsync("http://www.codeproject.com/WebServices/ArticleRSS.aspx");

            feeds.Add( await newArticles);

            Task<feedData> newQuestions = GetFeedAsync("http://www.codeproject.com/webservices/QuestionRSS.aspx");

            feeds.Add(await newQuestions);
        }

        private async Task<feedData> GetFeedAsync(string uri)
        {
            SyndicationClient client = new SyndicationClient();
            Uri feedUri = new Uri(uri);
            try
            {
                SyndicationFeed feed = await client.RetrieveFeedAsync(feedUri);
                feedData FeedData = new feedData();
                if(feed.Title!= null && feed.Title.Text!= null)
                {
                    FeedData.title = feed.Title.Text;
                }
                if(feed.Subtitle!= null && feed.Subtitle.Text!=null)
                {
                    FeedData.description = feed.Subtitle.Text;
                }
                if (feed.Items!= null && feed.Items.Count>0)
                {
                    //use the lastest date as the last updated date.
                    FeedData.pubTime = feed.Items[0].PublishedDate.DateTime;
                    foreach (SyndicationItem item in feed.Items)
                    {
                        feedItem FeedItem = new feedItem();
                        if(item.Title!= null && item.Title.Text!= null)
                        {
                            FeedItem.title = item.Title.Text;
                        }
                        if(item.PublishedDate!= null)
                        {
                            FeedItem.postTime = item.PublishedDate.DateTime;
                        }
                        if (item.Authors != null && item.Authors.Count > 0)
                        {
                            FeedItem.author = item.Authors[0].Name.ToString();
                        }
                        if (item.Content != null && item.Content.Text != null)
                        {
                            FeedItem.content = item.Content.Text;
                        }

                        if (feed.SourceFormat == SyndicationFormat.Atom10)
                        {
                            if (item.Content!=null && item.Content.Text!= null)
                            {
                                FeedItem.content = item.Content.Text;
                            }
                            if(item.Id!= null)
                            {
                                FeedItem.link = new Uri("http://www.codeproject.com/WebServices/ArticleRSS.aspx");
                            }
                        }
                        else if (feed.SourceFormat==SyndicationFormat.Rss20)
                        {
                            if(item.Summary!= null && item.Summary.Text!= null)
                            { FeedItem.content = item.Summary.Text; }
                            if(item.Links!= null && item.Links.Count>0)
                            {
                                FeedItem.link = item.Links[0].Uri;
                            }
                        }
                    }
                }
                return FeedData;
            }
            catch (Exception ex)
            {

                throw new NotImplementedException(ex.HResult.ToString());
            }
        }


the data models i've used are

//holds info for a single blog feed including , including a list of blog posts(fees item).
    public class feedData
    {
        public string  title { get; set; }
        public string description { get; set; }
        public DateTime pubTime { get; set; }
        private List<feedItem> _feedItems = new List<feedItem>();
        public List<feedItem> feedItems { get { return _feedItems; } }

    }

    //holds each blog post's content
    public class feedItem
    {
        public string title { get; set; }
        public string author { get; set; }
        public string content { get; set; }
        public DateTime postTime { get; set; }
        public Uri link{ get; set; }
    }
Posted
Updated 4-Mar-15 3:31am
v2
Comments
Richard Deeming 4-Mar-15 9:21am    
Is there supposed to be a question in there somewhere?
Akash Gutha 4-Mar-15 9:26am    
i'm having trouble finding the edit option .... pls help
Akash Gutha 4-Mar-15 9:36am    
never mind i figured it out

1 solution

It looks like this is a Windows Store application; I had to make several changes to get your code to work in the desktop version of the .NET Framework.

The reason you're not getting any items in your feed is because you're never adding the feedItem object to the feedItems collection on your feedData class:
C#
foreach (SyndicationItem item in feed.Items)
{
    feedItem FeedItem = new feedItem();
    ...
    
    // Add this line:
    FeedData.feedItems.Add(FeedItem);
}


NB: Your class and variable names don't follow the standard naming conventions. Classes, methods and properties should be named using sentence case (FeedData, FeedItem, FeedItems, etc.); fields and local variables should be named using camel case (feedItem, feedData, etc.). By ignoring these conventions, you're making your code harder to read.
 
Share this answer
 
v2
Comments
Akash Gutha 4-Mar-15 11:26am    
thanks for the tip
i will keep it in mind

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900