Welcome Guest!
Create Account | Login
Locator+ Code:

Search:
FTPOnline Channels Conferences Resources Hot Topics Partner Sites Magazines About FTP RSS 2.0 Feed


Building a Web Services Conduit (Continued)

Nitty Gritty Details
After calling one of the Web service methods, the returned ProductInfo class accesses product details by calling the ProductInfo.Details property, which contains an array of all products (books in this example) found during the search. For an ASIN search, only one book will be returned because there is a one-to-one relationship between ASIN number and book. The author search may return multiple books. Since I want the details of only one book to be displayed at a time, the first item in the Details array is accessed:

Details details = pi.Details[0];

Getting to the book's data is now as easy as calling the Details object's properties. For example, to get pricing information you can use the ListPrice and OurPrice properties:

//Pricing properties return a "$" 
//sign so remove that before 
//converting to a double
double listPrice = Convert.ToDouble(
        details.ListPrice.Substring(1));
double ourPrice = Convert.ToDouble(
        details.OurPrice.Substring(1));

//Calculate amount and percentage 
//saved over list price
double saved = listPrice - ourPrice;
double savedPercent = 
        saved/listPrice;

These values (along with others such as Author, book URL, book image, and so on) can then be bound to Label Web server controls in the User Control (see Listing 4). The returned values can then calculate how much buying a book through Amazon.com saves someone over the list price of the book as well as the percentage amount saved. You can see an example of the output generated by binding different property values to Label server controls (see Figure 3).

 
Figure 3. Calculating Purchase Savings.

After you access a book's information through the Amazon.com Web service, you can then access any other books written by the author and display them by calling the AuthorSearchRequest() Web service method. In cases where a book has multiple authors (as in the one shown in Figure 3) the first author's name is used to make this call. Note that calling the AuthorSearchRequest() method to get the other books is only necessary when the User Control is passed the ASIN number for a single book. When passed the author name instead, all of the other books written by the author are already accessible from the ProductInfo Details property array.

You can see how to detect what information was initially passed to the User Control (either ASIN number or author name) and how you can use this information to write out other books by a book's lead author (see Listing 5). A link to each book found is added using a HyperLink server control generated from a method within the AddBookHyperLink() User Control:

private void AddBookHyperLink(
        string bookName, 
        string bookURL) {
        HyperLink hl = new HyperLink();
        hl.Text = bookName;
        hl.NavigateUrl = bookURL + "/" + 
                associateKey;
        hl.CssClass = "link";
        hl.Target = "_blank";
        phOtherBooks.Controls.Add(
                new LiteralControl("<li>"));
        phOtherBooks.Controls.Add(hl);
        phOtherBooks.Controls.Add(
                new LiteralControl("</li>"));
}
Back to top

Printer-Friendly Version











Java Pro | Visual Studio Magazine | Windows Server System Magazine
.NET Magazine | Enterprise Architect | XML & Web Services Magazine
VSLive! | Thunder Lizard Events | Discussions | Newsletters | FTP Home