views:

20

answers:

1
+1  Q: 

silverlight error

Hi,

I get this error from silverlight:

Operation named 'GetRssFeed' does not conform to the required signature. Return types must be an entity, collection of entities, or one of the predefined serializable types.

This is my domainservice class:

// TODO: Create methods containing your application logic.
    [EnableClientAccess()]
    public class RssService : DomainService
    {
        [Invoke]
        public XDocument GetRssFeed(string Url)
        //public string GetRssFeed(string Url)
        {
            XDocument RssFeed = XDocument.Load(Url);
            return RssFeed.Document;//.ToString();
        }
    }

And this is my mainpage.xaml.cs class:

public MainPage()
        {
            InitializeComponent();

            RssContext context = new RssContext();
            context.GetRssFeed("http://www.nu.nl/feeds/rss/algemeen.rss", GetRssFeedCompleted, null);
            //XDocument RssFeed = XDocument.Load("http://www.nu.nl/feeds/rss/algemeen.rss");

        }

        void GetRssFeedCompleted(InvokeOperation<XDocument> obj)
        {
            //FeedResult.Text = obj.Value;

        }

        private IEnumerable<Channel> getChannelQuery(XDocument xdoc)
        {
            //XDocument xd = (XDocument)xdoc;
            return from channels in xdoc.Descendants("channel")
                         select new Channel
                         {
                             Title = channels.Element("title") != null ? channels.Element("title").Value : "",
                             Link = channels.Element("link") != null ? channels.Element("link").Value : "",
                             Description = channels.Element("description") != null ? channels.Element("description").Value : "",
                             Items = from items in channels.Descendants("item")
                                             select new Item
                                             {
                                                 Title = items.Element("title") != null ? items.Element("title").Value : "",
                                                 Link = items.Element("link") != null ? items.Element("link").Value : "",
                                                 Description = items.Element("description") != null ? items.Element("description").Value : "",
                                                 Guid = (items.Element("guid") != null ? items.Element("guid").Value : "")
                                             }
                         };
            }
    }

If i change the return type XDocument in my domainservice class, i get that error. But making it a string is just fine. I googled up this error msg, there are some work arounds for custom return types. But this isnt custom. The XDocument object belongs to the .NET framework.

How can i fix this?

+1  A: 

Although an XDocument is in the .NET Framework, the XDocument is not serializable. To be used in a web service (or DomainService), it needs to be serializable. So, the error is valid. You'll need to use either a type that is serializable or return a string. In the example you provide above, returning a string as the RSS document is perfectly fine.

You might want to take a look at the .NET WCF Syndication Framework (makes creating/serving RSS/Atom feeds relatively simple).

WPCoder
I figured out how to parse the string to xdocument. That was the reason for me not to use the string in the first place. But got it working now, thanks!
Yustme