Click here to Skip to main content
13,699,815 members
Click here to Skip to main content
Add your own
alternative version


39 bookmarked
Posted 10 Sep 2003

Implementing Amazon Web Services in VB.NET

, 10 Sep 2003
Rate this:
Please Sign up or sign in to vote.
Article shows implementing Amazon web service in VB.NET.


Web services are some of the most exciting emerging technologies. Web services in general means services offered via the web. They are the new service-oriented approach to programming. Web services are based on building applications by discovering and implementing available  services or invoking available applications to complete a task.

In this article we are going to learn to implement keyword searching, the default searching capability when you go to Moreover we will utilize the SOAP option that allows Amazon web services to be accessed through SOAP requests and responses providing a more object-oriented approach to integrate data into your application. The documentation for the Amazon Web service is available at Amazon in the developer's kit.

For the purpose of this article you will need the .NET framework installed, you will need a free token (license key) from Amazon, which you can get here. (Make sure to read the Terms of Service before signing up for the token.) Moreover you will need Visual Studio .NET if you want to experiment with source code presented in this article.

Getting started

Open your Visual Studio .NET, create a new ASP.NET Web Application Project, which we will call amazonproject, click OK as shown in figure 1.

Figure 1: Creating a web application

Adding Web Reference

Now we will add the web reference to the Amazon web service. A web reference enables a project to consume one or more web services. It creates the proxy class needed to communicate with the web service. From the Project menu click Add Web References. The Add Web Reference dialog box opens. Enter the address to the web service in the address bar (case sensitive). After you enter the URL, press Enter and the Amazon web service gets loaded and its information is shown in the dialog box as shown in figure 2. Moreover the Add Reference button will be enabled.

Figure 2: Adding Web Reference

Click the Add Reference button to add this web reference to our project. (If you don’t have Visual Studio .NET you will have to use command line wsdl.exe to generate the proxy class.)

Now in the Solution Explorer, expand the Web References folder to note the namespace ( for the Amazon Web reference classes. For programming ease, right click on the web reference and rename it to Amazon.

Creating a web form

The first step to creating the Web form is to change the default name of the page from the WebForm1.aspx to AmazonService.aspx. Simply right click over the name in the Solution Explorer and choose Rename from the popup menu. Then you may enter the new name over the old name. Visual Studio.NET supports a drag and drop design tool that helps you layout your Web page quickly. In our case three Label, two TextBox, one DataGrid and a button elements were dragged from the Web Forms toolbox on the left side of the screen onto the Web form and arranged. Modify the properties of the controls to reflect as below.

Label1lblKeywordSearchKeyword Search

The final web form will look like that shown in the figure 3.

Figure 3: Web Form

You will have to enter keyword and mode from the user interface in order to do the search. Example of input parameters are keyword: Java and mode: books.

Invoking the Web service

Now we can proceed to write the logic to call the web service. The logic will reside in the button click method. The logic of button click is presented below:

Private Sub Search_Click(ByVal sender As Object, _
     ByVal e As System.EventArgs) Handles Search.Click

   ' Variable to Store the Token Key 
   Dim TokenKey As String

   ' Declare variable for the amazon search service object 
   Dim Service As Amazon.AmazonSearchService = New _

   'Declare variable for KeywordRequest which is the object 
   'for the search request
   Dim keyword As Amazon.KeywordRequest = New Amazon.KeywordRequest()

   ' Declare variable for the amazon Search Result 
   Dim ProductInformation As Amazon.ProductInfo

   ' Please Type your token key here 

    'Fill in the properties of the keyword request
    keyword.keyword = txtKeyword.Text 'what you are searching
    keyword.mode = txtMode.Text 'amozon product line = 1 'page you want
    keyword.tag = "webservices-20" 'affiliate tag
    keyword.type = "lite" 'lite or heavy type
    keyword.devtag = TokenKey 'token key

    'Initiate the search
     ProductInformation = Service.KeywordSearchRequest(keyword)

     'Transform productInformation to DataSet
     Datagrid1.DataSource = TransformToDataSet(ProductInformation)
   End Sub

Lets step through the above code. To make a SOAP request, create an instance of AmazonSearchService. Next create the KeyRequest instance for the KeywordSearchRequest to be performed. Fill the properties of the KeywordRequest object. The properties and descriptions are outlined below. The keyword and mode property, the user will fill in through user interface.

KeywordWhat you are searching for
ModeAmazon product line like books, music.
PageAn integer indicating the number of pages that the search request returns.
TypeSet the type Lite or Heavy. Indicates the amount of XML data returned to you
Affiliate TagYour Affiliate tag, if you don’t have one use webservices-20
Dev-tagYour token information

Finally invoke the KeywordSearchRequest passing the KeywordRequest object to it. The invocation returns ProductInfo object. Then transfer the ProductInfo information to a DataSet. Finally bind the dataset to the DataGrid so that information can be easily displayed to the user. Below code outlines how the returned ProductInfo object information is transferred to DataSet.

Function TransformToDataSet(ByVal productInfo As_
      Amazon.ProductInfo) As DataSet

  'Create the instance of dataset
  Dim ds As DataSet = New DataSet()

  'Create the headers

  'Get the Details object collection from
  'productInfo object
   Dim detailsCollection() As Amazon.Details = _

   'Declare variables to be used in iteration
   Dim details As Amazon.Details
   Dim datarow As DataRow
   'Iterate through detail object and
   'get its properties
   For Each details In detailsCollection
      datarow = ds.Tables("ListedProducts").NewRow
      datarow("Image") = details.ImageUrlSmall.ToString()
      datarow("ProductName") = details.ProductName.ToString()
      datarow("Authors") = details.Authors(0).ToString()
      datarow("Price") = details.ListPrice.ToString()

   Return ds
End Function

Stepping through the above code we can see, that first we create the instance of DataSet to hold the data. Then we construct the header column for the information we want to display to the user. We than message the ProductInfo object and get an array of Details object from it. The Details object contains various properties about the product, the authors, the list price, image URLs (Check out the Amazon SDK documentation for details about the available properties). We than iterate through the collection of Details objects and construct each DataRow of the dataset. Additionally you would also want to put error handling when filling the DataSet.

Displaying the result

Once the data is in the dataset it can be easily displayed to the user interface using the DataGrid. Below outlined is the DataGrid code of the user interface.

<?xml:namespace prefix = asp />
<asp:datagrid id=Datagrid1 AutoGenerateColumns="False" 

CellPadding="4" BackColor="White" BorderWidth="1px" 

BorderStyle="None" BorderColor="#C00000" runat="server">

<headERSTYLE BackColor="Olive" ForeColor="#C00000" Font-Bold="True">
<FOOTERSTYLE BackColor="#FFFFCC" ForeColor="#330099"></FOOTERSTYLE>



<asp:Image id=Image1 Runat="server" ImageUrl=
  '<%# Container.DataItem("image") %>'></asp:Image>


<asp:BoundColumn HeaderText="Product" DataField="ProductName">

<asp:BoundColumn HeaderText="Author" DataField="Authors">
<asp:BoundColumn HeaderText="Price" DataField="Price">



Amazon web services are big and encapsulates various request objects like KeywordRequest, AuthorRequest, AsinRequest and more. They allow you to programmatically access the majority of features on the Amazon site.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Pratik Desai
Web Developer
United States United States
Architects softwares with emerging technologies that will save time and increase productivity.

You may also be interested in...


Comments and Discussions

Suggestionerror while adding web reference... Pin
S.K.Tripathi1-May-14 20:51
memberS.K.Tripathi1-May-14 20:51 
GeneralHTTP Error Pin
kamran8531-Jul-09 22:39
memberkamran8531-Jul-09 22:39 
GeneralRe: HTTP Error Pin
mrrcomp16-Sep-09 10:15
membermrrcomp16-Sep-09 10:15 
Questiondataset not defined????? Pin
pendo14-Apr-09 1:20
memberpendo14-Apr-09 1:20 
AnswerRe: dataset not defined????? Pin
mjk123451-Oct-09 14:47
membermjk123451-Oct-09 14:47 
GeneralAmazone Pin
mcasoni23-Jun-08 0:20
membermcasoni23-Jun-08 0:20 
GeneralRe: Amazone Pin
kamran8531-Jul-09 22:43
memberkamran8531-Jul-09 22:43 
GeneralThere is a problem for this webService Pin
Ayman Alsayed23-Aug-07 0:56
memberAyman Alsayed23-Aug-07 0:56 
GeneralVery Useful Pin
jsreekumar4-Aug-07 23:32
memberjsreekumar4-Aug-07 23:32 
GeneralThe remote name could not be resolved Pin
Lets explore it20-Jun-06 20:59
memberLets explore it20-Jun-06 20:59 
Generalerror with DataGrid asp:Image tag Pin
Beetlebub23-May-05 8:09
memberBeetlebub23-May-05 8:09 
QuestionHow to sort by Item Condition Pin
Sumit Kapoor13-Jun-04 20:21
memberSumit Kapoor13-Jun-04 20:21 
GeneralServer Error in '/amazonproject' Pin
grobb14-Jun-04 23:07
membergrobb14-Jun-04 23:07 
GeneralDisplay more search results/Search by ISBN Pin
dcmurray18-Feb-04 14:31
memberdcmurray18-Feb-04 14:31 
QuestionWhere to put DataGrid Code? Pin
MReinbold18-Nov-03 9:22
memberMReinbold18-Nov-03 9:22 
AnswerRe: Where to put DataGrid Code? Pin
Pratik Desai21-Nov-03 6:39
memberPratik Desai21-Nov-03 6:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04-2016 | 2.8.180910.1 | Last Updated 11 Sep 2003
Article Copyright 2003 by Pratik Desai
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid