<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" media="screen" href="/styles/xslt/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:c9="http://channel9.msdn.com">
<channel>
	<title>Channel 9</title>
    <atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/Niners/c4f.Peter-Bernhardt/Posts/RSS"></atom:link>
    <itunes:summary></itunes:summary>
    <itunes:author>Microsoft</itunes:author>
    <itunes:subtitle></itunes:subtitle>
    <image>
      <url>http://mschnlnine.vo.llnwd.net/d1/Dev/App_Themes/C9/images/feedimage.png</url>
      <title>Channel 9</title>
      <link>http://channel9.msdn.com/Niners/c4f.Peter-Bernhardt/Posts</link>
    </image>
    <itunes:image href=""></itunes:image>
    <itunes:category text="Technology"></itunes:category>
    <description>Channel 9 keeps you up to date with the latest news and behind the scenes info from Microsoft that developers love to keep up with. From LINQ to SilverLight – Watch videos and hear about all the cool technologies coming and the people behind them.</description>
    <link>http://channel9.msdn.com/Niners/c4f.Peter-Bernhardt/Posts</link>
    <language>en</language>
    <pubDate>Thu, 20 Jun 2013 06:58:12 GMT</pubDate>
    <lastBuildDate>Thu, 20 Jun 2013 06:58:12 GMT</lastBuildDate>
    <generator>Rev9</generator>
    <c9:totalResults>7</c9:totalResults>
    <c9:pageCount>1</c9:pageCount>
    <c9:pageSize>25</c9:pageSize>
  <item>
      <title>Building a Family History Web Service Client</title>
      <description><![CDATA[<span id="c4fmetadata">
<table border="0" cellpadding="1" cellspacing="0" width="100%">
<tbody>
<tr class="entry_overview">
<td width="50">&nbsp;</td>
<td><span class="entry_description">This article is basically about Family History Web service using Visual Web Developer 2005 Express Edition In this article a client application is shown which is built as a front end to the Web service.
</span></td>
</tr>
<tr>
<td colspan="2">
<div class="entry_author">Peter Bernhardt</div>
<div class="entry_company"><a href="http://www.3leafdev.com/Home.aspx">3Leaf Development</a></div>
<br>
<div class="entry_details"><b>Difficulty: </b><span class="entry_details_input">Easy</span></div>
<div class="entry_details"><b>Time Required:</b> <span class="entry_details_input">
1-3 hours</span></div>
<div class="entry_details"><b>Cost: </b><span class="entry_details_input">Free</span></div>
<div class="entry_details"><b>Software: </b><span class="entry_details_input"><a href="http://msdn.com/express/">Visual Basic or Visual C# Express Editions</a>,</span></div>
<div class="entry_details"><b>Hardware: </b><span class="entry_details_input"></span></div>
<div class="entry_details"><b>Download: </b><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1066660/Family_20History_20Part_202_20Code.msi">Download</a>
<ul>
</ul>
</div>
</td>
</tr>
</tbody>
</table>
</span>
<p>Last time, I walked through putting together a Family History Web service using Visual Web Developer 2005 Express Edition. To complete the circle, in this installment I'll show you a client application I built as a front end to the Web service. Before getting
 into the application itself, I want to report that since my last entry I've updated my development environment to use the latest beta release of the Microsoft Visual Studio Express Editions. If you haven't yet made the move yourself, I urge you do so at your
 earliest opportunity. Because the update introduces some breaking changes with earlier beta releases, this will likely inflict some pain if you've already built some applications. But for me, at least, the pain is far outweighed by the gain in bug fixes and
 features improvements, one of which I am pleased to highlight in this post. But I hold that for a bit later.</p>
<p><img src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1066660/image002.jpg" height="294" width="490"></p>
<p>The client application for my Family History Web service is a Windows Forms application. As you may recall, the Web service exposes two methods; a search method and an update method. This provides the bare bones functionality I need to start gathering information
 about my ancestors. I thus started by creating a new Windows Application in Microsoft Visual C# 2005 Express Edition. Next, I added a connection to the Family History Web service as a data source.</p>
<p><img src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1066660/image004.jpg" height="451" width="490"></p>
<p>All versions of Visual Studio provide an easy-to-use wizard for configuring a Web service as a data source for an application. I've described how to use the wizard in previous entries; you simply select the
<b>Data | Add New Data Source</b> menu item. This launches a wizard that lets you choose from a Database, Web service or custom object as a data source. After selecting
<b>Web Service </b>as my data source type, I clicked Next to open the <b>Add Web Reference
</b>dialog. </p>
<p>&nbsp;</p>
<p><img src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1066660/image006.jpg" height="400" width="490"></p>
<p>One of the great benefits of Visual Studio 2005 is that you don't need to run Internet Information Services (IIS) on your development machine to build and test Web-based applications. Along with all that goodness, however, in certain circumstances you may
 have a minor problem when you go to write a client for a Web service. If you are building the client in a separate solution, as I am in this case, and haven't deployed the Web service to a publicly available address, which I have not, you won't be able to
 browse to the Web service using the page provided in the <b>Add Web Reference </b>
dialog. To solve this, all I had to do was open the Family History Web service in Visual Web Developer 2005 Express Edition and run the application in debug mode. (And it's worth noting that I kept the Web service running while I built the client application
 to provide an end-to-end development environment.)</p>
<p><img src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1066660/image008.jpg" height="404" width="490"></p>
<p>In the Web service summary page, I just copied the <span class="SpellE"><span class="GramE">Url</span></span> to the
<span class="SpellE"><i>asmx</i></span><i> </i>page and copied it in to the URL text box of the
<b>Add Web Reference. </b>I clicked <b>Go </b>and the wizard did the rest.</p>
<p>&nbsp;</p>
<p><img src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1066660/image010.jpg" height="400" width="490"></p>
<p>Alright, I've held you in suspense long enough and now I'll tell you about one of the great things in the latest release of Visual Studio 2005. If you did read my earlier entry about using the Google Web service, you may remember the problem I had with getting
 the wizard to properly display the data types exposed by a Web service. This was the result of a bug in earlier releases of Microsoft Visual Studio 2005 wherein in the subsystem responsible for generating the Web service proxy classes did not properly translate
 the schema exposed in the Web services contract (WSDL) into public properties. That meant that the data types did not appear correctly in the Data Sources window, which in turn meant that you could not take advantage of drag-and-drop databinding. Eventually
 I found a workaround for the problem and got everything working correctly, but only after a lot of frustration and cursing of the Microsoft Beta Gods.</p>
<p>To my great delight, after I successfully added a reference to the Family History Web service, I opened the
<b>Data Sources </b>window and found that the data type was exposed in all its glory.</p>
<p><img src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1066660/image012.jpg" height="232" width="202"></p>
<p>I quickly set about taking advantage of the tools provided in the <b>Data Sources</b> window: I updated associated controls for the
<span class="SpellE"><b>BirthDate</b></span><b> </b>and <span class="SpellE"><b>DeathDate</b></span><b>
</b>fields to use a <b>DateTimePicker</b>, and I changed the <b>ID</b> field to use a
<b>Label </b>control</p>
<p>&nbsp;</p>
<p><img src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1066660/image014.jpg" height="232" width="202"></p>
<p>This made building the user interface very simple. I started by adding a <span class="SpellE">
<b>SplitContainer</b></span><b> </b>control on the form and changing its orientation property to
<b>Horizontal</b>. The modest design goal of my application was to provide a search capability on the top half of the form (using the
<span class="SpellE"><b>FindPerson</b></span><b> </b>Web method exposed by the Web service) and using the bottom half of the form to add or update family member data (using the
<span class="SpellE"><b>UpdatePerson</b></span> Web method of the Web service). So, in the top panel of the
<span class="SpellE"><b>SplitContainer</b></span><b> </b>I added to <span class="SpellE">
<b>TextBox</b></span><b> </b>controls and a <b>Button</b> control to enable searching. To build the bottom half, in the
<b>Data Sources</b> window I first changed the associated control for the top-level
<b>Person</b> class to <b>Details</b> and then dragged it onto the form surface. Visual Studio drew all the necessary controls on the form and created the
<b>BindingSource </b>and <span class="SpellE"><b>BindingNavigator</b></span><b> </b>
components for handling the chore of binding the Web service data to the controls on the form. I rearranged the controls and added two
<b>Button </b>controls to allow users to add new family members and update existing family members, respectively.
</p>
<p><img src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1066660/image016.jpg" height="450" width="490"></p>
<p>When a user executes a search using the top half of the form, the Web service returns an array of
<b>Person </b>objects. The code below is from the private <span class="SpellE"><b>searchPersons</b></span> method, which is called from the search button's click event handler. This shows the code that creates a new instance of the Web service proxy class,
 calls the <span class="SpellE"><b>FindPerson</b></span><b> </b>Web method using the first and last names input into the user interface. The array of
<b>Person </b>objects returned from the Web service is bound to the controls on the form by assigning the array to the
<span class="SpellE"><b>DataSource</b></span><b> </b>property of the <b>BindingSource
</b>control.</p>
<p><b>Visual C#</b></p>
<pre><code>localhost.FamilyHistory ws = new localhost.FamilyHistory();<br>localhost.Person[] persons = ws.FindPerson(firstNameSearch.Text, lastNameSearch.Text);<br><br>// Bind results to UI<br>personBindingSource.DataSource = persons;</code></pre>
<p><b>Visual Basic</b></p>
<pre><code>Dim ws As localhost.FamilyHistory = New localhost.FamilyHistory()<br>Dim persons() As localhost.Person = ws.FindPerson(firstNameSearch.Text, lastNameSearch.Text)<br><br>' Bind results to UI<br>personBindingSource.DataSource = persons</code></pre>
<p>By default, the data for the first person in the array is displayed in the bottom half of the form. The
<span class="SpellE"><b>BindingNavigator</b></span> component allows users to navigate through the list of returned family members. Using a similar pattern to the search operation, the click event handlers for the
<i>new</i> and <i>update</i> buttons call a private method called <span class="SpellE">
<b>submitPerson</b></span>. The <i>new </i>button differs from the <i>update </i>
button only in that clear the value of the <i>id </i>field for the person. When the Web service receives an
<span class="SpellE"><b>UpdatePerson</b></span><b> </b>message where the person <i>
id </i>value is empty, this indicates this is a new record; otherwise, the person data is treated as an update to an existing record.</p>
<p><b>Visual C#</b></p>
<pre><code>// Load data in Person object<br>localhost.Person person = new localhost.Person();<br>person.FirstName = firstNameTextBox.Text;<br>person.MiddleName = middleNameTextBox.Text;<br>person.LastName = lastNameTextBox.Text;<br>person.BirthDate = birthDateDateTimePicker.Value.ToShortDateString();<br>person.BirthLocation = birthLocationTextBox.Text;<br>person.DeathDate = deathDateDateTimePicker.Value.ToShortDateString();<br>person.DeathLocation = deathLocationTextBox.Text;<br>if (personId.Text != string.Empty)<br>{<br>     person.ID = Convert.ToInt32(personId.Text);<br>}<br><br>// Send update to Web service</code></pre>
<p><b>Visual Basic</b></p>
<pre><code>' Load data in Person object<br>Dim person As localhost.Person = New localhost.Person()<br>person.FirstName = firstNameTextBox.Text<br>person.MiddleName = middleNameTextBox.Text<br>person.LastName = lastNameTextBox.Text<br>person.BirthDate = birthDateDateTimePicker.Value.ToShortDateString()<br>person.BirthLocation = birthLocationTextBox.Text<br>person.DeathDate = deathDateDateTimePicker.Value.ToShortDateString()<br>person.DeathLocation = deathLocationTextBox.Text<br>If (personId.Text &lt;&gt; String.Empty) Then<br>  person.ID = Convert.ToInt32(personId.Text)<br>End If<br><br>' Send update to Web service<br>Dim ws As localhost.FamilyHistory = New localhost.FamilyHistory()<br>personId.Text = ws.UpdatePerson(person).ToString()<br>localhost.FamilyHistory ws = new localhost.FamilyHistory();<br>personId.Text = ws.UpdatePerson(person).ToString();</code></pre>
<p>The return value from the <span class="SpellE"><b>UpdatePerson</b></span><b> </b>
Web method is the <i>id </i>of the new or updated person record. This value is displayed back to the form.</p>
<p>Finally, I wanted to point out a special application setting that gets created when you add a connection to a Web service. Visual Studio 2005 automatically names the settings, and sets its value to the
<span class="SpellE"><span class="GramE">Url</span></span> of the Web reference.</p>
<p>&nbsp;</p>
<p><img src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1066660/image018.jpg" height="400" width="490"></p>
<p>Application settings get stored in the application's configuration file, allowing you to update settings without having to recompile an application. Here's a snippet of the
<span class="SpellE"><i>app.config</i></span><i> </i>file for the application.</p>
<div>
<div>
<p class="code"><span>&lt;</span><span class="SpellE"><span class="GramE">applicationSettings</span></span><span>&gt;</span><span><br>
&nbsp;&nbsp;&nbsp;&nbsp;</span><span>&lt;</span><span class="SpellE">FamilyHistoryClient.Properties.Settings</span><span>&gt;</span><span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span>&lt;</span>setting<span>&nbsp;name</span><span>=&quot;FamilyHistoryClient_localhost_Family_x0020_History&quot;</span><span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="SpellE">serializeAs</span></span><span>=&quot;String&quot;&gt;</span><span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span>&lt;</span>value<span>&gt;</span><span>http://localhost:1065/CS/Service.asmx</span><span>&lt;/</span>value<span>&gt;</span><span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span>&lt;/</span>setting<span>&gt;</span><span><br>
&nbsp;&nbsp;&nbsp;&nbsp;</span><span>&lt;/</span><span class="SpellE">FamilyHistoryClient.Properties.Settings</span><span>&gt;</span><span><br>
</span><span>&lt;/</span><span class="SpellE">applicationSettings</span><span>&gt;</span>
</p>
</div>
</div>
<p>When the application is compiled, this file appears in the output directory as
<b><i>&lt;</i></b><span class="SpellE"><i>appName</i></span><i>&gt;.<span class="SpellE">exe.config</span>.
</i></p>
<p>To appreciate the beauty of this, I looked at the code for the proxy class that Visual Studio 2005 automatically generated for the Web service. You may not see the proxy class because it is hidden by default. To view the file, titled
<span class="SpellE"><i>Reference.</i>cs</span>, but clicking the <b>Show All Files</b> button in the Solution Explorer toolbar and then expand
<b>Web References | <span class="SpellE">localhost</span> | <span class="SpellE">
Reference.map</span> </b>as shown below.</p>
<p><img src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1066660/image020.jpg" height="329" width="284"><span>&nbsp;</span></p>
<p>In <span class="SpellE"><i>Reference.cs</i></span><i> </i>I found the Web Service URL application setting is accessed in the constructor of the proxy to establish the
<span class="SpellE"><span class="GramE">Url</span></span> for the target Web service.</p>
<p><b>Visual C#</b></p>
this.Url&nbsp;=&nbsp;FamilyHistoryClient.Properties.Settings. Default.FamilyHistoryClient_localhost_Family_x0020_History;
<pre></pre>
<p><b>Visual Basic</b></p>
<pre><code>Me.Url = FamilyHistoryClient.Settings.<br>    Default.FamilyHistoryClient_localhost_Family_x0020_History</code></pre>
<p>While the auto-named property setting name is a bit unwieldy, this represents a big improvement on past implementations of Visual Studio 2005 Web service tools that hard-coded the Web reference
<span class="SpellE"><span class="GramE">Url</span></span> in the proxy class. This made it difficult to use configuration settings to control the location of Web service endpoints at runtime. Of course, this will make it much easier for me to deploy my client
 application once I've found a home for the Family History Web service.</p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/c4f.Peter-Bernhardt/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:26cffbbfb567442098c29e7600d86fba">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/articles/Building-a-Family-History-Web-Service-Client</comments>
      <itunes:summary>



&amp;nbsp;
This article is basically about Family History Web service using Visual Web Developer 2005 Express Edition In this article a client application is shown which is built as a front end to the Web service.




Peter Bernhardt
3Leaf Development

Difficulty: Easy
Time Required: 
1-3 hours
Cost: Free
Software: Visual Basic or Visual C# Express Editions,
Hardware: 
Download: Download








Last time, I walked through putting together a Family History Web service using Visual Web Developer 2005 Express Edition. To complete the circle, in this installment I&#39;ll show you a client application I built as a front end to the Web service. Before getting
 into the application itself, I want to report that since my last entry I&#39;ve updated my development environment to use the latest beta release of the Microsoft Visual Studio Express Editions. If you haven&#39;t yet made the move yourself, I urge you do so at your
 earliest opportunity. Because the update introduces some breaking changes with earlier beta releases, this will likely inflict some pain if you&#39;ve already built some applications. But for me, at least, the pain is far outweighed by the gain in bug fixes and
 features improvements, one of which I am pleased to highlight in this post. But I hold that for a bit later. 
 
The client application for my Family History Web service is a Windows Forms application. As you may recall, the Web service exposes two methods; a search method and an update method. This provides the bare bones functionality I need to start gathering information
 about my ancestors. I thus started by creating a new Windows Application in Microsoft Visual C# 2005 Express Edition. Next, I added a connection to the Family History Web service as a data source. 
 
All versions of Visual Studio provide an easy-to-use wizard for configuring a Web service as a data source for an application. I&#39;ve described how to use the wizard in previous entries; you simply select the
Data | Add New Data Source menu item.</itunes:summary>
      <link>http://channel9.msdn.com/coding4fun/articles/Building-a-Family-History-Web-Service-Client</link>
      <pubDate>Mon, 13 Nov 2006 02:50:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/articles/Building-a-Family-History-Web-Service-Client</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/1066660_100.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/1066660_220.jpg" height="165" width="220"></media:thumbnail>      
      <dc:creator>Peter Bernhardt</dc:creator>
      <itunes:author>Peter Bernhardt</itunes:author>
      <slash:comments>8</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/coding4fun/articles/Building-a-Family-History-Web-Service-Client/RSS</wfw:commentRss>
    </item>
  <item>
      <title>Aggregating Syndicated Content</title>
      <description><![CDATA[<span id="c4fmetadata">
<table border="0" cellpadding="1" cellspacing="0" width="100%">
<tbody>
<tr class="entry_overview">
<td width="50">&nbsp;</td>
<td><span class="entry_description">In this article, it is shown how to extend basic RSS user control to work with more than one content feed. Combining syndicated content from various sources, known most simply as aggregation, widens the breadth of information
 available on the web site and allows relating information in uniquely relevant ways for users.</span></td>
</tr>
<tr>
<td colspan="2">
<div class="entry_author">Peter Bernhardt</div>
<div class="entry_company"><a href="http://www.3leafdev.com/Home.aspx">3Leaf Development</a></div>
<br>
<div class="entry_details"><b>Difficulty: </b><span class="entry_details_input">Easy</span></div>
<div class="entry_details"><b>Time Required:</b> <span class="entry_details_input">
1-3 hours</span></div>
<div class="entry_details"><b>Cost: </b><span class="entry_details_input">Free</span></div>
<div class="entry_details"><b>Software: </b><span class="entry_details_input"><a href="http://msdn.com/express/">Visual Basic or Visual C# Express Editions</a></span></div>
<div class="entry_details"><b>Hardware: </b><span class="entry_details_input"></span></div>
<div class="entry_details"><b>Download: </b>
<ul>
<li><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1066560/RSSAggregator_20-_20CS.msi">C# Download</a>
</li><li><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1066560/RSSAggregator_20-_20VB.msi">VB Download</a>
</li></ul>
</div>
</td>
</tr>
</tbody>
</table>
</span>
<p>Building on my last installment, in this article I'll show you how to extend our basic RSS user control to work with more than one content feed. Combining syndicated content from various sources, known most simply as aggregation, widens the breadth of information
 available on your web site and lets you relate information in uniquely relevant ways for users.</p>
<p>One interesting background item I'd like to mention is Kent Sharkey's MSDN article
<a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/mergingrssfeeds.asp">
E Pluriblog Unum: Merging RSS Feeds</a>, which demonstrates some nifty techniques for merging RSS feeds into a single file. While the article is based on version 1.1 of the .NET Framework, you can use the source code that accompanies the article to jump start
 your own projects. I didn't do that myself, but I did borrow some of the ideas about how to approach aggregating syndicated content into a comprehensive view.</p>
<p>The first thing I considered was how to manage a list of individual feeds. While you can use a number of different techniques for tracking a list of source feeds, such as an
<a href="http://en.wikipedia.org/wiki/OPML">Outline Processor Markup Language</a> (OPML) file, I decided to take advantage of SQL Server 2005 Express Edition and the enhanced ASP.NET 2.0 data binding model to implement a basic RSS feed manager. Besides the
 ease of use ASP.NET 2.0 provides for accessing data, my main reason for choosing this method is that it sets the stage for leveraging the personalization services available using the Web Parts framework. After all, the ultimate goal of this type of application
 is to allow individual users to choose their own list of feeds. But let's not get ahead of ourselves; my goal in this article is to show how to manage the feed list itself.</p>
<p>In a fresh Visual Studio Web Developer Express project, I added a new SQL Database. I created a single table in the database and named it
<i>feeds</i><b>. </b>Using the integrated table designer, I configured three columns in the table: an identity column and two string-based columns for storing the title and location of the feed.</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1066560/rssagg_1.gif" target="_Top"><img src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1066560/rssagg_1_thumb.gif" title="Click here for larger image" alt="Click here for larger image" border="0" height="347" width="475"></a></p>
<p><b>(click image to zoom)</b></p>
<p>Next, I added a new Web User Control to the project. From the Toolbox, I dragged a
<b>SqlDataSource </b>control to the design surface of the Web User Control. This control is the cornerstone of the enhanced data access model in ASP.NET 2.0. It provides a direct connection between user interface controls and an ADO.NET managed provider (such
 as the SQL database I use in this application). From the smart tag menu, I selected &quot;Configure Data Source...&quot; to launch the data source configuration wizard.
</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1066560/rssagg_2.gif" target="_Top"><img src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1066560/rssagg_2_thumb.gif" alt="Click here for larger image" border="0"></a></p>
<p><b>(click image to zoom)</b></p>
<p>I followed the steps in the wizard to create a new connection string for the database, making sure that I selected the option to save the connection string information to the application configuration file. The wizard provides a page for building the default
 SQL SELECT statement. You can enter a custom SQL statement or stored procedure, or do what I did and work with the available table in the database to build the query statement directly.</p>
<p><img src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1066560/rssagg_3.gif" alt="" border="0"></p>
<p>Once you select a table, the available columns appear in the Columns list. As you select individual columns, the text of the SELECT statement displayed on the page gets updated accordingly. The next page in the wizard allows you to test the query. That wasn't
 much help in this case because I didn't have any data in the database. </p>
<p>After completing the wizard, I went back to the Toolbox and added a <b>GridView
</b>control to the Web User Control page. The smart tag menu for the <b>GridView </b>
control immediately appeared and I used the &quot;Choose Data Source&quot;<b> </b>dropdown menu to set the
<b>DataSourceID </b>property to the <b>SqlDataSource</b> control.</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1066560/rssagg_4.gif" target="_Top"><img src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1066560/rssagg_4_thumb.gif" alt="Click here for larger image" border="0"></a></p>
<p><b>(click image to zoom)</b></p>
<p>Next, I selected the &quot;Edit Columns&quot; item from the smart tag menu to edit the <b>
GridView</b>'s columns. I used the editor to make the identity column (<b>feedId</b>) invisible and updated the header text for the
<b>title</b> and <b>url</b> columns so they would look better when displayed on the web page.</p>
<p><img src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1066560/rssagg_5.gif" alt="" border="0"></p>
<p>I also updated the appearance of the <b>GridView</b> using the Auto Format editor (accessible from the smart tag menu). I then moved over to the Properties window for the
<b>GridView</b> control. To allow users to update or delete an item directly inside the list, I changed the
<b>AutoGenerateDeleteButton</b> and <b>AutoGenerateEditButton</b> properties to <b>
true</b>. This automatically altered the appearance of the <b>GridView</b> in the designer. As shown below, Edit and Delete links now appeared on the left side of the grid.</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1066560/rssagg_6.gif" target="_Top"><img src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1066560/rssagg_6_thumb.gif" alt="Click here for larger image" border="0"></a></p>
<p><b>(click image to zoom)</b></p>
<p>The ADO.NET 2.0 object model is very simple, with the <b>SqlDataSource </b>control responsible for executing CRUD operations against a data source on behalf of its bound server controls. In this case, the
<b>SqlDataSource </b>control is responsible for executing not only the SELECT statement to retrieve the data, but also the DELETE and UPDATE commands. Using the Properties window for the
<b>SqlDataSource </b>control, I opened the Command and Property Editor<b> </b>for the
<b>DeleteQuery </b>property and typed in the necessary SQL statement to perform a delete.</p>
<p><img src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1066560/rssagg_7.gif" alt="" border="0"></p>
<p>Notice that the parameter I used is written out as <b>@original_feedId</b>. The
<b>SqlDataSource </b>control has another property titled <b>OldValuesParameterFormatString</b> that specifies how an input parameter ought to appear in a query. The default for this property is
<b>original_{0}</b>, where <b>{0}</b> is a placeholder for the actual value of the parameter. Also note that I changed the
<b>Parameter source</b> value to <b>Control</b> and the <b>ControlID </b>value to point to the
<b>GridView </b>control. I followed the same procedure to add an UPDATE SQL statement in the
<b>UpdateQuery </b>property of the <b>SqlDataSource </b>control.</p>
<p>Well, all that is well and good. However, I found that the <b>GridView </b>does not provide an easy way to add new records to a database. You can solve this problem in a number of different ways (including creative use of the footer template of the
<b>GridView</b>). My solution was to use the <b>DetailsView </b>control. Like the
<b>GridView</b>, this is another versatile tool for data access. It lets you navigate over a set of data, displaying one record at a time, update or delete the current record, or add a new record. You can also use this control in conjunction with a
<b>GridView </b>to implement a classic master/detail representation of data. In that scenario, the
<b>GridView </b>simply displays a list of selectable items, which when selected appear in detail in the
<b>DetailsView </b>control. The flexibility of these controls gives you a lot of choices in providing the best user interface for your Web pages. For my purposes, I liked the idea of providing direct edit and delete in the
<b>GridView</b>, while using the <b>DetailsView </b>for adding new records.</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1066560/rssagg_8.gif" target="_Top"><img src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1066560/rssagg_8_thumb.gif" alt="Click here for larger image" border="0"></a></p>
<p><b>(click image to zoom)</b></p>
<p>After adding a <b>DetailsView </b>control directly beneath the <b>GridView, </b>
I set its <b>DataSourceID </b>property to the <b>SqlDataSource </b>control and made sure that only its
<b>AutoGenerateInsertButton </b>property was set to <b>true. </b>To boost performance, I changed the
<b>EnabledViewState </b>property to <b>false</b>.<b> </b>With that done, I added the necessary SQL text for performing a database INSERT in the
<b>InsertQuery </b>property of the <b>SqlDataSource </b>control.</p>
<p><img src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1066560/rssagg_9.gif" alt="" border="0"></p>
<p>The only difference between the configuration of the <b>InsertQuery </b>property and the other query-related properties of the
<b>SqlDataSource </b>control was that the <b>ControlID </b>for <b>InsertQuery </b>
was set to the <b>DetailsView </b>control (rather than the <b>GridView</b>).</p>
<p>Remarkably, I implemented all the logic for managing the feed list without having to write a single line of code. Of course, downloading and merging the feeds is another matter, but it is certainly worth pausing here to marvel at the power and simplicity
 of the ASP.NET 2.0 data binding architecture.</p>
<p>In order to display the aggregated RSS 2.0 feeds, the first hurdle is implementing a common data format. Because I only needed to display a few standard data items (item, description and link), I decided to use a strongly-typed
<b>DataSet </b>to store the data gathered from each feed. The main advantage of this approach is that I could easily bind the resulting data to a user interface control. After adding a new
<b>DataSet </b>to the project, I opened it in the designer and created a single <b>
DataTable </b>with four columns (see below).</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1066560/rssagg_10.gif" target="_Top"><img src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1066560/rssagg_10_thumb.gif" alt="Click here for larger image" border="0"></a></p>
<p><b>(click image to zoom)</b></p>
<p>In addition to the three basic item attributes, I also included a column called
<b>Feed </b>to store the name of the source RSS feed so I could display this information on the Web page.</p>
<p>Next, I added two private methods to the <b>FeedManager </b>control's code file. The first method,
<b>MergeRssFeeds</b>, is called from the control's <b>Load </b>event handler. The first line of code creates a class-level instance of the strongly-typed
<b>AggregateRSS </b>dataset used to hold the data extracted from the RSS feeds. The code then iterates through the rows of the
<b>GridView </b>control, which represent each of the configured RSS feeds. Within the
<code>For</code><b> </b>loop, the code calls a second method, <b>AddRssFeed, </b>
passing in the name of the RSS Feed and the URL address of the RSS feed.</p>
<p><b>Visual Basic</b></p>
<pre><code>Private Sub MergeRssFeeds()<br>    RssData = New AggregatedRSS<br>    If Me.GridView1.Rows.Count &gt; 0 Then<br>        For i As Integer = 0 To Me.GridView1.Rows.Count - 1<br>            AddRssFeed(Me.GridView1.Rows(i).Cells(2).Text, _<br>                Me.GridView1.Rows(i).Cells(3).Text)<br>        Next i<br>    End If<br>    Me.Repeater1.DataSource = RssData<br>    Me.Repeater1.DataBind()<br>End Sub </code></pre>
<p><b>Visual C#</b></p>
<code></code>
<pre>private void MergeRssFeeds()<br>{<br>    RssData = new AggregatedRSS();<br>    try<br>    {<br>        if (this.GridView1.Rows.Count &gt; 0)<br>        {<br>            for (int i = 0; i &lt; this.GridView1.Rows.Count; i&#43;&#43;)<br>            {<br>                AddRssFeed(this.GridView1.Rows[i].Cells[2].Text,<br>                this.GridView1.Rows[i].Cells[3].Text);<br>            }<br>        }<br>        this.Repeater1.DataSource = RssData;<br>        this.Repeater1.DataBind();<br>    }<br>    catch (WebException wx)<br>    {<br>        Literal1.Text = String.Format(<br>        &quot;&lt;h3&gt;Error&lt;/h3&gt;&lt;p&gt;A Web exception occurred while merging the&quot; &#43; <br>        &quot; RSS feeds.&lt;br/&gt;Make sure you have a valid connection to the &quot; &#43; <br>        &quot;internet.&lt;/p&gt;&lt;p&gt;&lt;em&gt;{0}&lt;em&gt;&lt;/p&gt;&quot;, wx.Message);<br>        Literal1.Visible = true;<br>    }<br>}</pre>
<p>At the end of the loop, the code sets the <b>DataSource </b>property of the <b>
Repeater </b>control to the populated <b>DataSet </b>and then calls the <b>DataBind
</b>method of the <b>Repeater </b>to bind the data to the control.</p>
<p>The helper method <b>AddRssFeed </b>performs most of the heavy lifting in this application. The code first fetches the RSS feed using the
<b>WebRequest </b>class and loads the data into an <b>XmlTextReader. </b>The code then sets up a
<b>While </b>loop to iterate over the XML stream. To make the code easier to explain, I've included the first few lines of code below.</p>
<p><b>Visual Basic</b></p>
<pre><code>Private Sub AddRssFeed(ByVal feedTitle As String, ByVal feedUrl As String)<br>    Dim rssReader As XmlTextReader = Nothing<br>    Dim itemCount As Integer = 0<br><br>    Try<br>        Dim rssFeed As WebRequest = WebRequest.Create(feedUrl)<br>        rssReader = New XmlTextReader(rssFeed.GetResponse().GetResponseStream())<br>        While rssReader.Read<br>            [see detail below]<br>        End While<br>    Finally<br>        If Not rssReader Is Nothing Then rssReader.Close()<br>    End Try<br>End Sub <br> </code></pre>
<p><b>Visual C#</b></p>
<code></code>
<pre>private void AddRssFeed(string feedTitle, string feedUrl)<br>{<br>    XmlTextReader rssReader = null;<br>    int itemCount = 0;<br><br>    try<br>    {<br>        WebRequest rssFeed = WebRequest.Create(feedUrl);<br>        rssReader = <br>            new xmlTextReader(rssFeed.GetResponse().GetResponseStream());<br>        while (rssReader.Read())<br>        {<br>             [See the detail below]<br>        }<br>    }<br>    finally<br>    {<br>        if (itemReader != null) itemReader.Close();<br>    }<br>}</pre>
<p>Inside the outside <b>While </b>loop, the code looks for elements named &quot;item&quot;. This indicates that an RSS feed item is the current node. When this happens, the code creates a new
<b>RssItemRow </b>to store the item data and then creates a new <b>XmlReader </b>
object using the <b>ReadSubTree </b>method of the parent <b>XmlReader. </b>This reader (called
<b>itemReader)</b> holds the current RSS item data. The code calls the <b>Read </b>
method of the inner <b>XmlReader </b>to find each of the data items of interest. When found, the code stores the data value in the appropriate cell of the
<b>RssItemRow. </b>At the end of the inside <b>While </b>loop, the code calls the strongly-typed
<b>AddRssItemRow </b>method of the <b>DataTable </b>to add the row to the <b>DataSet.</b></p>
<p><b>Visual Basic</b></p>
<pre><code>While rssReader.Read<br>    If rssReader.IsStartElement And (&quot;item&quot; = rssReader.LocalName) Then<br>        Dim itemReader As XmlReader = Nothing<br>        Try<br>            Dim newRow As AggregatedRSS.RssItemRow = RssData.RssItem.NewRssItemRow()<br>            itemReader = rssReader.ReadSubtree()<br>            newRow.Feed = feedTitle<br>            While itemReader.Read<br>                If itemReader.IsStartElement Then<br>                    If (&quot;title&quot; = itemReader.LocalName) Then<br>                        newRow.Title = itemReader.ReadString<br>                    ElseIf (&quot;description&quot; = itemReader.LocalName) Then<br>                        Dim newDescription As String = itemReader.ReadString<br>                        ' Truncate description to 100 characters<br>                        If newDescription.Length &gt; 100 Then<br>                            newDescription = newDescription.Substring(0, 100) &#43; &quot; ...&quot;<br>                        End If<br>                            newRow.Description = newDescription<br>                        ElseIf (&quot;link&quot; = itemReader.LocalName) Then<br>                            newRow.Link = itemReader.ReadString<br>                        End If<br>                    End If<br>            End While<br>            RssData.RssItem.AddRssItemRow(newRow)<br>            itemCount = itemCount &#43; 1<br>        Finally<br>            If Not itemReader Is Nothing Then itemReader.Close()<br>        End Try<br>    End If<br>    ' Add only the first five items from each feed<br>    If itemCount &gt;= 5 Then Exit While<br>End While</code></pre>
<p><b>Visual C#</b></p>
<pre><code>while (rssReader.Read())<br>{<br>    if ((rssReader.IsStartElement()) &amp;&amp; (&quot;item&quot; == rssReader.LocalName))<br>    {<br>        XmlReader itemReader = null;<br>         try<br>         {<br>        AggregatedRSS.RssItemRow newRow = RssData.RssItem.NewRssItemRow();<br>        itemReader = rssReader.ReadSubtree();<br>        newRow.Feed = feedTitle;<br>        while (itemReader.Read())<br>        {<br>            if (itemReader.IsStartElement())<br>            {<br>            if (&quot;title&quot; == itemReader.LocalName)<br>                newRow.Title = itemReader.ReadString();<br>            else if (&quot;description&quot; == itemReader.LocalName)<br>            {<br>                string newDescription = itemReader.ReadString();<br>                //Truncate description to 100 characters<br>                if (newDescription.Length &gt; 100)<br>                    newDescription = newDescription.Substring(0, 100) &#43; <br>                        &quot; ...&quot;;<br>                newRow.Description = newDescription;<br>            }<br>            else if (&quot;link&quot; == itemReader.LocalName)<br>                newRow.Link = itemReader.ReadString();<br>            }<br>        }<br>        RssData.RssItem.AddRssItemRow(newRow);<br>        itemCount&#43;&#43;;<br>         }<br>        finally<br>        {<br>            if (itemReader != null) itemReader.Close();<br>        }<br>        // Add up to 5 of the items returns (this can be set in a <br>        // configuration file)<br>        if (itemCount &gt;= 5) break;<br>    }<br>}</code></pre>
<p>That's all the code I need to implement the RSS aggregation. As you can see, the hairiest part of the application was setting up the
<b>XmlReader </b>and iterating through them to extract the necessary feed data. But once that task was accomplished, ASP.NET's superior data binding capabilities made building this application very easy.</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1066560/rssagg_11.gif" target="_Top"><img src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1066560/rssagg_11_thumb.gif" alt="Click here for larger image" border="0"></a></p>
<p><b>(click image to zoom)</b></p>
<p>Looking ahead, the next step in the evolution of this project is to separate out the feed manager and feed display components into separate controls and to add personalization services ASP.NET 2.0 Web Parts framework. Until next time.</p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/c4f.Peter-Bernhardt/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:f923f6d70e2d4655a5299e7600d881d2">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/articles/Aggregating-Syndicated-Content</comments>
      <itunes:summary>



&amp;nbsp;
In this article, it is shown how to extend basic RSS user control to work with more than one content feed. Combining syndicated content from various sources, known most simply as aggregation, widens the breadth of information
 available on the web site and allows relating information in uniquely relevant ways for users.



Peter Bernhardt
3Leaf Development

Difficulty: Easy
Time Required: 
1-3 hours
Cost: Free
Software: Visual Basic or Visual C# Express Editions
Hardware: 
Download: 

C# Download
VB Download







Building on my last installment, in this article I&#39;ll show you how to extend our basic RSS user control to work with more than one content feed. Combining syndicated content from various sources, known most simply as aggregation, widens the breadth of information
 available on your web site and lets you relate information in uniquely relevant ways for users. 
One interesting background item I&#39;d like to mention is Kent Sharkey&#39;s MSDN article

E Pluriblog Unum: Merging RSS Feeds, which demonstrates some nifty techniques for merging RSS feeds into a single file. While the article is based on version 1.1 of the .NET Framework, you can use the source code that accompanies the article to jump start
 your own projects. I didn&#39;t do that myself, but I did borrow some of the ideas about how to approach aggregating syndicated content into a comprehensive view. 
The first thing I considered was how to manage a list of individual feeds. While you can use a number of different techniques for tracking a list of source feeds, such as an
Outline Processor Markup Language (OPML) file, I decided to take advantage of SQL Server 2005 Express Edition and the enhanced ASP.NET 2.0 data binding model to implement a basic RSS feed manager. Besides the
 ease of use ASP.NET 2.0 provides for accessing data, my main reason for choosing this method is that it sets the stage for leveraging the personalization services available using the Web Parts framework. After all, the ul</itunes:summary>
      <link>http://channel9.msdn.com/coding4fun/articles/Aggregating-Syndicated-Content</link>
      <pubDate>Mon, 13 Nov 2006 02:42:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/articles/Aggregating-Syndicated-Content</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/1066560_100.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/1066560_220.jpg" height="165" width="220"></media:thumbnail>      
      <dc:creator>Peter Bernhardt</dc:creator>
      <itunes:author>Peter Bernhardt</itunes:author>
      <slash:comments>1</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/coding4fun/articles/Aggregating-Syndicated-Content/RSS</wfw:commentRss>
    </item>
  <item>
      <title>Building a Family History Web Service</title>
      <description><![CDATA[
<table border="0" cellpadding="1" cellspacing="0">
<tbody>
<tr class="entry_overview">
<td width="50">&nbsp;</td>
<td><span class="entry_description">In this article review of Family History Web Service is made. It shows a client application built for collecting data about shared ancestors. Its developed using the Visual Web Developer 2005 Express Edition.</span></td>
</tr>
<tr>
<td colspan="2">
<div class="entry_author">Peter Bernhardt</div>
<br>
<div class="entry_details"><b>Difficulty: </b><span class="entry_details_input">Intermediate</span></div>
<div class="entry_details"><b>Time Required:</b> <span class="entry_details_input">
1-3 hours</span></div>
<div class="entry_details"><b>Cost: </b><span class="entry_details_input">Free</span></div>
<div class="entry_details"><b>Software: </b><span class="entry_details_input"><a href="http://msdn.com/express/">Visual Studio Express Editions</a></span></div>
<div class="entry_details"><b>Hardware: </b></div>
<div class="entry_details"><b>Download: </b><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/913303/263310_FamilyHistory.zip">Download</a></div>
</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>In my next two entries I’m going to review a family history Web service I’ve built using
<a href="http://go.microsoft.com/?linkid=2556525">Visual Web Developer 2005 Express Edition</a>. In this entry, I’ll start with a look at the Web service. In a following article, I’ll show you a client application I’ve built for my sister and cousins to use
 for collecting data about our shared ancestors (sorry, but Mom still won’t go near a computer).
</p>
<p><img src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/913303/image001.jpg" width="490" border="0" height="304">
</p>
<p>To begin, I fired up Visual Web Developer 2005 Express Edition and created a new ASP.NET Web site. A nice convenience of the latest version of ASP.NET is that you don’t need to install Internet Information Server (IIS) on your computer to build Web sites
 or Web services. Instead, you can run the application locally using the built-in Visual Web Developer Web Server. When you run a Web application, you’ll notice an icon appears in your task bar. If you double-click on the icon, a details dialog box similar
 to the one shown below appears. I really, really like this feature as it reduces the hassle of configuring your system to build Web applications to zero.
</p>
<p><img src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/913303/image002.jpg" width="428" border="0" height="231">
</p>
<p>But I’m get a bit ahead of the game. Once I had my new Web service opened in the IDE, my first task was to create a store for my family data. When you create a new project, you’ll notice a folder titled &quot;Data&quot; in the list of project items. When I right-clicked
 the folder and selected &quot;Add New Item...&quot; from the context menu, this displayed the dialog shown below.
</p>
<p><img src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/913303/image003.jpg" width="490" border="0" height="329">
</p>
<p>You can use XML or an ordinary text file as your data source for a Web application. As you can see, I chose a database – I named it, and then clicked the Add button. This created a brand new
<a href="http://go.microsoft.com/?linkid=2556527">SQL Server Express</a> database file for me in the project. Another great feature of Visual Studio 2005 in all its flavors is that you get built-in database support, without the muss or fuss of using an external
 program. Think of it as a one-stop shop. And Visual Web Developer 2005 Express Edition provides a wickedly simple designer for defining tables, views, stored procedures and other types of database objects. I created a new table named &quot;person&quot; and defined columns
 for the various attributes I want to record in my family history database. </p>
<p><img src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/913303/image004.jpg" width="490" border="0" height="400">
</p>
<p>With the skeleton of my database laid out, I moved to the Service.cs code file in my Web services application. Here I started by adding an attribute to the class definition.
</p>
<p><b>Visual C#</b> </p>
<pre><code></code></pre>
<pre class="csharpcode">[WebService(Namespace = <span class="str">&quot;uri:family:geneology&quot;</span>,Name = <span class="str">&quot;Family History&quot;</span>, <br>                Description = <span class="str">&quot;Web service for gathering family history data.&quot;</span> )]</pre>
<p><style type="text/css">
<!--
.csharpcode
 {font-size:small;
 color:black;
 font-family:consolas,"Courier New",courier,monospace;
 background-color:#ffffff}
.csharpcode 
 {font-size:small;
 color:black;
 font-family:consolas,"Courier New",courier,monospace;
 background-color:#ffffff}
.csharpcode 
 {margin:0em}
.csharpcode .rem
 {color:#008000}
.csharpcode .kwrd
 {color:#0000ff}
.csharpcode .str
 {color:#006080}
.csharpcode .op
 {color:#0000c0}
.csharpcode .preproc
 {color:#cc6633}
.csharpcode .asp
 {background-color:#ffff00}
.csharpcode .html
 {color:#800000}
.csharpcode .attr
 {color:#ff0000}
.csharpcode .alt
 {margin:0em;
 width:100%;
 background-color:#f4f4f4}
.csharpcode .lnum
 {color:#606060}
-->
</style></p>
<p><b>Visual Basic</b> </p>
<pre><code></code></pre>
<pre class="csharpcode">&lt;WebService(<span class="kwrd">Namespace</span>:=<span class="str">&quot;uri:family:geneology&quot;</span>, Name:=<span class="str">&quot;Family History&quot;</span>, _ <br>                Description:=<span class="str">&quot;Web service for gathering family history data.&quot;</span>)&gt;</pre>
<p><style type="text/css">
<!--
.csharpcode
 {font-size:small;
 color:black;
 font-family:consolas,"Courier New",courier,monospace;
 background-color:#ffffff}
.csharpcode 
 {font-size:small;
 color:black;
 font-family:consolas,"Courier New",courier,monospace;
 background-color:#ffffff}
.csharpcode 
 {margin:0em}
.csharpcode .rem
 {color:#008000}
.csharpcode .kwrd
 {color:#0000ff}
.csharpcode .str
 {color:#006080}
.csharpcode .op
 {color:#0000c0}
.csharpcode .preproc
 {color:#cc6633}
.csharpcode .asp
 {background-color:#ffff00}
.csharpcode .html
 {color:#800000}
.csharpcode .attr
 {color:#ff0000}
.csharpcode .alt
 {margin:0em;
 width:100%;
 background-color:#f4f4f4}
.csharpcode .lnum
 {color:#606060}
-->
</style></p>
<p>The <i>WebServiceAttribute</i> class (you can leave out &quot;Attribute&quot; in your code as I did) lets you give the Web service a unique internet identity using the namespace attribute. I also gave the Web service a name and a description.
</p>
<p>Then I renamed the stub &quot;Hello World&quot; Web method to &quot;FindPerson&quot;<i> </i>and updated its
<i>WebMethodAttribute </i>declaration to describe the task I intend for the Web method. In this case, the FindPerson method returns a list of people stored in my family history database based on some search criteria. After thinking a bit about how to return
 search results, I decided against using a <i>DataSet </i>(which is possible but not really a good idea if you want your Web service to get along well with non-.NET clients) and chose to model a Person object after the contents of my database and use that as
 my return type. </p>
<p>I added a class named &quot;Person&quot; to my project and defined a number of public properties that deliberately map to the columns in the person table of the database. Of course, I am not solely bound to mapping the attributes of the table data to the properties
 of the class; I will probably extend the class some more with behaviors as this application takes on more heft later on. Next, to make the class truly useful, I added a
<i>SerializableAttribute</i> to the class declaration. </p>
<p><b>Visual C#</b> </p>
<pre><code></code></pre>
<pre class="csharpcode">[Serializable()]<br><span class="kwrd">public</span> <span class="kwrd">class</span> Person {<br>...<br>}</pre>
<p><style type="text/css">
<!--
.csharpcode
 {font-size:small;
 color:black;
 font-family:consolas,"Courier New",courier,monospace;
 background-color:#ffffff}
.csharpcode 
 {font-size:small;
 color:black;
 font-family:consolas,"Courier New",courier,monospace;
 background-color:#ffffff}
.csharpcode 
 {margin:0em}
.csharpcode .rem
 {color:#008000}
.csharpcode .kwrd
 {color:#0000ff}
.csharpcode .str
 {color:#006080}
.csharpcode .op
 {color:#0000c0}
.csharpcode .preproc
 {color:#cc6633}
.csharpcode .asp
 {background-color:#ffff00}
.csharpcode .html
 {color:#800000}
.csharpcode .attr
 {color:#ff0000}
.csharpcode .alt
 {margin:0em;
 width:100%;
 background-color:#f4f4f4}
.csharpcode .lnum
 {color:#606060}
-->
</style></p>
<p><b>Visual Basic</b> </p>
<pre><code></code></pre>
<pre class="csharpcode">&lt;Serializable()&gt; _<br><span class="kwrd">Public</span> <span class="kwrd">Class</span> Person<br>...<br><span class="kwrd">End</span> Class</pre>
<p><style type="text/css">
<!--
.csharpcode
 {font-size:small;
 color:black;
 font-family:consolas,"Courier New",courier,monospace;
 background-color:#ffffff}
.csharpcode 
 {font-size:small;
 color:black;
 font-family:consolas,"Courier New",courier,monospace;
 background-color:#ffffff}
.csharpcode 
 {margin:0em}
.csharpcode .rem
 {color:#008000}
.csharpcode .kwrd
 {color:#0000ff}
.csharpcode .str
 {color:#006080}
.csharpcode .op
 {color:#0000c0}
.csharpcode .preproc
 {color:#cc6633}
.csharpcode .asp
 {background-color:#ffff00}
.csharpcode .html
 {color:#800000}
.csharpcode .attr
 {color:#ff0000}
.csharpcode .alt
 {margin:0em;
 width:100%;
 background-color:#f4f4f4}
.csharpcode .lnum
 {color:#606060}
-->
</style></p>
<p>This signals to the ASP.NET runtime that the class and all of its properties can be serialized (that is, converted to XML) either as an input to one of my Web methods or as a return value.
</p>
<p>Returning to the Web method, I updated the method signature to return an array of
<i>Person</i> objects (families do have members with the same first and last names, after all). I also added another Web method called &quot;UpdatePerson&quot; for adding a new person to my database or for updating an existing person. Again, I took advantage of the underlying
 serialization capabilities of ASP.NET by declaring a single input parameter of type
<i>Person</i>. </p>
<p>Following good coding practice, I factored out the actual nuts and bolts work of querying and updating the database to three private helper methods in the Service.cs file. If you look over the code in the &quot;SearchPerson&quot;, &quot;AddPerson&quot; and &quot;UpdatePerson&quot; methods
 you will find the application uses stored procedures to perform work against the database. Again, the database tools provided in Visual Studio Web Developer 2005 Express made this chore virtually painless.
</p>
<p><img src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/913303/image005.jpg" width="490" border="0" height="375">
</p>
<p>That completes the tour of this application.&nbsp;Next time, I’ll show you the client application I’m going to use to manage querying and data entry for the Web service. In the meantime, I encourage you to download
<a href="http://go.microsoft.com/?linkid=2556525">Visual Web Developer 2005 Express Edition</a> and explore this Web service application for yourself.
</p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/c4f.Peter-Bernhardt/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:75f3603a7fda4abe9edf9e7600da5084">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/articles/Building-a-Family-History-Web-Service</comments>
      <itunes:summary>



&amp;nbsp;
In this article review of Family History Web Service is made. It shows a client application built for collecting data about shared ancestors. Its developed using the Visual Web Developer 2005 Express Edition.



Peter Bernhardt

Difficulty: Intermediate
Time Required: 
1-3 hours
Cost: Free
Software: Visual Studio Express Editions
Hardware: 
Download: Download




&amp;nbsp; 
In my next two entries I’m going to review a family history Web service I’ve built using
Visual Web Developer 2005 Express Edition. In this entry, I’ll start with a look at the Web service. In a following article, I’ll show you a client application I’ve built for my sister and cousins to use
 for collecting data about our shared ancestors (sorry, but Mom still won’t go near a computer).
 

 
To begin, I fired up Visual Web Developer 2005 Express Edition and created a new ASP.NET Web site. A nice convenience of the latest version of ASP.NET is that you don’t need to install Internet Information Server (IIS) on your computer to build Web sites
 or Web services. Instead, you can run the application locally using the built-in Visual Web Developer Web Server. When you run a Web application, you’ll notice an icon appears in your task bar. If you double-click on the icon, a details dialog box similar
 to the one shown below appears. I really, really like this feature as it reduces the hassle of configuring your system to build Web applications to zero.
 

 
But I’m get a bit ahead of the game. Once I had my new Web service opened in the IDE, my first task was to create a store for my family data. When you create a new project, you’ll notice a folder titled &amp;quot;Data&amp;quot; in the list of project items. When I right-clicked
 the folder and selected &amp;quot;Add New Item...&amp;quot; from the context menu, this displayed the dialog shown below.
 

 
You can use XML or an ordinary text file as your data source for a Web application. As you can see, I chose a database – I named it, and then clicked the Add</itunes:summary>
      <link>http://channel9.msdn.com/coding4fun/articles/Building-a-Family-History-Web-Service</link>
      <pubDate>Tue, 31 Oct 2006 18:37:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/articles/Building-a-Family-History-Web-Service</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/913303_100.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/913303_220.jpg" height="165" width="220"></media:thumbnail>      
      <dc:creator>Peter Bernhardt</dc:creator>
      <itunes:author>Peter Bernhardt</itunes:author>
      <slash:comments>3</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/coding4fun/articles/Building-a-Family-History-Web-Service/RSS</wfw:commentRss>
    </item>
  <item>
      <title>Displaying Your iTunes Library</title>
      <description><![CDATA[<span id="c4fmetadata">
<table class="" cellspacing="0" cellpadding="1" width="100%" border="0">
<tbody>
<tr class="entry_overview">
<td class="" width="50">&nbsp;</td>
<td class=""><span class="entry_description">iTunes allows to play and organize music collection, as well as buy individual songs from their online store. All the information stored using iTunes is stored as XML; that allows to display music library in different
 formats. In this article some of the new ASP.NET controls available in Visual Web Developer 2005 Express are used to display iTunes library on a Web page.</span></td>
</tr>
<tr>
<td class="" colspan="2">
<div class="entry_author">Peter Bernhardt</div>
<div class="entry_company"><a href="http://blogs.msdn.com/controlpanel/blogs/"></a></div>
<br>
<div class="entry_details"><b>Difficulty: </b><span class="entry_details_input">Intermediate</span></div>
<div class="entry_details"><b>Time Required:</b> <span class="entry_details_input">
1-3 hours</span></div>
<div class="entry_details"><b>Cost: </b><span class="entry_details_input">Free</span></div>
<div class="entry_details"><b>Software: </b><span class="entry_details_input"><a href="http://msdn.com/express/">Visual Studio Express Editions</a>,
<a class="" href="http://www.apple.com/itunes/">Apple iTunes</a></span></div>
<div class="entry_details"><b>Hardware: </b></div>
<div class="entry_details"><strong>Download: </strong><a class="" href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/913191/XML_20For_20Fun_20-_20iTunes_20Library.msi">Download</a></div>
<div class="entry_details"><strong><span class="entry_details_input"></span></strong>&nbsp;</div>
<div class="entry_details&lt;UL">
<ul>
</ul>
</div>
</td>
</tr>
</tbody>
</table>
</span>
<p>You probably already know about Apple's iTunes application and that it allows you to play and organize your music collection, as well as buy individual songs from their online store. What you probably don't know is that all the information you store using
 iTunes is stored as XML; that allows you to display your music library in different formats. Like a web page, for example.
</p>
<p><img src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/913191/ituneslib_1.png" width="485" border="0">
</p>
<p>So, to give you a flavor for how you might use the iTunes data in your own applications, in this article I'll use some of the new ASP.NET controls available in Visual Web Developer 2005 Express to display my iTunes library on a Web page.
</p>
<p>If you want to use your own library and you don't already have iTunes installed, visit
<a href="http://www.apple.com/itunes">http://www.apple.com/itunes</a> to download the free iTunes application. Using my own library, I began by creating a new ASP.NET Web site. Next, I used the
<b>Web Site | Add Existing Item </b>menu command to add my iTunes music library file.
</p>
<p><img src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/913191/ituneslib_2.png" width="485" border="0">
</p>
<p>As pictured above, the default iTunes directory is located in the <b>My Music </b>
folder. The XML file is named <i>iTunes Music Library.xml</i>. After adding the file to my Web site project, I changed the name to something simpler:
<i>iTunes.xml</i>. </p>
<p>ASP.NET 2.0 introduces a new <b>XmlDataSource </b>control that is a special type of data source control for consuming XML data. In Visual Web Developer 2005 Express, you'll find this control located in the
<b>Data </b>section of the <b>Toolbox. </b>After dragging an <b>XmlDataSource </b>
control onto the Web form, I used the <b>Configure Data Source </b>dialog box to point the control to my iTunes data file.
</p>
<p><img src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/913191/ituneslib_3.png" width="485" border="0">
</p>
<p>Before moving on, take a moment to look at the other options available in the <b>
Configure Data Source </b>dialog. You can specify a transformation file that updates the structure of the XML file. You may wonder why this might be necessary. But as I discovered myself shortly after performing this step, you will often find circumstances
 where it's necessary to change the source XML to make it a usable data source. For now, however, I only set the
<b>DataFile </b>property of the <b>XmlDataSource </b>property. </p>
<div class="body">
<div class="postBody" id="269f3ba4-1962-4c7b-9c62-d73b2d31a3b3">
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">asp:XmlDataSource</span> <span class="attr">ID</span><span class="kwrd">=&quot;XmlDataSource1&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <span class="attr">DataFile</span><span class="kwrd">=&quot;~/iTunes.xml&quot;</span><span class="kwrd">&gt;</span><br><span class="kwrd">&lt;/</span><span class="html">asp:XmlDataSource</span><span class="kwrd">&gt;</span></pre>
<style type="text/css">
<!--
.csharpcode
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{margin:0em;
	width:100%;
	background-color:#f4f4f4}
.csharpcode .lnum
	{color:#606060}
-->
</style></div>
</div>
<p>Also, if you peek at the source code for the default Web form at this point, you'll find code similar to that shown above. This highlights the fact that you can easily add code directly to ASP.NET Web forms to configure controls. The Visual Studio designers
 simply provide an easy-to-use alternative to hand coding while reducing the guesswork.
</p>
<p>The <b>XmlDataSource </b>by itself only takes you halfway toward displaying XML data on a web page: You also need a control for displaying that data. Because the
<b>XmlDataSource</b> control supports declarative databinding to XML files, you can use it to bind hierarchical data to controls that are specially designed for traversing this type of data, like a
<b>TreeView</b> or <b>Menu</b>. You can also use the <b>XmlDataSource </b>for binding XML data to list controls like the
<b>GridView, DropDownList</b> or <b>DataList </b>controls. </p>
<p>On the design surface of the Default Web form, I added a <b>TreeView </b>control on the line below the
<b>XmlDataSource </b>control. Next, I set the <b>DataSource </b>property of the <b>
TreeView </b>to the instance of the <b>XmlDataSource </b>control. Again, leveraging the designer support in Visual Studio 2005, I accomplished this easily using the Smart Tag menu provided with the
<b>TreeView </b>control. </p>
<p><img alt="" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/913191/ituneslib_4.png" border="0">
</p>
<p>At design time, the <b>TreeView </b>control displays the data as it will appear when you run the Web page. The following graphic shows what the data from my iTunes XML file looked like at this point.
</p>
<p><img src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/913191/ituneslib_5.png" width="485" border="0">
</p>
<p>Hmmmm …. that's not very useful, is it? It's time to take a look at the iTunes XML file. Below is a snippet from my file.
</p>
<pre><code></code></pre>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">dict</span><span class="kwrd">&gt;</span><br>        <span class="kwrd">&lt;</span><span class="html">key</span><span class="kwrd">&gt;</span>35<span class="kwrd">&lt;/</span><span class="html">key</span><span class="kwrd">&gt;</span><br>        <span class="kwrd">&lt;</span><span class="html">dict</span><span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">key</span><span class="kwrd">&gt;</span>Track ID<span class="kwrd">&lt;/</span><span class="html">key</span><span class="kwrd">&gt;&lt;</span><span class="html">integer</span><span class="kwrd">&gt;</span>35<span class="kwrd">&lt;/</span><span class="html">integer</span><span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">key</span><span class="kwrd">&gt;</span>Name<span class="kwrd">&lt;/</span><span class="html">key</span><span class="kwrd">&gt;&lt;</span><span class="html">string</span><span class="kwrd">&gt;</span>Gula Gula<span class="kwrd">&lt;/</span><span class="html">string</span><span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">key</span><span class="kwrd">&gt;</span>Artist<span class="kwrd">&lt;/</span><span class="html">key</span><span class="kwrd">&gt;&lt;</span><span class="html">string</span><span class="kwrd">&gt;</span>Jan Garbarek<span class="kwrd">&lt;/</span><span class="html">string</span><span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">key</span><span class="kwrd">&gt;</span>Composer<span class="kwrd">&lt;/</span><span class="html">key</span><span class="kwrd">&gt;&lt;</span><span class="html">string</span><span class="kwrd">&gt;</span>Mari Boine Persen, arr Jan Garbarek<span class="kwrd">&lt;/</span><span class="html">string</span><span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">key</span><span class="kwrd">&gt;</span>Album<span class="kwrd">&lt;/</span><span class="html">key</span><span class="kwrd">&gt;&lt;</span><span class="html">string</span><span class="kwrd">&gt;</span>I Took Up The Runes<span class="kwrd">&lt;/</span><span class="html">string</span><span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">key</span><span class="kwrd">&gt;</span>Genre<span class="kwrd">&lt;/</span><span class="html">key</span><span class="kwrd">&gt;&lt;</span><span class="html">string</span><span class="kwrd">&gt;</span>Jazz<span class="kwrd">&lt;/</span><span class="html">string</span><span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">key</span><span class="kwrd">&gt;</span>Kind<span class="kwrd">&lt;/</span><span class="html">key</span><span class="kwrd">&gt;&lt;</span><span class="html">string</span><span class="kwrd">&gt;</span>AAC audio file<span class="kwrd">&lt;/</span><span class="html">string</span><span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">key</span><span class="kwrd">&gt;</span>Size<span class="kwrd">&lt;/</span><span class="html">key</span><span class="kwrd">&gt;&lt;</span><span class="html">integer</span><span class="kwrd">&gt;</span>5892093<span class="kwrd">&lt;/</span><span class="html">integer</span><span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">key</span><span class="kwrd">&gt;</span>Total Time<span class="kwrd">&lt;/</span><span class="html">key</span><span class="kwrd">&gt;&lt;</span><span class="html">integer</span><span class="kwrd">&gt;</span>363578<span class="kwrd">&lt;/</span><span class="html">integer</span><span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">key</span><span class="kwrd">&gt;</span>Disc Number<span class="kwrd">&lt;/</span><span class="html">key</span><span class="kwrd">&gt;&lt;</span><span class="html">integer</span><span class="kwrd">&gt;</span>1<span class="kwrd">&lt;/</span><span class="html">integer</span><span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">key</span><span class="kwrd">&gt;</span>Disc Count<span class="kwrd">&lt;/</span><span class="html">key</span><span class="kwrd">&gt;&lt;</span><span class="html">integer</span><span class="kwrd">&gt;</span>1<span class="kwrd">&lt;/</span><span class="html">integer</span><span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">key</span><span class="kwrd">&gt;</span>Track Number<span class="kwrd">&lt;/</span><span class="html">key</span><span class="kwrd">&gt;&lt;</span><span class="html">integer</span><span class="kwrd">&gt;</span>1<span class="kwrd">&lt;/</span><span class="html">integer</span><span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">key</span><span class="kwrd">&gt;</span>Track Count<span class="kwrd">&lt;/</span><span class="html">key</span><span class="kwrd">&gt;&lt;</span><span class="html">integer</span><span class="kwrd">&gt;</span>10<span class="kwrd">&lt;/</span><span class="html">integer</span><span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">key</span><span class="kwrd">&gt;</span>Year<span class="kwrd">&lt;/</span><span class="html">key</span><span class="kwrd">&gt;&lt;</span><span class="html">integer</span><span class="kwrd">&gt;</span>1990<span class="kwrd">&lt;/</span><span class="html">integer</span><span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">key</span><span class="kwrd">&gt;</span>Date Modified<span class="kwrd">&lt;/</span><span class="html">key</span><span class="kwrd">&gt;&lt;</span><span class="html">date</span><span class="kwrd">&gt;</span>2005-06-06T04:11:43Z<span class="kwrd">&lt;/</span><span class="html">date</span><span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">key</span><span class="kwrd">&gt;</span>Date Added<span class="kwrd">&lt;/</span><span class="html">key</span><span class="kwrd">&gt;&lt;</span><span class="html">date</span><span class="kwrd">&gt;</span>2005-06-06T04:11:18Z<span class="kwrd">&lt;/</span><span class="html">date</span><span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">key</span><span class="kwrd">&gt;</span>Bit Rate<span class="kwrd">&lt;/</span><span class="html">key</span><span class="kwrd">&gt;&lt;</span><span class="html">integer</span><span class="kwrd">&gt;</span>128<span class="kwrd">&lt;/</span><span class="html">integer</span><span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">key</span><span class="kwrd">&gt;</span>Sample Rate<span class="kwrd">&lt;/</span><span class="html">key</span><span class="kwrd">&gt;&lt;</span><span class="html">integer</span><span class="kwrd">&gt;</span>44100<span class="kwrd">&lt;/</span><span class="html">integer</span><span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">key</span><span class="kwrd">&gt;</span>Track Type<span class="kwrd">&lt;/</span><span class="html">key</span><span class="kwrd">&gt;&lt;</span><span class="html">string</span><span class="kwrd">&gt;</span>File<span class="kwrd">&lt;/</span><span class="html">string</span><span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">key</span><span class="kwrd">&gt;</span>Location<span class="kwrd">&lt;/</span><span class="html">key</span><span class="kwrd">&gt;&lt;</span><span class="html">string</span><span class="kwrd">&gt;</span>file://localhost/C:/Documents%20and%20Settings/User1/<span class="kwrd"></span><br>                <span class="kwrd"></span>My%20Documents/My%20Music/iTunes/iTunes%20Music/Jan%20Garbarek/I%20Took%20Up<span class="kwrd"></span><br><span class="kwrd"></span><span class="kwrd"></span><span class="kwrd"></span>                <span class="kwrd"></span>%20The%20Runes/01%20Gula%20Gula.m4a/<span class="kwrd">&lt;/</span><span class="html">string</span><span class="kwrd">&gt;</span><span class="html"></span><span class="kwrd"></span><span class="html"></span><span class="kwrd"></span><span class="kwrd"></span><span class="html"></span><span class="kwrd"></span><br>            <span class="kwrd"></span><span class="kwrd">&lt;</span><span class="html">key</span><span class="kwrd">&gt;</span>File Folder Count<span class="kwrd">&lt;/</span><span class="html">key</span><span class="kwrd">&gt;&lt;</span><span class="html">integer</span><span class="kwrd">&gt;</span>4<span class="kwrd">&lt;/</span><span class="html">integer</span><span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">key</span><span class="kwrd">&gt;</span>Library Folder Count<span class="kwrd">&lt;/</span><span class="html">key</span><span class="kwrd">&gt;&lt;</span><span class="html">integer</span><span class="kwrd">&gt;</span>1<span class="kwrd">&lt;/</span><span class="html">integer</span><span class="kwrd">&gt;</span><br>        <span class="kwrd">&lt;/</span><span class="html">dict</span><span class="kwrd">&gt;</span><br>. . . <br><span class="kwrd">&lt;/</span><span class="html">dict</span><span class="kwrd">&gt;</span> <br></pre>
<style type="text/css">
<!--
.csharpcode
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{margin:0em;
	width:100%;
	background-color:#f4f4f4}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>Even old hands with XML may find this a peculiar structure. Rather than employing a traditional hierarchical tree structure, the key/value pairs represent something more akin to a serialized dictionary object. The key/value pairs are composed so that the
 first element is the key and the next is the value. To transform this data into a structure that the ASP.NET controls can use, I added an XSLT File to the Web site project and named the file
<i>iTunes.xsl</i>. I had a number of choices in how to execute the transformation – for example, deciding which of the various properties of each song I wanted to use – but the basic approach you need in any case is that the properties of interest much appear
 in the transformed XML structure as attributes. In terms of limiting the data I wanted to display, I choose to use only three properties of each song: the name of the song, the artist, and the album.
</p>
<p>The XSL for performing the transformation required that I create a new node named
<i>track </i>for each song, and add an attribute named <i>value </i>that stores the name of the song. The transformation then creates two child-nodes for each
<i>track </i>node called <i>artist </i>and <i>album</i>, respectively. Again, to represent the data associated with each of these items, I used an attribute named
<i>value</i>. </p>
<pre><code></code></pre>
<pre class="csharpcode"><span class="kwrd">&lt;?</span><span class="html">xml</span> <span class="attr">version</span><span class="kwrd">=&quot;1.0&quot;</span> <span class="attr">encoding</span><span class="kwrd">=&quot;utf-8&quot;</span>?<span class="kwrd">&gt;</span><br><span class="kwrd">&lt;</span><span class="html">xsl:stylesheet</span> <span class="attr">version</span><span class="kwrd">=&quot;1.0&quot;</span><br>    <span class="attr">xmlns:xsl</span><span class="kwrd">=&quot;http://www.w3.org/1999/XSL/Transform&quot;</span><span class="kwrd">&gt;</span><br><span class="kwrd">&lt;</span><span class="html">xsl:output</span> <span class="attr">method</span><span class="kwrd">=&quot;xml&quot;</span> <br>  <span class="attr">version</span><span class="kwrd">=&quot;1.0&quot;</span><br>  <span class="attr">encoding</span><span class="kwrd">=&quot;iso-8859-1&quot;</span> <br>  <span class="attr">indent</span><span class="kwrd">=&quot;yes&quot;</span> <span class="kwrd">/&gt;</span><br><br>  <span class="kwrd">&lt;</span><span class="html">xsl:template</span> <span class="attr">match</span><span class="kwrd">=&quot;/&quot;</span><span class="kwrd">&gt;</span><br>    <span class="kwrd">&lt;</span><span class="html">xsl:element</span> <span class="attr">name</span><span class="kwrd">=&quot;library&quot;</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">xsl:attribute</span> <span class="attr">name</span><span class="kwrd">=&quot;value&quot;</span><span class="kwrd">&gt;</span><br>        <span class="kwrd">&lt;</span><span class="html">xsl:value-of</span> <span class="attr">select</span><span class="kwrd">=&quot;'My iTunes Library'&quot;</span> <span class="kwrd">/&gt;</span><br>      <span class="kwrd">&lt;/</span><span class="html">xsl:attribute</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">xsl:apply-templates</span> <span class="attr">select</span><span class="kwrd">=&quot;plist/dict/dict/dict&quot;</span><span class="kwrd">/&gt;</span><br>    <span class="kwrd">&lt;/</span><span class="html">xsl:element</span><span class="kwrd">&gt;</span><br>  <span class="kwrd">&lt;/</span><span class="html">xsl:template</span><span class="kwrd">&gt;</span><br><br>  <span class="kwrd">&lt;</span><span class="html">xsl:template</span> <span class="attr">match</span><span class="kwrd">=&quot;plist/dict/dict/dict&quot;</span><span class="kwrd">&gt;</span><br>    <span class="kwrd">&lt;</span><span class="html">xsl:element</span> <span class="attr">name</span><span class="kwrd">=&quot;track&quot;</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">xsl:attribute</span> <span class="attr">name</span><span class="kwrd">=&quot;value&quot;</span><span class="kwrd">&gt;</span><br>        <span class="kwrd">&lt;</span><span class="html">xsl:value-of</span> <span class="attr">select</span><span class="kwrd">=&quot;key[.='Name']/following-sibling::node()[1]&quot;</span><span class="kwrd">/&gt;</span><br>      <span class="kwrd">&lt;/</span><span class="html">xsl:attribute</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">xsl:call-template</span> <span class="attr">name</span><span class="kwrd">=&quot;artist&quot;</span> <span class="kwrd">/&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">xsl:call-template</span> <span class="attr">name</span><span class="kwrd">=&quot;album&quot;</span> <span class="kwrd">/&gt;</span><br>    <span class="kwrd">&lt;/</span><span class="html">xsl:element</span><span class="kwrd">&gt;</span><br>  <span class="kwrd">&lt;/</span><span class="html">xsl:template</span><span class="kwrd">&gt;</span><br><br>  <span class="kwrd">&lt;</span><span class="html">xsl:template</span> <span class="attr">name</span><span class="kwrd">=&quot;artist&quot;</span><span class="kwrd">&gt;</span><br>    <span class="kwrd">&lt;</span><span class="html">xsl:element</span> <span class="attr">name</span><span class="kwrd">=&quot;artist&quot;</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">xsl:attribute</span> <span class="attr">name</span><span class="kwrd">=&quot;value&quot;</span><span class="kwrd">&gt;</span><br>        <span class="kwrd">&lt;</span><span class="html">xsl:value-of</span> <span class="attr">select</span><span class="kwrd">=&quot;key[.='Artist']/following-sibling::node()[1]&quot;</span><span class="kwrd">/&gt;</span><br>      <span class="kwrd">&lt;/</span><span class="html">xsl:attribute</span><span class="kwrd">&gt;</span><br>    <span class="kwrd">&lt;/</span><span class="html">xsl:element</span><span class="kwrd">&gt;</span><br>  <span class="kwrd">&lt;/</span><span class="html">xsl:template</span><span class="kwrd">&gt;</span><br><br>  <span class="kwrd">&lt;</span><span class="html">xsl:template</span> <span class="attr">name</span><span class="kwrd">=&quot;album&quot;</span><span class="kwrd">&gt;</span><br>    <span class="kwrd">&lt;</span><span class="html">xsl:element</span> <span class="attr">name</span><span class="kwrd">=&quot;album&quot;</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">xsl:attribute</span> <span class="attr">name</span><span class="kwrd">=&quot;value&quot;</span><span class="kwrd">&gt;</span><br>        <span class="kwrd">&lt;</span><span class="html">xsl:value-of</span> <span class="attr">select</span><span class="kwrd">=&quot;key[.='Album']/following-sibling::node()[1]&quot;</span><span class="kwrd">/&gt;</span><br>      <span class="kwrd">&lt;/</span><span class="html">xsl:attribute</span><span class="kwrd">&gt;</span><br>    <span class="kwrd">&lt;/</span><span class="html">xsl:element</span><span class="kwrd">&gt;</span><br>  <span class="kwrd">&lt;/</span><span class="html">xsl:template</span><span class="kwrd">&gt;</span><br>  <br><span class="kwrd">&lt;/</span><span class="html">xsl:stylesheet</span><span class="kwrd">&gt;</span> </pre>
<style type="text/css">
<!--
.csharpcode
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{margin:0em;
	width:100%;
	background-color:#f4f4f4}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>The intricacies of XSL and XPath are beyond the scope of this article (if you want to learn more about these topics, a good place to start is
<a href="http://www.w3schools.com/default.asp">http://www.w3schools.com/default.asp</a>).
</p>
<p>Returning to the <b>Configure Data Source </b>dialog box for the <b>XmlDataSource
</b>control, I set the <b>TransformFile </b>property to the XSL stylesheet. As shown below, the updated schema improved the data displayed in the
<b>TreeView </b>control, but I still had some work to do in order to get the correct data.
</p>
<p><img src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/913191/ituneslib_6.png" width="485" border="0">
</p>
<p>Next, I opened the <b>TreeView DataBindings Editor</b> using the Smart Tag menu for the
<b>TreeView </b>control. I added each of the nodes in the available data bindings list and then set the
<b>TextField </b>property of each of the bindings to display the <i>value </i>XML attribute created during the XSL transformation.
</p>
<p><img src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/913191/ituneslib_7.png" width="485" border="0">
</p>
<p>After closing the <b>TreeView DataBindings Editor, </b>I returned to the Smart Tag menu for the
<b>TreeView </b>control. I selected the <b>Auto Format </b>menu item and used the Auto Format dialog box to choose a more stylish scheme for my list.
</p>
<p><b><img alt="" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/913191/ituneslib_8.png" border="0"></b>
</p>
<p>As a final touch, I used the old-fashioned <b>Properties </b>window to change the
<b>ExpandDepth </b>property of the <b>TreeView </b>control so it only showed songs beneath the main library node.
</p>
<p><img src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/913191/ituneslib_9.png" width="485" border="0">
</p>
<p>This example has only scratched the surface of what you can do with your iTunes music data and ASP.NET 2.0. In fact, with this nudge I'm hopeful you may be inspired to find even more creative ways to show off your great taste in music to the rest of world.
 Consider, for example, using this example to build on Bill Evjen's fine article on how to extend the Personal Web Site Starter Kit (<a href="http://msdn.microsoft.com/coding4fun/webcoder/extendpws/default.aspx">http://msdn.microsoft.com/coding4fun/webcoder/extendpws/default.aspx</a>).
</p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/c4f.Peter-Bernhardt/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:25b47a787ecd41eb8c2b9e7600dabf65">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/articles/Displaying-Your-iTunes-Library</comments>
      <itunes:summary>



&amp;nbsp;
iTunes allows to play and organize music collection, as well as buy individual songs from their online store. All the information stored using iTunes is stored as XML; that allows to display music library in different
 formats. In this article some of the new ASP.NET controls available in Visual Web Developer 2005 Express are used to display iTunes library on a Web page.



Peter Bernhardt


Difficulty: Intermediate
Time Required: 
1-3 hours
Cost: Free
Software: Visual Studio Express Editions,
Apple iTunes
Hardware: 
Download: Download
&amp;nbsp;









You probably already know about Apple&#39;s iTunes application and that it allows you to play and organize your music collection, as well as buy individual songs from their online store. What you probably don&#39;t know is that all the information you store using
 iTunes is stored as XML; that allows you to display your music library in different formats. Like a web page, for example.
 

 
So, to give you a flavor for how you might use the iTunes data in your own applications, in this article I&#39;ll use some of the new ASP.NET controls available in Visual Web Developer 2005 Express to display my iTunes library on a Web page.
 
If you want to use your own library and you don&#39;t already have iTunes installed, visit
http://www.apple.com/itunes to download the free iTunes application. Using my own library, I began by creating a new ASP.NET Web site. Next, I used the
Web Site | Add Existing Item menu command to add my iTunes music library file.
 

 
As pictured above, the default iTunes directory is located in the My Music 
folder. The XML file is named iTunes Music Library.xml. After adding the file to my Web site project, I changed the name to something simpler:
iTunes.xml.  
ASP.NET 2.0 introduces a new XmlDataSource control that is a special type of data source control for consuming XML data. In Visual Web Developer 2005 Express, you&#39;ll find this control located in the
Data section of the Toolbox. After dragging an XmlD</itunes:summary>
      <link>http://channel9.msdn.com/coding4fun/articles/Displaying-Your-iTunes-Library</link>
      <pubDate>Tue, 31 Oct 2006 15:33:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/articles/Displaying-Your-iTunes-Library</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/913191_100.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/913191_220.jpg" height="165" width="220"></media:thumbnail>      
      <dc:creator>Peter Bernhardt</dc:creator>
      <itunes:author>Peter Bernhardt</itunes:author>
      <slash:comments>3</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/coding4fun/articles/Displaying-Your-iTunes-Library/RSS</wfw:commentRss>
    </item>
  <item>
      <title>A Simple RSS Feed</title>
      <description><![CDATA[<span id="c4fmetadata">
<table class="" cellspacing="0" cellpadding="1" width="100%" border="0">
<tbody>
<tr class="entry_overview">
<td class="" width="50">&nbsp;</td>
<td class=""><span class="entry_description">The article describes a control that fetches an RSS feed from a site of interest and organizes that content for display on a web page.</span></td>
</tr>
<tr>
<td class="" colspan="2">
<div class="entry_author">Peter Bernhardt</div>
<div class="entry_company&lt;/DIV"><br>
<div class="entry_details"><b>Difficulty: </b><span class="entry_details_input">Easy</span></div>
<div class="entry_details"><b>Time Required:</b> <span class="entry_details_input">
1-3 hours</span></div>
<div class="entry_details"><b>Cost: </b><span class="entry_details_input">Free</span></div>
<div class="entry_details"><b>Software: </b><span class="entry_details_input"><a href="http://msdn.com/express/">Visual Studio Express Editions</a></span></div>
<div class="entry_details"><b>Hardware: </b><span class="entry_details_input"></span></div>
<div class="entry_details"><b>Download: </b>
<ul>
<li><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/912335/SimpleRSSCS.msi">C# Download</a>
</li><li><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/912335/SimpleRSSVB.msi">VB Download</a></li></ul>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</span>
<p>Quite a few years ago, I came to the practical conclusion that I don't know everything there is to know about the world. Sure, it's presumptuous to even start from a place that requires such a conclusion. But such arrogance is a failing of youth, and I know
 better now. In fact, this reality is only magnified in the Internet age, as I find it virtually impossible to keep up-to-date with the non-stop flow of information, ideas, and opinions available on the web. Even within my modest scope of interests, I have
 a hard time staying current with the latest developments in Visual Basic, Visual C# and the .NET Framework.
</p>
<p>So, over the course of my next few entries I'm going to explore different approaches to using something with which you're likely already familiar: RSS (a/k/a Really Simple Syndication) —a technology that greatly eases the burden of grappling with information
 overload. </p>
<p>As a quick primer, Wikpedia describes RSS as &quot;short descriptions of web content together with links to the full versions of the content. This information is delivered as an XML file called an RSS feed, webfeed, RSS stream, or RSS channel. In addition to
 facilitating syndication, RSS allows a website's frequent readers to track updates on the site using a news aggregator.&quot; (For the full entry, see
<a href="http://en.wikipedia.org/wiki/RSS">RSS on Wikpedia</a>). </p>
<p>To get started, we'll look at a simple RSS feed reader you can build using Visual Web Developer 2005 Express Edition. I'm going to build a control that fetches an RSS feed from a site of interest and organizes that content for display on a web page. Of course,
 you could also build an RSS feed reader as a Windows application, or take advantage of any one of a number of free RSS client applications available (e.g.,
<a href="http://www.rssreader.com/">RSS Reader</a> or <a href="http://www.sharpreader.net/">
SharpReader</a>) if your aim is to aggregate content for your own personal consumption. Using syndicated content in a Web application has a different purpose, however, as it allows you to extend the content you create yourself and enrich the user experience
 of visitors to your site. </p>
<p>Before getting into the code, let's first take a look at a snippet of a typical RSS 2.0 file. In this example, the syndication provider is Microsoft's MSDN Web site, and I'm using the feed devoted to Visual Basic content.
</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">rss</span><br>  <span class="attr">xmlns:msdn</span><span class="kwrd">=&quot;http://msdn.microsoft.com/aboutmsdn/rss/&quot;</span><br>  <span class="attr">xmlns:dc</span><span class="kwrd">=&quot;http://purl.org/dc/elements/1.1/&quot;</span><br>  <span class="attr">xmlns:msdndomain</span><span class="kwrd">=&quot;http://msdn.microsoft.com/aboutmsdn/rss/domains&quot;</span><br>  <span class="attr">version</span><span class="kwrd">=&quot;2.0&quot;</span><span class="kwrd">&gt;</span><br>  <span class="kwrd">&lt;</span><span class="html">channel</span><span class="kwrd">&gt;</span><br>    <span class="kwrd">&lt;</span><span class="html">title</span><span class="kwrd">&gt;</span>MSDN: Visual Basic<span class="kwrd">&lt;/</span><span class="html">title</span><span class="kwrd">&gt;</span><br>    <span class="kwrd">&lt;</span><span class="html">link</span><span class="kwrd">&gt;</span>http://msdn.microsoft.com/vbasic/<span class="kwrd">&lt;/</span><span class="html">link</span><span class="kwrd">&gt;</span><br>    <span class="kwrd">&lt;</span><span class="html">description</span><span class="kwrd">&gt;</span>Recently Published Visual Basic Content<span class="kwrd">&lt;/</span><span class="html">description</span><span class="kwrd">&gt;</span><br>    <span class="kwrd">&lt;</span><span class="html">language</span><span class="kwrd">&gt;</span>en-us<span class="kwrd">&lt;/</span><span class="html">language</span><span class="kwrd">&gt;</span><br>    <span class="kwrd">&lt;</span><span class="html">pubDate</span><span class="kwrd">&gt;</span>Thu, 30 Jun 2005 13:01:02 GMT<span class="kwrd">&lt;/</span><span class="html">pubDate</span><span class="kwrd">&gt;</span><br>    <span class="kwrd">&lt;</span><span class="html">lastBuildDate</span><span class="kwrd">&gt;</span>Thu, 30 Jun 2005 13:01:02 GMT<span class="kwrd">&lt;/</span><span class="html">lastBuildDate</span><span class="kwrd">&gt;</span><br>    <span class="kwrd">&lt;</span><span class="html">generator</span><span class="kwrd">&gt;</span>MSDN RSS Service 1.1.0.0<span class="kwrd">&lt;/</span><span class="html">generator</span><span class="kwrd">&gt;</span><br>    <span class="kwrd">&lt;</span><span class="html">ttl</span><span class="kwrd">&gt;</span>1440<span class="kwrd">&lt;/</span><span class="html">ttl</span><span class="kwrd">&gt;</span><br>    <span class="kwrd">&lt;</span><span class="html">item</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">title</span><span class="kwrd">&gt;</span>June CTP of Visual Studio 2005 Available to MSDN Subscribers<span class="kwrd">&lt;/</span><span class="html">title</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">description</span><span class="kwrd">&gt;</span>The latest Community Technical Preview of Visual Studio 2005 is now <br>                   available for download to MSDN subscribers.<span class="kwrd">&lt;/</span><span class="html">description</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">link</span><span class="kwrd">&gt;</span>http://msdn.microsoft.com/subscriptions/<span class="kwrd">&lt;/</span><span class="html">link</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">category</span> <span class="attr">domain</span><span class="kwrd">=&quot;msdndomain:ContentType&quot;</span><span class="kwrd">&gt;</span>Announcement<span class="kwrd">&lt;/</span><span class="html">category</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">category</span> <span class="attr">domain</span><span class="kwrd">=&quot;msdndomain:Subject&quot;</span><span class="kwrd">&gt;</span>.NET development<span class="kwrd">&lt;/</span><span class="html">category</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">msdn:headlineImage</span><span class="kwrd">&gt;</span><br>        http://msdn.microsoft.com/msdn-online/shared/graphics/icons/article.gif<br>      <span class="kwrd">&lt;/</span><span class="html">msdn:headlineImage</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">msdn:contentType</span><span class="kwrd">&gt;</span>Announcement<span class="kwrd">&lt;/</span><span class="html">msdn:contentType</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">msdn:simpleDate</span><span class="kwrd">&gt;</span>Jun 27<span class="kwrd">&lt;/</span><span class="html">msdn:simpleDate</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">guid</span> <span class="attr">isPermaLink</span><span class="kwrd">=&quot;false&quot;</span><span class="kwrd">&gt;</span>Titan_1106<span class="kwrd">&lt;/</span><span class="html">guid</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">pubDate</span><span class="kwrd">&gt;</span>Tue, 28 Jun 2005 02:00:13 GMT<span class="kwrd">&lt;/</span><span class="html">pubDate</span><span class="kwrd">&gt;</span><br>    <span class="kwrd">&lt;/</span><span class="html">item</span><span class="kwrd">&gt;</span><br>    <span class="rem">&lt;!-- more items follow --&gt;</span><br>  <span class="kwrd">&lt;/</span><span class="html">channel</span><span class="kwrd">&gt;</span><br><span class="kwrd">&lt;/</span><span class="html">rss</span><span class="kwrd">&gt;</span> </pre>
<p>A typical feed file is loaded with information, some of which is not included uniformly by all syndication providers (MSDN's headline image, for example, is not standard). At the top of the XML structure is a single
<code>&lt;channel&gt; </code>node that includes a title and description you can use to introduce the list of content items. The
<code>&lt;channel&gt; </code>node contains many child <code>&lt;item&gt; </code>nodes representing each article of content (including the title of the article, a description, publication date and the link to the full article).
</p>
<p>After creating a new Web Site in Visual Web Developer 2005 Express Edition, I added a
<b>Web User Control</b> that I'll use to display this information. </p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/912335/SimpleRSS_1.gif"><img alt="Click here for larger image" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/912335/SimpleRSS_1_thumb.gif" border="0"></a>
</p>
<p><b>(click image to zoom)</b> </p>
<p>One of the features of ASP.NET 2.0 is that it supports both the code-behind model familiar to Visual Studio 2003 developers, and (something new) in-line code which allows you to write all your code within
<code>&lt;script&gt;</code> tags in the .aspx or .ascx files. While using the in-line code approach doesn't make any difference in how the ASP.NET pages perform, I prefer the code-behind model and will use it throughout this example. You'll also notice that I'm using
 Visual Basic to write the code for this application. </p>
<p>Working in the designer, I added a <b>Repeater </b>control to the control. The
<b>Repeater </b>is a data-bound control for displaying data using a custom layout. This is ideal for showing a list of content items from an RSS feed. As shown below, you can use the smart tag menu associated with the control to set the data source for the
 control at design. However, for this application I'll be setting the data source at runtime using the RSS feed.
</p>
<p><a href="http://blogs.msdn.com/blogfiles/coding4fun/xml/SimpleRSS/SimpleRSS_2.gif"><img alt="Click here for larger image" src="http://blogs.msdn.com/blogfiles/coding4fun/xml/SimpleRSS/SimpleRSS_2_thumb.gif" border="0"></a>
</p>
<p><b>(click image to zoom)</b> </p>
<p>Switching to the code-behind file for the .ascx file (RSSList.ascx.vb), I added
<code>Imports</code><b> </b>statements for the namespaces containing the classes necessary to acquire the RSS feed and store it to a local resource that will bind to the
<b>Repeater</b>. </p>
<p><b>Visual C#</b> </p>
<pre><code></code></pre>
<pre class="csharpcode"><span class="kwrd">using</span> System.Data;<br><span class="kwrd">using</span> System.Net;</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p><b>Visual Basic</b> </p>
<pre><code></code></pre>
<pre class="csharpcode"><span class="kwrd">Imports</span> System.Net<br><span class="kwrd">Imports</span> System.Data</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>In addition to using the event handler for the control's <b>Page Load </b>event, I also added a private helper function called
<b>RefreshFeed</b>. This gets the RSS data and returns it as a <b>DataSet</b> to the
<b>Page Load </b>event handler. In the <b>RefreshFeed </b>function, the first line of code creates an instance of an
<b>HttpWebRequest </b>object using the shared <b>Create </b>function of the <b>WebRequest
</b>class. </p>
<p><b>Visual C#</b> </p>
<pre><code></code></pre>
<pre class="csharpcode">HttpWebRequest rssFeed = (HttpWebRequest)WebRequest.Create(<br>    <span class="str">&quot;http://msdn.microsoft.com/vbasic/rss.xml&quot;</span>);</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p><b>Visual Basic</b> </p>
<pre><code></code></pre>
<pre class="csharpcode"><span class="kwrd">Dim</span> rssFeed <span class="kwrd">As</span> HttpWebRequest =_ <br><span class="kwrd">DirectCast</span>(WebRequest.Create(<span class="str">&quot;http://msdn.microsoft.com/vbasic/rss.xml&quot;</span>),_<br>           HttpWebRequest)</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>As an input argument to the <b>Create </b>function, the code passes the target URL of the RSS feed. The function returns an
<b>HttpWebRequest </b>object, which is a special type of <b>WebRequest </b>object that supports additional properties and methods for interacting with servers using HTTP. In this case, my needs are very simple for
<b>HttpWebRequest</b>; the code first gets the response from the server (<b>GetResponse</b>) and then, because the response is in XML format, the response stream (<b>GetResponseStream</b>) can be loaded directly into a
<b>DataSet </b>using the <b>ReadXml </b>method overload that accepts a <b>Stream </b>
as an input argument. </p>
<p><b>Visual C#</b> </p>
<pre><code></code></pre>
<pre class="csharpcode">DataSet rssData = <span class="kwrd">new</span> DataSet();<br>rssData.ReadXml(rssFeed.GetResponse().GetResponseStream());</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p><b>Visual Basic</b> </p>
<pre><code></code></pre>
<pre class="csharpcode"><span class="kwrd">Dim</span> rssData <span class="kwrd">As</span> DataSet = <span class="kwrd">New</span> DataSet()<br>rssData.ReadXml(rssFeed.GetResponse().GetResponseStream())</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>The <b>ReadXml </b>method automatically infers the schema for the XML data. That means the
<code>&lt;channel&gt; </code>and <code>&lt;items&gt; </code>nodes of the source XML data are represented in the
<b>DataSet </b>as separate <b>DataTable</b>s<b>. </b>In the <b>Page Load </b>event handler, after calling the
<b>RefereshFeed </b>method to return a <b>DataSet </b>containing the RSS feed data, the code access the channel and items data in different ways. The second
<b>DataTable </b>in the <b>DataSet </b>contains the channel information. To display the feed title and description, the code copies the first and only row from the
<b>DataTable</b> into an <b>Object </b>array using the <b>ItemArray </b>property of the
<b>Row</b>. Then, because I want to be sure I locate the correct data column, the code assigns the ordinal position of the title and description columns, respectively, to local variables of type
<b>Integer</b>. Using these values, the code calls the <b>GetValue </b>method of the
<b>Object </b>array to store the value associated with each column to the <b>Friend
</b>field defined for the class (I'll use these values in the <b>Repeater </b>control).
</p>
<p><b>Visual C#</b> </p>
<pre><code></code></pre>
<pre class="csharpcode"><span class="kwrd">object</span>[] channelItems = rssData.Tables[1].Rows[0].ItemArray;<br><span class="kwrd">int</span> titleColumn = rssData.Tables[1].Columns[<span class="str">&quot;title&quot;</span>].Ordinal;<br><span class="kwrd">int</span> descriptionColumn = rssData.Tables[1].Columns[<span class="str">&quot;description&quot;</span>].Ordinal;<br>Title = channelItems.GetValue(titleColumn).ToString();<br>Description = channelItems.GetValue(descriptionColumn).ToString();</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p><b>Visual Basic</b> </p>
<pre><code></code></pre>
<pre class="csharpcode"><span class="kwrd">Dim</span> channelItems <span class="kwrd">As</span> <span class="kwrd">Object</span>() = rssData.Tables(1).Rows(0).ItemArray<br><span class="kwrd">Dim</span> titleColumn <span class="kwrd">As</span> <span class="kwrd">Integer</span> = rssData.Tables(1).Columns(<span class="str">&quot;title&quot;</span>).Ordinal<br><span class="kwrd">Dim</span> descriptionColumn <span class="kwrd">As</span> <span class="kwrd">Integer</span> =<br>     rssData.Tables(1).Columns(<span class="str">&quot;description&quot;</span>).Ordinal<br>Title = channelItems.GetValue(titleColumn).ToString()<br>Description = channelItems.GetValue(descriptionColumn).ToString()</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>Next, the code sets the <b>DataSource </b>property of the <b>Repeater </b>control to the
<b>DataTable </b>in the <b>DataSet </b>holding the item content from the RSS feed. Finally, the code calls the
<b>DatBind </b>method of the <b>Repeater </b>to bind the data source to the control.
</p>
<p><b>Visual C#</b> </p>
<pre><code></code></pre>
<pre class="csharpcode">Repeater1.DataSource = rssData.Tables(2)<br>Repeater1.DataBind() </pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p><b>Visual Basic</b> </p>
<pre><code></code></pre>
<pre class="csharpcode">Repeater1.DataSource = rssData.Tables(2)<br>Repeater1.DataBind() </pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>In the source view of the <b>RssFeed.ascx </b>control, I added templates for the
<b>Repeater </b>control to display the data. In the <code>&lt;HeaderTemplate&gt;</code> the code begins a table with a header element that displays the channel title and description.</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">HeaderTemplate</span><span class="kwrd">&gt;</span><br>   <span class="kwrd">&lt;</span><span class="html">table</span> <span class="attr">border</span>=<span class="attr">0</span> <br>       <span class="attr">   style</span><span class="kwrd">=&quot;width: 240px; font-size: x-small; color: black; font-family: Verdana;&quot;</span><span class="kwrd">&gt;</span><span class="kwrd"></span><span class="kwrd"></span><br>       <span class="kwrd">&lt;</span><span class="html">thead</span><span class="kwrd">&gt;</span><br>           <span class="kwrd">&lt;</span><span class="html">tr</span> <span class="attr">style</span><span class="kwrd">=&quot;font-weight: bold;&quot;</span><span class="kwrd">&gt;</span><br>               <span class="kwrd">&lt;</span><span class="html">td</span><span class="kwrd">&gt;</span><span class="asp">&lt;%</span>#Me.Title<span class="asp">%&gt;</span><span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span><br>           <span class="kwrd">&lt;/</span><span class="html">tr</span><span class="kwrd">&gt;</span><br>           <span class="kwrd">&lt;</span><span class="html">tr</span> <span class="attr">style</span><span class="kwrd">=&quot;font-style: italic;&quot;</span><span class="kwrd">&gt;</span><br>               <span class="kwrd">&lt;</span><span class="html">td</span><span class="kwrd">&gt;</span><span class="asp">&lt;%</span>#Me.Description<span class="asp">%&gt;</span><span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span><br>           <span class="kwrd">&lt;/</span><span class="html">tr</span><span class="kwrd">&gt;</span><br>       <span class="kwrd">&lt;/</span><span class="html">thead</span><span class="kwrd">&gt;</span><br><span class="kwrd">&lt;/</span><span class="html">HeaderTemplate</span><span class="kwrd">&gt;</span> <br></pre>
<p>Similarly, in the <code>&lt;ItemTemplate&gt; </code>the code displays the title of a content item with its associated link, as well as the description of the item.</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">ItemTemplate</span><span class="kwrd">&gt;</span><br>   <span class="kwrd">&lt;</span><span class="html">tr</span> <span class="attr">bgcolor</span><span class="kwrd">=&quot;LightBlue&quot;</span><span class="kwrd">&gt;</span><br>       <span class="kwrd">&lt;</span><span class="html">td</span><span class="kwrd">&gt;</span><br>           <span class="kwrd">&lt;</span><span class="html">a</span> <span class="attr">target</span><span class="kwrd">=&quot;article&quot;</span> <span class="attr">style</span><span class="kwrd">=&quot;text-decoration: none; color: black;&quot;</span><br>            <span class="attr">href</span>=&amp;<span class="attr">amp</span>;<span class="attr">lt</span>;%# <span class="attr">DataBinder</span>.<span class="attr">Eval</span>(<span class="attr">Container</span>.<span class="attr">DataItem</span>, <span class="kwrd">&quot;link&quot;</span>) %&amp;<span class="attr">amp</span>;<span class="attr">gt</span>;<span class="kwrd">&gt;</span><span class="kwrd"></span><br>            <span class="asp">&lt;%</span># DataBinder.Eval(Container.DataItem, <span class="str">&quot;title&quot;</span>) <span class="asp">%&gt;</span> <span class="kwrd">&lt;/</span><span class="html">a</span><span class="kwrd">&gt;</span><br>        <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span><br>    <span class="kwrd">&lt;/</span><span class="html">tr</span><span class="kwrd">&gt;</span><br>    <span class="kwrd">&lt;</span><span class="html">tr</span> <span class="attr">bgcolor</span><span class="kwrd">=&quot;Ivory&quot;</span><span class="kwrd">&gt;</span><br>        <span class="kwrd">&lt;</span><span class="html">td</span> <span class="attr">style</span><span class="kwrd">=&quot;color: CornFlowerBlue;&quot;</span><span class="kwrd">&gt;</span><br>           <span class="asp">&lt;%</span># DataBinder.Eval(Container.DataItem, <span class="str">&quot;description&quot;</span>) <span class="asp">%&gt;</span><br>        <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span><br>   <span class="kwrd">&lt;/</span><span class="html">tr</span><span class="kwrd">&gt;</span><br><span class="kwrd">&lt;/</span><span class="html">ItemTemplate</span><span class="kwrd">&gt;</span></pre>
<p>&nbsp;</p>
<pre><code></code></pre>
<p>As a final and very necessary step, I added an <b>OutputCache </b>directive to at the top of the .ascx page to cache the output of the control for one hour.</p>
<pre class="csharpcode"><span class="asp">&lt;%@ OutputCache Duration=&quot;3600&quot; VaryByParam=&quot;None&quot; %&gt;</span><br></pre>
This will prevent executing the <b>RefreshFeed </b>function every time a user access a page containing the control. If I didn't do this, and my site got heavy use, this would result in a lot of traffic between my Web server and the syndication provider. If
 you run the application, the syndicated content displays as shown below.
<p><a href="http://blogs.msdn.com/blogfiles/coding4fun/xml/SimpleRSS/SimpleRSS_3.gif"><img title="Click here for larger image" alt="Click here for larger image" src="http://blogs.msdn.com/blogfiles/coding4fun/xml/SimpleRSS/SimpleRSS_3_thumb.gif" border="0"></a>
</p>
<p><b>(click image to zoom)</b> </p>
<p>In future articles I'll dig deeper into the possibilities for using syndicated RSS feeds in a Web application. Until then, I encourage you to download the code and try it out for yourself.</p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/c4f.Peter-Bernhardt/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:4e3ef3a2bd284201ad4a9e7600db5bde">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/articles/A-Simple-RSS-Feed</comments>
      <itunes:summary>



&amp;nbsp;
The article describes a control that fetches an RSS feed from a site of interest and organizes that content for display on a web page.



Peter Bernhardt

Difficulty: Easy
Time Required: 
1-3 hours
Cost: Free
Software: Visual Studio Express Editions
Hardware: 
Download: 

C# Download
VB Download







Quite a few years ago, I came to the practical conclusion that I don&#39;t know everything there is to know about the world. Sure, it&#39;s presumptuous to even start from a place that requires such a conclusion. But such arrogance is a failing of youth, and I know
 better now. In fact, this reality is only magnified in the Internet age, as I find it virtually impossible to keep up-to-date with the non-stop flow of information, ideas, and opinions available on the web. Even within my modest scope of interests, I have
 a hard time staying current with the latest developments in Visual Basic, Visual C# and the .NET Framework.
 
So, over the course of my next few entries I&#39;m going to explore different approaches to using something with which you&#39;re likely already familiar: RSS (a/k/a Really Simple Syndication) —a technology that greatly eases the burden of grappling with information
 overload.  
As a quick primer, Wikpedia describes RSS as &amp;quot;short descriptions of web content together with links to the full versions of the content. This information is delivered as an XML file called an RSS feed, webfeed, RSS stream, or RSS channel. In addition to
 facilitating syndication, RSS allows a website&#39;s frequent readers to track updates on the site using a news aggregator.&amp;quot; (For the full entry, see
RSS on Wikpedia).  
To get started, we&#39;ll look at a simple RSS feed reader you can build using Visual Web Developer 2005 Express Edition. I&#39;m going to build a control that fetches an RSS feed from a site of interest and organizes that content for display on a web page. Of course,
 you could also build an RSS feed reader as a Windows application, or take advantage of any one</itunes:summary>
      <link>http://channel9.msdn.com/coding4fun/articles/A-Simple-RSS-Feed</link>
      <pubDate>Tue, 31 Oct 2006 14:30:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/articles/A-Simple-RSS-Feed</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/912335_100.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/912335_220.jpg" height="165" width="220"></media:thumbnail>      
      <dc:creator>Peter Bernhardt</dc:creator>
      <itunes:author>Peter Bernhardt</itunes:author>
      <slash:comments>24</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/coding4fun/articles/A-Simple-RSS-Feed/RSS</wfw:commentRss>
    </item>
  <item>
      <title>Using the Amazon Web Service</title>
      <description><![CDATA[<span id="c4fmetadata">
<table class="" cellspacing="0" cellpadding="1" width="100%" border="0">
<tbody>
<tr class="entry_overview">
<td class="" width="50">&nbsp;</td>
<td class=""><span class="entry_description">This article demonstrates consuming a Web service. It uses Amazon Web services to build an application that searches for books, music or movies based on keywords.</span></td>
</tr>
<tr>
<td class="" colspan="2">
<div class="entry_author">Peter Bernhardt</div>
<div class="entry_company"><a href="http://blogs.msdn.com/controlpanel/blogs/"></a></div>
<br>
<div class="entry_details"><b>Difficulty: </b><span class="entry_details_input">Easy</span></div>
<div class="entry_details"><b>Time Required:</b> <span class="entry_details_input">
1-3 hours</span></div>
<div class="entry_details"><b>Cost: </b><span class="entry_details_input">Free</span></div>
<div class="entry_details"><b>Software: </b><span class="entry_details_input"><a href="http://msdn.com/express/">Visual Studio Express Editions</a>,
<a href="http://www.amazon.com/gp/aws/registration/registration-form.html">Amazon SDK</a></span></div>
<div class="entry_details"><b>Hardware: </b><span class="entry_details_input"></span></div>
<div class="entry_details"><b>Download: </b>Lost!
<ul>
</ul>
</div>
</td>
</tr>
</tbody>
</table>
</span>For my inaugural post, I wanted to look at how client applications consume a Web service. I chose the Amazon Web services to build an application that searches for books, music or movies based on keywords.
<p><img height="433" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/912260/image001.jpg" width="450">
</p>
<p>While you can use the Amazon Web services for free, you first need to <a href="http://www.amazon.com/gp/aws/registration/registration-form.html/104-3123406-3472721?">
register with Amazon</a>. Once you've registered, Amazon will email you a subscription identification code to include in the requests you send to the Web service. I'll show you how that works once we get into the code for the application.
</p>
<p>Amazon recently released version 4.0 of its E-Commerce Web Services (ECS). Unfortunately, I discovered some problems using the ECS version, as documented
<a href="http://forums.prospero.com/n/mb/message.asp?webtag=am-assocdevxml&amp;msg=6777.1">
here</a>. So for this application, I used the previous 3.0 release of Amazon Web services.
</p>
<p>The 3.0 release includes a <a href="http://www.amazon.com/gp/redirect.html/ref=sc_fe_c_0_3434641_8/104-1553359-4486307?location=http://images.amazon.com/media/i3d/01/associates/kit.zip&amp;token=98EB5C03A885032DB6F41D8619E6CDE13E67B29C">
downloadable software development kit</a>. Before getting started on the application, I installed the SDK on my computer. The SDK provides all the information you need on using Amazon Web services to add content to Web sites, enable transactions, and upload
 products to Amazon.com. I don't need to add content to my Web site or use the more advanced features of the Amazon Web services. Not yet, anyway. I usually have modest objectives when I begin working with unfamiliar technology. A desktop application that uses
 one of the Web methods provided by the Amazon Web service is a good starting point. Once I get familiar with the Amazon Web services I can look forward to tackling more ambitious projects later on.
</p>
<p>For this example, we'll use one of the new Visual Studio 2005 Express Editions. The Express Editions of Visual Studio 2005 are simplified, streamlined and lightweight versions of Visual Studio tailored for hobbyist, novice, and student developers. Beta 2
 of the Express editions can be downloaded at <a href="http://msdn.microsoft.com/express">
http://msdn.microsoft.com/express</a>. Any of the Visual Studio 2005 Express Editions allow you to build applications which consume Web services; I'm using Visual C# 2005 Express Edition in this example.
</p>
<p>Prior versions of Visual Studio .NET made it very easy to incorporate a Web service in an application. Visual Studio 2005 is no different. The easiest and most direct method is to use the Add Web Reference dialog, accessible from either the Project menu
 or by right-clicking on the project in Solution Explorer. The Add Web Reference dialog lets you browse your local machine or external locations for available Web services. For the Amazon Web service, I copied in the path to the Web Services Description Language
 (WSDL) file from the “DTD, XSD and SOAP WSDL” page in the References section of the API Guide. A WSDL (pronounced “wiz-dull”) is an XML-based representation of all the information you need to use a particular Web service, including the locations (or endpoints)
 for sending messages, descriptions of the operations provided by the Web service and how they need to be formatted, and the types of data you can include in a message.
</p>
<p><img height="345" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/912260/image002.jpg" width="485" border="0">
</p>
<p>I then clicked the “Go” button and the wizard went off to find the WSDL file. After a second or two the wizard displayed a service description for the Amazon Web service. The wizard added a default Web reference name of&nbsp; “com.amazon.soap”. I changed that
 to something simpler, “Amazon”. When I clicked the Add Reference button, Visual C# Express automatically translated the WSDL file into a class (contained in the hidden project file Reference.cs). This class serves as a proxy for interacting with the Web service
 using managed types without having to bother with the gory details of SOAP or XML serialization or how to invoke a Web service. Visual C# Express also outfits the class with asynchronous versions of all the Web methods it discovers in the WSDL. All this behind-the-scenes
 work frees you to concentrate on the details of working with the methods and data exposed by the Web service to do interesting things in your application.
</p>
<p>To simplify my code, I added a using statement at the top of the Form1.cs file for the namespace containing the Amazon Web service proxy class.
</p>
<p><b>Visual C#</b> </p>
<pre><code></code></pre>
<pre class="csharpcode"><span class="kwrd">using</span> WSFun.Amazon;</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p><b>Visual Basic</b> </p>
<pre><code></code></pre>
<pre class="csharpcode"><span class="kwrd">Imports</span> WSFun.Amazon</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>To perform a keyword search of the Amazon product listing, you need to call the KeywordSearchRequest Web method. This method requires a KeywordRequest input parameter, so my first task was to create an instance of a KeywordRequest object and set its various
 properties. </p>
<p><b>Visual C#</b> </p>
<pre><code></code></pre>
<pre class="csharpcode">KeywordRequest keywordReq = <span class="kwrd">new</span> KeywordRequest();<br>keywordReq.locale = <span class="str">&quot;us&quot;</span>;<br>keywordReq.type = <span class="str">&quot;lite&quot;</span>;<br>keywordReq.sort = <span class="str">&quot;reviewrank&quot;</span>;<br>keywordReq.mode = <span class="kwrd">this</span>.SearchMode;<br>keywordReq.keyword = <span class="kwrd">this</span>.searchText.Text;<br>keywordReq.tag = <span class="kwrd">this</span>.SubscriberID;<br>keywordReq.devtag = <span class="kwrd">this</span>.SubscriberID;</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p><b>Visual Basic</b> </p>
<pre><code></code></pre>
<pre class="csharpcode"><span class="kwrd">Dim</span> keywordReq <span class="kwrd">As</span> KeywordRequest = <span class="kwrd">New</span> KeywordRequest()<br>keywordReq.locale = <span class="str">&quot;us&quot;</span><br>keywordReq.type = <span class="str">&quot;lite&quot;</span><br>keywordReq.sort = <span class="str">&quot;reviewrank&quot;</span><br>keywordReq.mode = <span class="kwrd">Me</span>.SearchMode<br>keywordReq.keyword = <span class="kwrd">Me</span>.searchText.Text<br>keywordReq.tag = <span class="kwrd">Me</span>.SubscriberID<br>keywordReq.devtag = <span class="kwrd">Me</span>.SubscriberID</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>I used hard values for the type and sort properties; I could have added user controls to the form to manipulate those values at runtime (for example, to sort the results alphabetically or by their sales rank rather than the hard-coded customer review rank).
 The mode and keyword properties are dynamic. The mode property controls which product line to search. Here, I use the value specified in the selected radio button on the form: either Books, Music or DVDs. I added a common handler for each of the radio button's
 CheckedChanged event to update the private member SearchMode to the appropriate string value used in the request.
</p>
<p><b>Visual C#</b> </p>
<pre><code></code></pre>
<pre class="csharpcode">keywordReq.tag = <span class="kwrd">this</span>.SubscriberID;<br>keywordReq.devtag = <span class="kwrd">this</span>.SubscriberID;</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p><b>Visual Basic</b> </p>
<pre><code></code></pre>
<pre class="csharpcode">keywordReq.tag = <span class="kwrd">Me</span>.SubscriberID<br>keywordReq.devtag = <span class="kwrd">Me</span>.SubscriberID</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>In the final lines of this block of code, I set the credentials for the request using the subscription identifier I obtained from Amazon. For version 3.0 of the Amazon Web services, you need to add this value to both the tag and devtag properties of the
 KeywordRequest. I accessed the subscription identifier using a private property. This makes the code more manageable. I stored the actual subscriber id in the application's configuration file; this allows me to change the id without having to recompile the
 application. If you download the code accompanying this article, be sure to update the app.config file to use the subscriber identification you obtain from Amazon.
</p>
<p>Next, I created an instance of the Web service proxy class and called the KeywordSearchRequest method, passing in the KeywordRequest object as an input parameter.
</p>
<p><b>Visual C#</b> </p>
<pre><code></code></pre>
<pre class="csharpcode">AmazonSearchService amazonWS = <span class="kwrd">new</span> AmazonSearchService();<br>ProductInfo productInfo = amazonWS.KeywordSearchRequest(keywordReq);</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p><b>Visual Basic</b> </p>
<pre><code></code></pre>
<pre class="csharpcode"><span class="kwrd">Dim</span> amazonWS <span class="kwrd">As</span> AmazonSearchService = <span class="kwrd">New</span> AmazonSearchService()<br><span class="kwrd">Dim</span> productInfo <span class="kwrd">As</span> ProductInfo = amazonWS.KeywordSearchRequest(keywordReq)</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>The KeywordSearchRequest returns a ProductInfo object, which includes a Details property. This property is actually an array of Details objects representing the items that matched my search criteria. After first checking to make sure the Details property
 contains items, I add the Details array to the Items collection of the Listbox control on the form.
</p>
<p><b>Visual C#</b> </p>
<pre><code></code></pre>
<pre class="csharpcode"><span class="kwrd">this</span>.searchResults.Items.AddRange(productInfo.Details);</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p><b>Visual Basic</b> </p>
<pre><code></code></pre>
<pre class="csharpcode"><span class="kwrd">Me</span>.searchResults.Items.AddRange(productInfo.Details)</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>In order to correctly display the name of the item returned in my search, I used the cool new partial class feature of Visual Studio 2005 to extend the Details class that Visual C# created when I imported the WSDL file. To do this, I first created a new
 class file for the project and named it Details_2.cs. I included the new partial keyword in the class declaration and then added an override for the ToString method. The ToString method is inherited by every class from the .NET Framework's base Object class
 and is used by the Listbox control for displaying a value for listed items. </p>
<p><b>Visual C#</b> </p>
<pre><code></code></pre>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">string</span> ToString()<br>{<br>     <span class="kwrd">return</span> ProductName;<br>}</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p><b>Visual Basic</b> </p>
<pre><code></code></pre>
<pre class="csharpcode"><span class="kwrd">Overrides</span> <span class="kwrd">Function</span> ToString() <span class="kwrd">As</span> <span class="kwrd">String</span><br>     <span class="kwrd">Return</span> ProductName<br><span class="kwrd">End</span> FunctionFunction</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>This override uses the ProductName property of the Details object. This lets me display the product information in the list box.
</p>
<p>I also added a new property to the partial class, called ItemImage. I used this property to return the image associated with a selected product item.
</p>
<p><b>Visual C#</b> </p>
<pre><code></code></pre>
<pre class="csharpcode">WebRequest webReq = WebRequest.Create(<span class="kwrd">this</span>.ImageUrlMedium);<br>WebResponse webResp = webReq.GetResponse();<br>_image = Image.FromStream(webResp.GetResponseStream());</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p><b>Visual Basic</b> </p>
<pre><code></code></pre>
<pre class="csharpcode"><span class="kwrd">Dim</span> webReq <span class="kwrd">As</span> WebRequest = WebRequest.Create(<span class="kwrd">Me</span>.ImageUrlMedium)<br><span class="kwrd">Dim</span> webResp <span class="kwrd">As</span> WebResponse = webReq.GetResponse()<br>_image = Image.FromStream(webResp.GetResponseStream())</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>The code in the property's get method uses a System.Net.WebRequest object to return the image specified in the ImageUrlMedium property of the Details object. In the handler for the ListBox's SelectedIndexChanged event, I access this property to update the
 image displayed on the form. </p>
<p><b>Visual C#</b> </p>
<pre><code></code></pre>
<pre class="csharpcode"><span class="kwrd">this</span>.itemPicture.Image = tempDetails.ItemImage;</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p><b>Visual Basic</b> </p>
<pre><code></code></pre>
<pre class="csharpcode"><span class="kwrd">Me</span>.itemPicture.Image = tempDetails.ItemImage</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>This completes the tour of this application.&nbsp;Download Visual C# 2005 Express Edition and explore this application for yourself. See http://msdn.microsoft.com/express.</p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/c4f.Peter-Bernhardt/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:a8951a68bc8c47798fd19e7600db7a58">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/articles/Using-the-Amazon-Web-Service</comments>
      <itunes:summary>



&amp;nbsp;
This article demonstrates consuming a Web service. It uses Amazon Web services to build an application that searches for books, music or movies based on keywords.



Peter Bernhardt


Difficulty: Easy
Time Required: 
1-3 hours
Cost: Free
Software: Visual Studio Express Editions,
Amazon SDK
Hardware: 
Download: Lost!







For my inaugural post, I wanted to look at how client applications consume a Web service. I chose the Amazon Web services to build an application that searches for books, music or movies based on keywords.

 
While you can use the Amazon Web services for free, you first need to 
register with Amazon. Once you&#39;ve registered, Amazon will email you a subscription identification code to include in the requests you send to the Web service. I&#39;ll show you how that works once we get into the code for the application.
 
Amazon recently released version 4.0 of its E-Commerce Web Services (ECS). Unfortunately, I discovered some problems using the ECS version, as documented

here. So for this application, I used the previous 3.0 release of Amazon Web services.
 
The 3.0 release includes a 
downloadable software development kit. Before getting started on the application, I installed the SDK on my computer. The SDK provides all the information you need on using Amazon Web services to add content to Web sites, enable transactions, and upload
 products to Amazon.com. I don&#39;t need to add content to my Web site or use the more advanced features of the Amazon Web services. Not yet, anyway. I usually have modest objectives when I begin working with unfamiliar technology. A desktop application that uses
 one of the Web methods provided by the Amazon Web service is a good starting point. Once I get familiar with the Amazon Web services I can look forward to tackling more ambitious projects later on.
 
For this example, we&#39;ll use one of the new Visual Studio 2005 Express Editions. The Express Editions of Visual Studio 2005 are simplified, streamlined and ligh</itunes:summary>
      <link>http://channel9.msdn.com/coding4fun/articles/Using-the-Amazon-Web-Service</link>
      <pubDate>Tue, 31 Oct 2006 14:24:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/articles/Using-the-Amazon-Web-Service</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/912260_100.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/912260_220.jpg" height="165" width="220"></media:thumbnail>      
      <dc:creator>Peter Bernhardt</dc:creator>
      <itunes:author>Peter Bernhardt</itunes:author>
      <slash:comments>15</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/coding4fun/articles/Using-the-Amazon-Web-Service/RSS</wfw:commentRss>
    </item>
  <item>
      <title>Using the Google Web Service</title>
      <description><![CDATA[<span id="c4fmetadata">
<table class="" cellspacing="0" cellpadding="1" width="100%" border="0">
<tbody>
<tr class="entry_overview">
<td class="" width="50">&nbsp;</td>
<td class=""><span class="entry_description">This article demonstrates consuming a Web service. It uses Google Search Web services to build an application that searches for given keywords.</span></td>
</tr>
<tr>
<td class="" colspan="2">
<div class="entry_author">Peter Bernhardt</div>
<div class="entry_company"><a href="http://blogs.msdn.com/controlpanel/blogs/"></a></div>
<br>
<div class="entry_details"><b>Difficulty: </b><span class="entry_details_input">Easy</span></div>
<div class="entry_details"><b>Time Required:</b> <span class="entry_details_input">
1-3 hours</span></div>
<div class="entry_details"><b>Cost: </b><span class="entry_details_input">Free</span></div>
<div class="entry_details"><b>Software: </b><span class="entry_details_input"><a href="http://msdn.com/express/">Visual Studio Express Editions</a>,
<a href="http://www.google.com/apis/">Google API</a>. </span></div>
<div class="entry_details"><b>Hardware: </b><span class="entry_details_input"></span></div>
<div class="entry_details"><b>Download: </b><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/912079/GoogleIt.msi">Download</a>
<ul>
</ul>
</div>
</td>
</tr>
</tbody>
</table>
</span>
<p>If you're like me, you probably spend more time at Google than any other place on the Internet. It remains my first and usually best choice for Internet-based research. Did you know that Google also has a Web service? With the Google Web service, you can
 bring the power of the Google search engine to any .NET Framework-based application.
</p>
<p><img height="345" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/912079/image001.jpg" width="485">
</p>
<p>If you read my earlier post about the Amazon Web service, the following should be familiar to you. The Google Web service is free, and you can
<a href="http://www.google.com/apis/download.html">download their developer kit</a> without being registered, but if you want to do anything meaningful you'll first need to
<a href="http://www.google.com/apis/">register with Google</a>. Google will email you a license key that lets you make up to 1,000 automated queries per day.
</p>
<p>I doubt I'll ever have the need to make that many requests on any given day. Maybe you can think of a unique way to make use of all those requests. Google itself offers these suggestions for ways you can use their Web service.
</p>
<ul>
<li>Auto-monitor the Web for new information on a subject </li><li>Glean market research insights and trends over time </li><li>Invent a catchy online game </li><li>Create a novel UI for searching </li><li>Add Google's spell-checking to an application </li></ul>
<p>Since I use Google primarily for research, my goal for using the Google Web service was to build a simple desktop application for basic research. I wanted to emulate my typical use of Google on the Web: that is, have a form for inputting a query and executing
 a search, and places to list and show the results of my query. </p>
<p>For this example, we'll use one of the new Visual Studio 2005 Express Editions. The Express Editions of Visual Studio 2005 are simplified, streamlined and lightweight versions of Visual Studio tailored for hobbyist, novice, and student developers. Beta 2
 of the Express editions can be downloaded at <a href="http://msdn.microsoft.com/express">
http://msdn.microsoft.com/express</a>. Any of the Visual Studio 2005 Express Editions allow you to build applications which consume Web services; I'm using Visual C# 2005 Express Edition in this example.
</p>
<p>Visual C# Express shares all of the great data access capabilities you'll also see in Visual Studio 2005. Working with the Google Web service API let me explore the Visual Studio Data Sources Window, which is a new tool window that displays objects in a
 project that you can use to create data bound forms. This includes data provided by Web services. With a Web service as a data source, it is virtually effortless to add data from the Web service to a form.
</p>
<p>Now, usually all you should have to do to get to that place is add a Web reference to your project and Visual Studio takes care of discovering the data types. I expected that to be the case with the Google Web service. But instead I ran head first into a
 known problem. I should say it was not known to me when I first added a Web reference to the Google WSDL using the wizard in the Visual C# Express development environment. Nor was it known to me when I tried to figure out how to bind to data that was not appearing
 in the Data Sources Window accurately. The picture below illustrates what was wrong.
</p>
<p><img height="220" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/912079/image002.jpg" width="284" border="0">
</p>
<p>While the Web service appeared in the Data Sources Window and I could use it to query the service and get back a result, nothing I tried would let me display the data on a form. As you will see as I continue my story, the GoogleSearchResult type contains
 an array of ResultElements, and this is what I wanted to bind to on the form. But they didn't show up. After an hour (or two) of head scratching and then some old fashioned Google research, I found myself in the Visual Studio 2005 Beta 2 readme file. Under
 the Data Access section of the known issues, I found this item: </p>
<p><b>5.10.&nbsp;&nbsp;&nbsp; Binding to Web services</b> </p>
<p>Web services do not correctly display in the Data Sources Window for binding in Windows Applications.
</p>
<p><b>To resolve this issue </b></p>
<p>Web service references are created with public fields instead of properties, and as a result do not yet work correctly at design time. As a work around, manually run the WSDL.exe tool to generate the correct web reference file. For more information, see
 the topic titled &quot;How to: Run WSDL.exe to Prepare a Web Service to be used as a Data Source&quot; in the Visual Studio help collection.
</p>
<p>If you followed the link to the article you will note (perhaps with as much irony as I did) that the example Microsoft provides for correcting the problem is the Google API. At any rate this article had me back on track. The next picture shows what my Data
 Sources Window looked like after I added the manually generated Web reference file to my project.
</p>
<p><img height="450" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/912079/image003.jpg" width="284" border="0">
</p>
<p>Working in the Data Sources Window, you can view all the data types available from a Web service. This view represents what you'll see if you have a Windows form open in design mode. The icons next to each item in the tree represent the type of control you
 can create by dragging the element onto a form. You can change the control type using the drop-down arrow that appears when you select an item.
</p>
<p>Anyway, the real beauty of this is that once you have your data ducks in a row you can begin building a data-bound user interface by dragging and dropping items from the Data Sources Window onto the form. Below is an early draft of my user interface. I built
 this in a matter of seconds by dragging items from the Data Sources Window onto the form. Visual Studio automatically created the necessary Data Connectors.
</p>
<p><img height="336" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/912079/image004.jpg" width="485" border="0">
</p>
<p>I ultimately decided to make this application have a browser-like look and feel. So in addition to a ToolStrip menu a status bar, I used a ListBox control at the top of my application to display the title of each search result. And then below that, I added
 a Web browser control to the form to display the associated Web page when a user selects an item from the list.
</p>
<p>If you read through the documentation that comes with the Google developer kit, you'll find you have many different ways to submit a search query. You can apply language and country filters, for example, or search specific domains. You can also limit the
 search by date or file type. Basically, you have all the options available on the Google Advanced Search Web page. To experiment a bit with these possibilities, I added a ComboBox control to my application's ToolStrip to designate a language for a given search.
</p>
<p>Behind the user interface elements, I leveraged the asynchronous processing capabilities of the Web service proxy class. The WSDL.exe tool automatically generates asynchronous versions of the Web methods it finds in the WSDL file. This lets you call a Web
 method on a separate thread to avoid locking up the application. Of course, you have other ways to boost performance. For example, I limited the number of results returned from the Google Web service to 10. But if I really want to make full use of the tool,
 asynchronous processing will help you to overcome performance bottlenecks. </p>
<p>To implement asynchronous processing, I added a BackgroundWorker component to the form and set up event handlers in the Form's constructor method.
</p>
<pre></pre>
<pre class="csharpcode">backgroundWorker.DoWork &#43;=<span class="kwrd">new</span> DoWorkEventHandler(backgroundWorker_DoWork);<br>backgroundWorker.ProgressChanged &#43;=<br>    <span class="kwrd">new</span> ProgressChangedEventHandler(backgroundWorker_ProgressChanged);<br>backgroundWorker.RunWorkerCompleted &#43;=<br>    <span class="kwrd">new</span> RunWorkerCompletedEventHandler(backgroundWorker_RunWorkerCompleted);</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>The code in my Search button's click event handler calls a helper method called StartSearch to begin the asynchronous Web service call using the BackgroundWorker. To pass the two user input values (the query text and the language selection) to the thread
 on which the BackgroundWorker runs, component executes the Web service call, I used a string array.
</p>
<pre></pre>
<pre class="csharpcode"><span class="kwrd">string</span>[] searchCriteria = { <span class="kwrd">this</span>.queryText.Text, <span class="kwrd">this</span>._language };</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>And then passed the array as an argument to the RunWorkAsync method of the BackgroundWorker.
</p>
<pre></pre>
<pre class="csharpcode">backgroundWorker.RunWorkerAsync(searchCriteria);</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>That invokes the method I delegated above called backgroundWorker_DoWork. This method executes on a separate thread. That's why I need to pass the values from the Windows form as input to this method (they aren't available to me from another thread). After
 first instantiating an instance of the Web service, the code reconstitutes the input argument (e.Argument) as a string array and then passes those values as parameters to the BeginGoogleSearch method of the Web service proxy class.
</p>
<pre></pre>
<pre class="csharpcode">Google.GoogleSearchService googleWS = <span class="kwrd">new</span> Google.GoogleSearchService();<br><span class="kwrd">string</span>[] searchCriteria = e.Argument <span class="kwrd">as</span> <span class="kwrd">string</span>[];<br>IAsyncResult asyncResult = googleWS.BegindoGoogleSearch(<br>  LicenseKey,<br>  searchCriteria[0], 0, 10, <span class="kwrd">true</span>,<br>  searchCriteria[1], <span class="kwrd">true</span>, <span class="str">&quot;&quot;</span>, <span class="str">&quot;&quot;</span>, <span class="str">&quot;&quot;</span>, <span class="kwrd">null</span>, <span class="kwrd">null</span>);</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>As I said before, BeginGoogleSearch is the first of the pair of asynchronous methods that the WSDL.exe tool created from the synchronous Web method. In the code that follows, I create WaitHandle that allows me to monitor the progress of the asynchronous
 Web service call. At intervals of 200 milliseconds I report the progress back to the main thread using the ReportProgress methods of the BackgroundWorker.
</p>
<pre></pre>
<pre class="csharpcode">worker.ReportProgress(percentageComplete);</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>This causes the code in the delegate method for the ProgressChanged event to execute. In this case, the name of the delegate is backgroundWorker_ProgressChanged, which contains a single line of code to update the value of the ProgressBar control on the form.
</p>
<pre></pre>
<pre class="csharpcode"><span class="kwrd">this</span>.progressBar.Value = e.ProgressPercentage;</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>When the asynchronous call completes, the code in BackgroundWorker's RunWorkerCompleted delegate method executes. This method is named backgroundWorker_RunWorker; it performs some basic error and cancellation checking and then, if all went well, it processes
 the results of the Web service call. In the first line of code below, the result is cast from the input argument into an instance of the GoogleSearchResult. The next line updates the DataSource property of the DataConnector to use the collection of ResultElements
 (this is what contains the results of the Google search) which are exposed as a property of the GoogleSearchResult object.
</p>
<pre></pre>
<pre class="csharpcode">Google.GoogleSearchResult searchResponse = e.Result <span class="kwrd">as</span> Google.GoogleSearchResult;<br>resultElementDataConnector.DataSource = searchResponse.resultElements;</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>The DataSource for the ListBox is the DataConnector named resultElementDataConnector. The DisplayMember property of the ListBox is “title”, which maps to the title property of the ResultElement type, and the ValueMember property of the ListBox is set is
 similarly mapped to the “URL” property of the ResultElement. </p>
<p>Finally, the code in the handler for the ListBox's SelectedValueChanged event updates the Url property of the Web browser control, which causes the Web page associated with the search result to display on the form.
</p>
<pre></pre>
<pre class="csharpcode">itemBrowser.Url = resultList.SelectedValue.ToString(); </pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>That completes the tour of this application.&nbsp;What started out for me as an exploration of how to leverage the Google search services in a Windows application became something of an odyssey. But it was a journey that had a happy conclusion and made me appreciate
 the powerful data binding capabilities of Visual Studio 2005 more deeply. I encourage you to download Visual C# Express and explore this application for yourself.
</p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/c4f.Peter-Bernhardt/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:40534ab129194f60ab739e7600db8568">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/articles/Using-the-Google-Web-Service</comments>
      <itunes:summary>



&amp;nbsp;
This article demonstrates consuming a Web service. It uses Google Search Web services to build an application that searches for given keywords.



Peter Bernhardt


Difficulty: Easy
Time Required: 
1-3 hours
Cost: Free
Software: Visual Studio Express Editions,
Google API. 
Hardware: 
Download: Download








If you&#39;re like me, you probably spend more time at Google than any other place on the Internet. It remains my first and usually best choice for Internet-based research. Did you know that Google also has a Web service? With the Google Web service, you can
 bring the power of the Google search engine to any .NET Framework-based application.
 

 
If you read my earlier post about the Amazon Web service, the following should be familiar to you. The Google Web service is free, and you can
download their developer kit without being registered, but if you want to do anything meaningful you&#39;ll first need to
register with Google. Google will email you a license key that lets you make up to 1,000 automated queries per day.
 
I doubt I&#39;ll ever have the need to make that many requests on any given day. Maybe you can think of a unique way to make use of all those requests. Google itself offers these suggestions for ways you can use their Web service.
 

Auto-monitor the Web for new information on a subject Glean market research insights and trends over time Invent a catchy online game Create a novel UI for searching Add Google&#39;s spell-checking to an application 
Since I use Google primarily for research, my goal for using the Google Web service was to build a simple desktop application for basic research. I wanted to emulate my typical use of Google on the Web: that is, have a form for inputting a query and executing
 a search, and places to list and show the results of my query.  
For this example, we&#39;ll use one of the new Visual Studio 2005 Express Editions. The Express Editions of Visual Studio 2005 are simplified, streamlined and lightweight versions of Visu</itunes:summary>
      <link>http://channel9.msdn.com/coding4fun/articles/Using-the-Google-Web-Service</link>
      <pubDate>Tue, 31 Oct 2006 14:12:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/articles/Using-the-Google-Web-Service</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/912079_100.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/912079_220.jpg" height="165" width="220"></media:thumbnail>      
      <dc:creator>Peter Bernhardt</dc:creator>
      <itunes:author>Peter Bernhardt</itunes:author>
      <slash:comments>10</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/coding4fun/articles/Using-the-Google-Web-Service/RSS</wfw:commentRss>
    </item>    
</channel>
</rss>