silverlight error
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?
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).
精彩评论