Requesting a Feed
Both WebClient
and HttpWebRequest
can make asynchronous calls to
web services, including requests
for syndication feeds. WebClient
is
the simpler of the two class libraries as it uses HttpWebRequest
under the covers. Using one of
these classes to make a web request for a syndicated feed, you can
retrieve the data as a string or as a stream, depending on what you desire. The examples
in this chapter demonstrate techniques with both classes and both return
formats.
The first step in requesting a feed is to find the feed’s URI. Many websites publish their syndication feed address in a conspicuous spot on their web page. The format of the feed may be either RSS or Atom. Because both of these protocols are commonly used, any code that requests a feed should be prepared to work with either RSS or Atom. For the following examples, the http://feeds.feedburner.com/johnpapa feed will be requested.
Note
The code solution for the following example is named SyndicationReader
and you can find it in the
code folder for this chapter.
The example application (shown in Figure 10-2) will request a feed from an
address that the user enters. When the feed is returned, it is loaded
into a SyndicationFeed
object and is
bound to the control, where it displays information about the feed and
its individual items.
The SyndicationReader
application allows the user to choose between using WebClient
and HttpWebRequest
. Although a real-world application targeted at nondevelopers would likely not ...
Get Data-Driven Services with Silverlight 2 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.