<?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.Alan-Lewis/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.Alan-Lewis/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.Alan-Lewis/Posts</link>
    <language>en</language>
    <pubDate>Thu, 23 May 2013 03:42:36 GMT</pubDate>
    <lastBuildDate>Thu, 23 May 2013 03:42:36 GMT</lastBuildDate>
    <generator>Rev9</generator>
    <c9:totalResults>1</c9:totalResults>
    <c9:pageCount>1</c9:pageCount>
    <c9:pageSize>25</c9:pageSize>
  <item>
      <title>Building a Custom eBay Watch List Using the SOAP API</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">Keeping a track on changes on eBay using its web service.</span></td>
</tr>
<tr>
<td class="" colspan="2">
<div class="entry_author">Alan Lewis</div>
<div class="entry_company"><a href="http://alanlewis.typepad.com/">Alan Lewis</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://developer.ebay.com/">eBay web service</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/912397/BuildingCustomeBayWatchList.msi">C# Download</a>
</li><li><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/912397/252348_Building_20A_20Custom_20eBay_20Watch_20List.zip">VB Download</a></li></ul>
</div>
</td>
</tr>
</tbody>
</table>
</span>
<p>If you're like me, you're always keeping an eye on what's happening on eBay. Whenever I find something that I'm interested in tracking, I use eBay's Watch List feature to remember it for me. However, I find when I'm watching lots of items it's not so easy
 to sort, filter, and display them as I want. That's where eBay Web Services comes in. What I did was write a program to retrieve all my watch list items using SOAP. Now I have complete control to customize the display and add the feature I want to the interface.
</p>
<p>In this article I'll walk you how I did this using ASP.NET 2.0. You'll learn the basics of eBay Web Services and see how easy it is to customize eBay.
</p>
<p><img alt="" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/912397/ebaywatch_1.gif" border="0">
</p>
<h4>Getting Registered with eBay</h4>
<p>To get started, register with the <a href="http://developer.ebay.com/join">eBay Developers Program</a>. Signing up for the program gives you access to the Sandbox, eBay's test environment that allows you to test your applications before taking them live.
 For this example, we want to pull down the real eBay Watch List data, so you need to get access to eBay's production environment. Register for access to the production eBay environment by submitting the
<a href="http://developer.ebay.com/DevZone/launch/SelfCertify.asp">Self-Certification Form</a>. Once you complete this form you'll receive an email with instructions on how to retrieve your production developer keys. Follow those instructions, and once you've
 retrieved your keys save them in a text file for later use. </p>
<p>Once you have access to the production environment, create an authentication token for your eBay username by going to
<a href="http://cgi1.ebay.com/aw-cgi/eBayISAPI.dll?RegisterShow&amp;ru=http%3A//www.ebay.com">
http://cgi1.ebay.com/aw-cgi/eBayISAPI.dll?RegisterShow&amp;ru=http%3A//www.ebay.com</a>. (<a href="http://cgi1.ebay.com/aw-cgi/eBayISAPI.dll?RegisterShow&amp;ru=http%3A//www.ebay.com">Sign up for eBay first</a> if you haven't done so.) eBay Web Services uses authentication
 tokens for user authentication to keep your user data secure. This system allows authorized third party applications to make Web Services calls on your behalf without those third parties having access to your eBay username and password. Use the
<a href="http://developer.ebay.com/tokentool/">Single User Authentication Token tool</a> to create an authentication token for your test user. In the tool, select the Production environment and enter the production developer keys you retrieved earlier. Go through
 the flow, and when you're done save the authentication token in the same place as you saved your developer keys.
</p>
<h4>Accessing the eBay Web Service</h4>
<p>Now that you have all of that stuff out of the way, we're ready to go. eBay offers access to its web services through SOAP, XML, SDKs for .NET and Java, and even a REST API. For this example we'll be using the SOAP API. eBay exposes a WSDL file that you
 use to generate wrapper code for the SOAP API. In Visual Studio 2005 or Visual Web Developer 2005 Express Edition, first create a new Web Site, and then import the eBay WSDL file by right-clicking the web site root in the Solution Explorer, then selecting
 Add Web Reference...: </p>
<p><img alt="" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/912397/ebaywatch_2.gif" border="0">
</p>
<p>In the Add Web Reference dialog, load the WSDL URL: </p>
<p><b>http://developer.ebay.com/webservices/latest/eBaySvc.wsdl</b> </p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/912397/ebaywatch_3.gif"><img alt="Click here for larger image" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/912397/ebaywatch_3_thumb.gif" border="0"></a>
</p>
<p><b>(Click image to zoom)</b> </p>
<p>It takes a few minutes to load the WSDL and generate the stubs from it. Once the WSDL is loaded, click Add Reference. If you get impatient with this process, just think:
<i>all this generated code is saving me time</i>! </p>
<h4>A Custom Watch List Web Form</h4>
<p>The example we are creating displays the contents of your eBay watch list in a simple table. Create a new Web Form, and in the
<b>&lt;div&gt;</b> element insert the following table: </p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">asp:Table</span> <span class="attr">BorderWidth</span><span class="kwrd">=&quot;1&quot;</span> <span class="attr">BorderStyle</span><span class="kwrd">=&quot;Solid&quot;</span> <span class="attr">ID</span><span class="kwrd">=&quot;Table1&quot;</span> <br>        <span class="attr">GridLines</span><span class="kwrd">=&quot;Both&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span><span class="kwrd">&gt;</span><br>    <span class="kwrd">&lt;</span><span class="html">asp:TableRow</span><span class="kwrd">&gt;</span><br>        <span class="kwrd">&lt;</span><span class="html">asp:TableCell</span> <span class="attr">Text</span><span class="kwrd">=&quot;Time Left&quot;</span> <span class="attr">Width</span><span class="kwrd">=&quot;90&quot;</span> <span class="attr">Font-Bold</span><span class="kwrd">=&quot;true&quot;</span><br>             <span class="attr">HorizontalAlign</span><span class="kwrd">=&quot;Center&quot;</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp:TableCell</span><span class="kwrd">&gt;</span><br>        <span class="kwrd">&lt;</span><span class="html">asp:TableCell</span> <span class="attr">Text</span><span class="kwrd">=&quot;Title&quot;</span> <span class="attr">Width</span><span class="kwrd">=&quot;120&quot;</span> <span class="attr">Font-Bold</span><span class="kwrd">=&quot;true&quot;</span><span class="kwrd">&gt;</span><br>        <span class="kwrd">&lt;/</span><span class="html">asp:TableCell</span><span class="kwrd">&gt;</span><br>        <span class="kwrd">&lt;</span><span class="html">asp:TableCell</span> <span class="attr">Text</span><span class="kwrd">=&quot;Price&quot;</span> <span class="attr">Width</span><span class="kwrd">=&quot;65&quot;</span> <span class="attr">Font-Bold</span><span class="kwrd">=&quot;true&quot;</span> <br>            <span class="attr">HorizontalAlign</span><span class="kwrd">=&quot;Center&quot;</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp:TableCell</span><span class="kwrd">&gt;</span><br>        <span class="kwrd">&lt;</span><span class="html">asp:TableCell</span> <span class="attr">Text</span><span class="kwrd">=&quot;Item ID&quot;</span> <span class="attr">Width</span><span class="kwrd">=&quot;80&quot;</span> <span class="attr">Font-Bold</span><span class="kwrd">=&quot;true&quot;</span><br>            <span class="attr">HorizontalAlign</span><span class="kwrd">=&quot;Center&quot;</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp:TableCell</span><span class="kwrd">&gt;</span>                <br>    <span class="kwrd">&lt;/</span><span class="html">asp:TableRow</span><span class="kwrd">&gt;</span><br><span class="kwrd">&lt;/</span><span class="html">asp:Table</span><span class="kwrd">&gt;</span>&nbsp;</pre>
<p>The table headers are declared in the markup. The rest of the table rows with the watch list data will be added dynamically once the web service call is made.
</p>
<p>The generated code allows you to make calls to any of the 100&#43; methods exposed by the eBay SOAP API. Once you have figured out how to make one eBay Web Service call, the rest is easy. The
<b>Page_Load</b> method in the code behind file contains the following code that sets up the call (you'll find the complete code in the download that accompanies this article):</p>
<p><b>Visual C#</b> <br>
</p>
<pre><code></code></pre>
<pre class="csharpcode"><span class="kwrd">string</span> endpoint = <span class="str">&quot;https://api.ebay.com/wsapi&quot;</span>;<br><span class="kwrd">string</span> callName = <span class="str">&quot;GetMyeBayBuying&quot;</span>;<br><span class="kwrd">string</span> siteId = <span class="str">&quot;0&quot;</span>;<br><span class="kwrd">string</span> appId = <span class="str">&quot;YOUR_APPID&quot;</span>;  <span class="rem">// use your app ID </span><br><span class="kwrd">string</span> devId = <span class="str">&quot;YOUR_DEVID&quot;</span>;  <span class="rem">// use your dev ID </span><br><span class="kwrd">string</span> certId = <span class="str">&quot;YOUR_CERTIFICATE&quot;</span>;  <span class="rem">// use your cert ID </span><br><span class="kwrd">string</span> version = <span class="str">&quot;437&quot;</span>;<br><span class="rem">// Build the request URL </span><br><span class="kwrd">string</span> requestURL = endpoint<br>    &#43; <span class="str">&quot;?callname=&quot;</span> &#43; callName<br>    &#43; <span class="str">&quot;&amp;siteid=&quot;</span> &#43; siteId<br>    &#43; <span class="str">&quot;&amp;appid=&quot;</span> &#43; appId<br>    &#43; <span class="str">&quot;&amp;version=&quot;</span> &#43; version<br>    &#43; <span class="str">&quot;&amp;routing=default&quot;</span>;<br><span class="rem">// Create the service </span><br>eBayAPIInterfaceService service = <span class="kwrd">new</span> eBayAPIInterfaceService();<br><span class="rem">// Assign the request URL to the service locator. </span><br>service.Url = requestURL;<br><span class="rem">// Set credentials </span><br>service.RequesterCredentials = <span class="kwrd">new</span> CustomSecurityHeaderType();<br>service.RequesterCredentials.eBayAuthToken = <span class="str">&quot;YOUR_TOKEN&quot;</span>;  <span class="rem">// use your token </span><br>service.RequesterCredentials.Credentials = <span class="kwrd">new</span> UserIdPasswordType();<br>service.RequesterCredentials.Credentials.AppId = appId;<br>service.RequesterCredentials.Credentials.DevId = devId;<br>service.RequesterCredentials.Credentials.AuthCert = certId;</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>
<p><b></b></p>
<pre class="csharpcode"><span class="kwrd">Dim</span> endpoint <span class="kwrd">As</span> <span class="kwrd">String</span> = <span class="str">&quot;https://api.ebay.com/wsapi&quot;</span><br><span class="kwrd">Dim</span> callName <span class="kwrd">As</span> <span class="kwrd">String</span> =  <span class="str">&quot;GetMyeBayBuying&quot;</span> <br><span class="kwrd">Dim</span> siteId <span class="kwrd">As</span> <span class="kwrd">String</span> = <span class="str">&quot;0&quot;</span><br><br><span class="kwrd">Dim</span> appId <span class="kwrd">As</span> <span class="kwrd">String</span> = <span class="str">&quot;YOUR_APPID&quot;</span>  <span class="rem">'TODO: Enter your AppID </span><br><span class="kwrd">Dim</span> devId <span class="kwrd">As</span> <span class="kwrd">String</span> = <span class="str">&quot;YOUR_DEVID&quot;</span>  <span class="rem">'TODO: Enter your DevID </span><br><span class="kwrd">Dim</span> certId <span class="kwrd">As</span> <span class="kwrd">String</span> = <span class="str">&quot;YOUR_CERTIFICATE&quot;</span>  <span class="rem">'TODO: Enter your CertID</span><br><br><span class="kwrd">Dim</span> version <span class="kwrd">As</span> <span class="kwrd">String</span> = <span class="str">&quot;437&quot;</span><br><br><span class="rem">' Build the request URL </span><br><span class="kwrd">Dim</span> requestURL <span class="kwrd">As</span> <span class="kwrd">String</span> = endpoint _<br>        &amp; <span class="str">&quot;?callname=&quot;</span> &amp; callName _<br>        &amp; <span class="str">&quot;&amp;siteid=&quot;</span> &amp; siteId _<br>        &amp; <span class="str">&quot;&amp;appid=&quot;</span> &amp; appId _<br>        &amp; <span class="str">&quot;&amp;version=&quot;</span> &amp; version _<br>        &amp; <span class="str">&quot;&amp;routing=default&quot;</span><br><br><span class="rem">' Create the service </span><br><span class="kwrd">Dim</span> service <span class="kwrd">As</span> <span class="kwrd">New</span> eBayAPIInterfaceService()<br><span class="kwrd">With</span> service<br>        <span class="rem">' Assign the request URL to the service locator. </span><br>        .Url = requestURL<br>        <span class="rem">' Set credentials </span><br>        .RequesterCredentials = <span class="kwrd">New</span> CustomSecurityHeaderType()<br>        .RequesterCredentials.eBayAuthToken = <span class="str">&quot;YOUR_TOKEN&quot;</span> <span class="rem">'TODO: Enter your production token </span><br>        .RequesterCredentials.Credentials = <span class="kwrd">New</span> UserIdPasswordType()<br>        <span class="kwrd">With</span> .RequesterCredentials.Credentials<br>                .AppId = appId<br>                .DevId = devId<br>                .AuthCert = certId<br>        <span class="kwrd">End</span> <span class="kwrd">With</span><br><span class="kwrd">End</span> <span class="kwrd">With</span>
</pre>
<p>Replace the &quot;YOUR&quot; strings with the developer keys and authentication token that you retrieved earlier. This code sets the SOAP header with the authentication information and creates the URL parameters that are passed in.
</p>
<p>The one line in this code that will change from call to call is this:</p>
<p><b>Visual C#</b>&nbsp; <br>
</p>
<pre><b><code></code></b></pre>
<pre class="csharpcode"><span class="kwrd">string</span> callName = <span class="str">&quot;GetMyeBayBuying&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>
<p><b></b></p>
<pre class="csharpcode"><span class="kwrd">Dim</span> callName <span class="kwrd">As</span> <span class="kwrd">String</span> = <span class="str">&quot;GetMyeBayBuying&quot;</span></pre>
<p>For whatever call you are making, set the <b>callName</b> accordingly. </p>
<p>The <b>GetMyeBayBuying</b> call retrieves all sorts of information about items you have purchased, items in your watch list, items you are bidding on, and more. The call to
<b>GetMyeBayBuying</b> is very simple:</p>
<p><b>Visual C#</b>&nbsp; <br>
</p>
<pre><code></code></pre>
<pre class="csharpcode"><span class="rem">// Make the call to GetMyeBayBuying </span><br>GetMyeBayBuyingRequestType buyingRequest = <span class="kwrd">new</span> GetMyeBayBuyingRequestType();<br>ItemListCustomizationType watchListOptions = <span class="kwrd">new</span> ItemListCustomizationType();<br>watchListOptions.Sort = ItemSortTypeCodeType.TimeLeft;<br>buyingRequest.WatchList = watchListOptions;<br>buyingRequest.Version = version;<br>GetMyeBayBuyingResponseType buyingResponse = service.GetMyeBayBuying(buyingRequest);<br>ItemType[] items = buyingResponse.WatchList.ItemArray;</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>
<p><b></b></p>
<pre class="csharpcode"><span class="rem">' Make the call to GetMyeBayBuying </span><br><span class="kwrd">Dim</span> buyingRequest <span class="kwrd">As</span> <span class="kwrd">New</span> GetMyeBayBuyingRequestType()<br><span class="kwrd">Dim</span> watchListOptions <span class="kwrd">As</span> <span class="kwrd">New</span> ItemListCustomizationType()<br>watchListOptions.Sort = ItemSortTypeCodeType.TimeLeft<br>buyingRequest.WatchList = watchListOptions<br>buyingRequest.Version = version<br><span class="kwrd">Dim</span> buyingResponse <span class="kwrd">As</span> GetMyeBayBuyingResponseType = _<br>        service.GetMyeBayBuying(buyingRequest)<br><span class="kwrd">Dim</span> items() <span class="kwrd">As</span> ItemType = buyingResponse.WatchList.ItemArray</pre>
<p>The instance of <b>GetMyeBayBuyingRequestType</b> contains the call input options. To specify that we want to retrieve the contents of the watch list, we set the
<b>WatchList</b> property with the <b>ItemListCustomizationType</b> options that we have created. We also set the
<b>Version</b> property to the same version string as we are passing in the URL. The
<b>eBayAPIInterfaceService</b> object contains a method for each call exposed by the SOAP API, and each method takes a &quot;request type&quot; object as a parameter. We pass in the request object that we've created and set the result to an instance of
<b>GetMyeBayBuyingResponseType</b>. Finally, we extract the watch list items from the
<b>WatchList.ItemArray</b> property of the response object, and set it to an array of
<b>ItemType</b>. </p>
<p>Once we have retrieved the items, it is up to us to display the information we want or make further calculations:</p>
<p><b>Visual C#</b>&nbsp; <br>
</p>
<pre><code></code></pre>
<pre class="csharpcode"><span class="rem">// Add table rows</span><br><span class="kwrd">for</span> (<span class="kwrd">int</span> i = 0; i &lt; items.Length; i&#43;&#43;)<br>{<br>    TableCell timeLeftCell = <span class="kwrd">new</span> TableCell();<br>    DateTime endTime = items[i].ListingDetails.EndTime;<br>    DateTime now = DateTime.Now;<br>    <span class="rem">// Display that the item has ended, or how much time is left</span><br>    <span class="kwrd">if</span> (endTime &lt; now)<br>    {<br>        timeLeftCell.Text = <span class="str">&quot;Ended&quot;</span>;<br>    }<br>    <span class="kwrd">else</span><br>    {<br>        TimeSpan timeLeft = endTime - now;<br>        <span class="kwrd">string</span> timeLeftDisplay = <span class="str">&quot;&quot;</span>;<br>        <span class="kwrd">int</span> days = timeLeft.Days;<br>        <span class="kwrd">if</span> (days &gt; 0)<br>            timeLeftDisplay &#43;= days.ToString() &#43; <span class="str">&quot; days, &quot;</span>;<br>        <span class="kwrd">int</span> hours = timeLeft.Hours;<br>        <span class="kwrd">if</span> (hours &gt; 0)<br>            timeLeftDisplay &#43;= hours.ToString() &#43; <span class="str">&quot; hours&quot;</span>;<br>        <span class="kwrd">int</span> minutes = timeLeft.Minutes;<br>        <span class="kwrd">if</span> (minutes &gt; 0 &amp;&amp; days == 0)<br>            timeLeftDisplay &#43;= <span class="str">&quot;, &quot;</span> &#43; minutes.ToString() &#43; <span class="str">&quot; min&quot;</span>;<br>        <span class="kwrd">int</span> seconds = timeLeft.Seconds;<br>        <span class="kwrd">if</span> (days == 0 &amp;&amp; hours == 0)<br>            timeLeftDisplay &#43;= <span class="str">&quot;, &quot;</span> &#43; seconds.ToString() &#43; <span class="str">&quot; sec&quot;</span>;<br>        timeLeftCell.Text = timeLeftDisplay;<br>    }     <br>    <span class="rem">// Display the item title</span><br>    TableCell titleCell = <span class="kwrd">new</span> TableCell();<br>    titleCell.Text = items[i].Title;<br>    <span class="rem">// Display the current price</span><br>    TableCell currentPriceCell = <span class="kwrd">new</span> TableCell();<br>    currentPriceCell.Text = items[i].SellingStatus.CurrentPrice.Value.ToString();<br>    <span class="rem">// Display the Item ID</span><br>    TableCell itemIDCell = <span class="kwrd">new</span> TableCell();<br>    itemIDCell.Text = <span class="str">&quot;&lt;a href=\&quot;http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&amp;item=&quot;</span><br>    &#43; items[i].ItemID &#43; <span class="str">&quot;\&quot;&gt;&quot;</span> &#43; items[i].ItemID &#43; <span class="str">&quot;&lt;/a&gt;&quot;</span>;<br>    <br>    TableRow row = <span class="kwrd">new</span> TableRow();<br>    <span class="kwrd">if</span> ((i % 2) == 1)<br>    {<br>        row.BackColor = System.Drawing.Color.LightGray;<br>    }<br>    row.Cells.Add(timeLeftCell);<br>    row.Cells.Add(titleCell);<br>    row.Cells.Add(currentPriceCell);<br>    row.Cells.Add(itemIDCell);<br><br>    Table1.Rows.Add(row); <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 class="csharpcode"><span class="rem">' Add table rows</span><br><span class="kwrd">For</span> i <span class="kwrd">As</span> <span class="kwrd">Integer</span> = 0 <span class="kwrd">To</span> items.Length - 1 <span class="kwrd">Step</span> i &#43; 1<br>    <span class="kwrd">Dim</span> timeLeftCell <span class="kwrd">As</span> <span class="kwrd">New</span> TableCell()<br>    <span class="kwrd">Dim</span> endTime <span class="kwrd">As</span> DateTime = items(i).ListingDetails.EndTime<br>    <span class="kwrd">Dim</span> now <span class="kwrd">As</span> DateTime = DateTime.Now<br><br>    <span class="rem">' Display that the item has ended, or how much time is left</span><br>    <span class="kwrd">If</span> endTime &lt; now <span class="kwrd">Then</span><br>        timeLeftCell.Text = <span class="str">&quot;Ended&quot;</span><br>    <span class="kwrd">Else</span><br>        <span class="kwrd">Dim</span> timeLeft <span class="kwrd">As</span> TimeSpan = endTime - now<br>        <span class="kwrd">Dim</span> timeLeftDisplay <span class="kwrd">As</span> <span class="kwrd">String</span> = <span class="kwrd">String</span>.Empty<br>        <span class="kwrd">Dim</span> days <span class="kwrd">As</span> <span class="kwrd">Integer</span> = timeLeft.Days<br>        <span class="kwrd">If</span> days &gt; 0 <span class="kwrd">Then</span><br>            timeLeftDisplay &amp;= days.ToString() &amp; <span class="str">&quot; days, &quot;</span><br>        <span class="kwrd">End</span> <span class="kwrd">If</span><br><br>        <span class="kwrd">Dim</span> hours <span class="kwrd">As</span> <span class="kwrd">Integer</span> = timeLeft.Hours<br>        <span class="kwrd">If</span> hours &gt; 0 <span class="kwrd">Then</span><br>            timeLeftDisplay &amp;= hours.ToString() &amp; <span class="str">&quot; hours&quot;</span><br>        <span class="kwrd">End</span> <span class="kwrd">If</span><br>        <span class="kwrd">Dim</span> minutes <span class="kwrd">As</span> <span class="kwrd">Integer</span> = timeLeft.Minutes<br>        <span class="kwrd">If</span> minutes &gt; 0 <span class="kwrd">And</span> days = 0 <span class="kwrd">Then</span><br>            timeLeftDisplay &amp;= <span class="str">&quot;, &quot;</span> &amp; minutes.ToString() &amp; <span class="str">&quot; min&quot;</span><br>        <span class="kwrd">End</span> <span class="kwrd">If</span><br>        <span class="kwrd">Dim</span> seconds <span class="kwrd">As</span> <span class="kwrd">Integer</span> = timeLeft.Seconds<br>        <span class="kwrd">If</span> days = 0 <span class="kwrd">And</span> hours = 0 <span class="kwrd">Then</span><br>            timeLeftDisplay &amp;= <span class="str">&quot;, &quot;</span> &amp; seconds.ToString() &amp; <span class="str">&quot; sec&quot;</span><br>        <span class="kwrd">End</span> <span class="kwrd">If</span><br>        timeLeftCell.Text = timeLeftDisplay<br>    <span class="kwrd">End</span> <span class="kwrd">If</span><br><br>    <span class="rem">' Display the item title</span><br>    <span class="kwrd">Dim</span> titleCell <span class="kwrd">As</span> <span class="kwrd">New</span> TableCell()<br>    titleCell.Text = items(i).Title<br>    <br>    <span class="rem">' Display the current price</span><br>    <span class="kwrd">Dim</span> currentPriceCell <span class="kwrd">As</span> <span class="kwrd">New</span> TableCell()<br>    currentPriceCell.Text = items(i).SellingStatus.CurrentPrice.Value.ToString()<br><br>    <span class="rem">' Display the Item ID</span><br>    <span class="kwrd">Dim</span> itemIDCell <span class="kwrd">As</span> <span class="kwrd">New</span> TableCell()<br>    itemIDCell.Text = <span class="str">&quot;&lt;a href=&quot;</span><span class="str">&quot;http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&amp;item=&quot;</span> _<br>        &amp; items(i).ItemID &amp; <span class="str">&quot;&quot;</span><span class="str">&quot;&gt;&quot;</span> &amp; items(i).ItemID &amp; <span class="str">&quot;&lt;/a&gt;&quot;</span><br><br>    <span class="kwrd">Dim</span> row <span class="kwrd">As</span> <span class="kwrd">New</span> TableRow()<br>    <span class="kwrd">If</span> (i <span class="kwrd">Mod</span> 2) = 1 <span class="kwrd">Then</span><br>        row.BackColor = System.Drawing.Color.LightGray<br>    <span class="kwrd">End</span> <span class="kwrd">If</span><br><br>    <span class="kwrd">With</span> row.Cells<br>        .Add(timeLeftCell)<br>        .Add(titleCell)<br>        .Add(currentPriceCell)<br>        .Add(itemIDCell)<br>    <span class="kwrd">End</span> <span class="kwrd">With</span><br><br>    Table1.Rows.Add(row)<br>Next</pre>
<p>The most complex code in this example actually has nothing to do with the web service call: the end time is passed back as a
<b>DateTime</b>, but we want to show how much time is left for each item. First, for items that have not already ended, we calculate a
<b>TimeSpan</b> between now and the end time. Then, we apply some simple heuristics on that
<b>TimeSpan</b> to create a more friendly string representation. Modern platforms like .NET make it easy to get data from web services, so you'll often find yourself spending much more time manipulating the data that you've retrieved.
</p>
<p>Each cell in the table row is represented by a <b>TableCell</b> object. For each field in each item that we retrieve, a
<b>TableCell</b> is created and its <b>Text</b> property is populated with what we want to display. We then create a
<b>TableRow</b> object and call the <b>Add</b> method on its <b>Cells</b> property. And last, we add the row to the
<b>Rows</b> property on the <b>Table1</b> object that is declared on the form. </p>
<p>That's it! With one simple form and little more than 100 lines of code, you have a working application that integrates with eBay Web Services to do something useful. In a future article I'll show you how to integrate other calls and use more sophisticated
 XML processing to add unique features not available in the standard eBay watch list.</p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/c4f.Alan-Lewis/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:c0ea11f56ee14e3791699e7600db1689">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/articles/Building-a-Custom-eBay-Watch-List-Using-the-SOAP-API</comments>
      <itunes:summary>



&amp;nbsp;
Keeping a track on changes on eBay using its web service.



Alan Lewis
Alan Lewis

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

C# Download
VB Download






If you&#39;re like me, you&#39;re always keeping an eye on what&#39;s happening on eBay. Whenever I find something that I&#39;m interested in tracking, I use eBay&#39;s Watch List feature to remember it for me. However, I find when I&#39;m watching lots of items it&#39;s not so easy
 to sort, filter, and display them as I want. That&#39;s where eBay Web Services comes in. What I did was write a program to retrieve all my watch list items using SOAP. Now I have complete control to customize the display and add the feature I want to the interface.
 
In this article I&#39;ll walk you how I did this using ASP.NET 2.0. You&#39;ll learn the basics of eBay Web Services and see how easy it is to customize eBay.
 

 
Getting Registered with eBay
To get started, register with the eBay Developers Program. Signing up for the program gives you access to the Sandbox, eBay&#39;s test environment that allows you to test your applications before taking them live.
 For this example, we want to pull down the real eBay Watch List data, so you need to get access to eBay&#39;s production environment. Register for access to the production eBay environment by submitting the
Self-Certification Form. Once you complete this form you&#39;ll receive an email with instructions on how to retrieve your production developer keys. Follow those instructions, and once you&#39;ve
 retrieved your keys save them in a text file for later use.  
Once you have access to the production environment, create an authentication token for your eBay username by going to

http://cgi1.ebay.com/aw-cgi/eBayISAPI.dll?RegisterShow&amp;amp;ru=http%3A//www.ebay.com. (Sign up for eBay first if you haven&#39;t done so.) eBay Web Services uses authentication
 tokens for user authentication to keep your user data secure. This system </itunes:summary>
      <link>http://channel9.msdn.com/coding4fun/articles/Building-a-Custom-eBay-Watch-List-Using-the-SOAP-API</link>
      <pubDate>Tue, 31 Oct 2006 14:43:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/articles/Building-a-Custom-eBay-Watch-List-Using-the-SOAP-API</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/912397_100.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/912397_220.jpg" height="165" width="220"></media:thumbnail>      
      <dc:creator>Alan Lewis</dc:creator>
      <itunes:author>Alan Lewis</itunes:author>
      <slash:comments>25</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/coding4fun/articles/Building-a-Custom-eBay-Watch-List-Using-the-SOAP-API/RSS</wfw:commentRss>
    </item>    
</channel>
</rss>