2
Vote

Specified method is not supported.

description

I am trying to consume an RSS 2.0 feed from a Silverlight Application but receive the error message "Specified method is not supported."

The stack trace is:
at System.Net.Browser.BrowserHttpWebRequest.BeginGetResponse(AsyncCallback callback, Object state)
at QDFeedParser.HttpFeedFactory.BeginDownloadXml(Uri feeduri, AsyncCallback callback)
at QDFeedParser.BaseFeedFactory.CreateFeed(Uri feeduri)
at AOIC.News.AddMarketNews()

The code I am using to do this is:

private void AddMarketNews()
    {
        try
        {
            Uri uri = new Uri("http://feeds.fin24.com/articles/Fin24/Markets/rss");
            IFeedFactory factory = new HttpFeedFactory();

            IFeed feed = factory.CreateFeed(uri);

            foreach (IFeedItem item in feed.Items)
            {
                TextBlock NewsItemTextBlock = new TextBlock();
                NewsItemTextBlock.Text = item.Title;

                MarketNewsStackPanel.Children.Add(NewsItemTextBlock);
            }
        }
        catch (Exception ex)
        { }
    }
Please tell me if I am doing something wrong.

comments

OskarsPodans wrote Jun 28, 2012 at 1:48 AM

In Silverlight you should use asynchronous methods of IFeedFactory like this:
private void AddMarketNews()
{
    Uri uri = new Uri("http://feeds.fin24.com/articles/Fin24/Markets/rss");
    IFeedFactory factory = new HttpFeedFactory();

    factory.BeginCreateFeed(uri, new AsyncCallback((result) =>
    {
        IFeed feed = factory.EndCreateFeed(result);
        Dispatcher.BeginInvoke(new Action<IFeed>(PopulateResults), feed);
    }));

}

void PopulateResults(IFeed feed)
{
    foreach (IFeedItem item in feed.Items)
    {
        TextBlock NewsItemTextBlock = new TextBlock();
        NewsItemTextBlock.Text = item.Title;

        MarketNewsStackPanel.Children.Add(NewsItemTextBlock);
    }
}
Most likely you will now get SecurityException.
Basically you can not make cross-domain HTTP requests from Silverlight.
Detailed information here:
http://msdn.microsoft.com/en-us/library/cc838250(v=vs.95)#crossdomain_communication

OskarsPodans wrote Jun 28, 2012 at 2:12 AM

How to fix qdfeed:

1) Remove or block synchronous methods from Silverlight version

or

2) FIX
// BaseFeedFactory.CreateFeed

if SILVERLIGHT || WINDOWS_PHONE

        var feedXmlResult = this.BeginDownloadXml(feeduri, null);
// HttpFeedFactory.BeginDownloadXml
            return request.BeginGetResponse(callback, requestState);
// callback parameter cannot be null, this causes "Specified method is not supported" exception