Tutorial : Amazon Commerce WSDL

Page Status: Beta

Back to Tutorials

Contents

[edit] Amazon Commerce WSDL

In this tutorial you build a solution that incorporates Amazon’s Commerce WSDL. The completed solution lets you do the following:

  • Type a product search term into a text box and receive back from the Amazon service a list of matching products.
  • Drag a product into a saved-product area (like a shopping cart).

[edit] Prerequisites

This tutorial requires an Amazon Access Key ID for the Amazon WSDL. Also, it assumes some familiarity with Bungee Builder. You can sign up for Amazon's WSDL at aws.amazon.com.

[edit] Related Resources

[edit] How to use this Tutorial

This tutorial is written for developers that are somewhat familiar with the basics of Bungee Builder. If you would like more detailed steps on working inside Bungee Builder, check out the Introduction to Bungee Builder and Hello World Tutorial before proceeding with this tutorial.

Throughout this tutorial, there are links to reference documentation on Bungee concepts:

  • Most numbered steps link to the relevant document on how to accomplish the given task. Use these links for more information on how to perform a given task (for example, how to add a class to a project).
  • Beneath the steps are links to the relevant concept documents. Use these links for conceptual information on the object being used (for example, what is a class?).

[edit] Procedure

  1. Create a new solution and TypeLib

    (Concept: Understanding Solutions and Projects)

    1. Solution name: AmazonECS
    2. Project type: TypeLib
    3. Project name: AmazonECS
  2. Create a WSDL project (import the Amazon WSDL)

    (Concept: Understanding Solutions and Projects)

    1. Project name: AmazonECSvc
    2. Project type: WSDL
    3. WSDL address: http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl?
  3. Add a class to the AmazonECS project

    (Concept: Understanding Classes)

    1. Name: clsAmazon (contains the fields, functions, and forms for the project)
  4. Add fields to clsAmazon

    (Concept: Understanding Fields)

    1. string keywords (Contains the product search term entered by the user)
      1. Type: string (this is the default type)
    2. Item selectedProduct (Contains the product currently selected from the list of products returned by the Amazon service or in the savedProducts list)
      1. Type: Item (select Class: Item under WSDL: AmazonECSvc)
    3. Collection(Item): savedProducts (Contains a collection of product terms to be saved in the shopping cart area of the form)
      1. Type: Item (select Class: Item under WSDL: AmazonECSvc)
      2. Select the Is Collection property
    4. Collection(Item): searchResults (Contains the response from the service call)
      1. Type: Item (select Class: Item under WSDL: AmazonECSvc)
      2. Select the Is Collection property
    5. AWSECommerceService amazonECS (The object (field) that references the WSDL project--makes all the functions from the WSDL available in the project)
      1. Type: AWSECommerceService (select SoapClass: AWSECommerceService under WSDL: AmazonECSvc)
  5. Add a function to clsAmazon

    (Concept: Understanding Functions)

    1. Name: ECSSearch
    2. Purpose: Calls the Amazon Web service.
  6. Edit the ECSSearch function

    (Concept: Understanding Bungee Logic)

    1. Add var statements
      1. var ItemSearchResponse varItemSearchResponse
        1. Name: varItemSearchResponse
        2. Type: Class: ItemSearchResponse (under WSDL: AmazonECSvc)
      2. var ItemSearch varItemSearch = new ItemSearch
        1. Name: varItemSearch
        2. Type: Class: ItemSearch (under WSDL: AmazonECSvc)
        3. Default Value: Object
        4. For the new object, set ItemSearchRequest Request[int] to Collection
      3. var ItemSearchRequest varItemSearchRequest = new ItemSearchRequest
        1. Name: varItemSearchRequest
        2. Type: Class: ItemSearchRequest (under WSDL: AmazonECSvc)
        3. Default Value: Object
        4. In new object, set public Collection(string) ResponseGroup to Collection
    2. Add assignment statements
      1. varItemSearch.AWSAccessKeyId = 'your-access-key-goes-here'
        1. Left side:
          1. Type = Var
          1. Select string AWSAccessKeyId (under ItemSearch var ItemSearch)
        2. Right side:
          1. Type = Data
          2. Type your Amazon access key as the value
      2. varItemSearchRequest.Keywords = keywords
        1. Left side:
          1. Type = Var
          2. Select string Keywords (under ItemSearchRequest varItemSearchRequest)
        2. Right side:
          1. Type = Path
          2. Select string keywords
      1. varItemSearchRequest.SearchIndex = 'Blended'
        1. Left side:
          1. Type = Var
          2. Select string SearchIndex (under ItemSearchRequest varItemSearchRequest)
        2. Right side:
          1. Type = Data
          2. Type Blended as the value ("Blended" returns products across all categories. You could limit the search to DVDs, music, books, etc. See the service documentation for more information.)
    3. Add call function statements
      1. searchResults.removeAll(void)
        1. Type = Path
        2. Select Function: removeAll (under Collection(Item): searchResults)
      2. varItemSearchRequest.ResponseGroup.add('ItemIds')
        1. Type = Var
        2. Select Function: add (under ItemSearchRequest varItemSearchRequest >Collection(string): ResponseGroup)
        3. Parameter:
          1. Type = Data
          2. Type ItemIds as the value
      3. varItemSearchRequest.ResponseGroup.add('ItemAttributes')
        1. Type = Var
        2. Select Function: add (under ItemSearchRequest varItemSearchRequest >Collection(string): ResponseGroup)
        3. Parameter:
          1. Type = Data
          2. Type ItemAttributes as the value
      4. varItemSearchRequest.ResponseGroup.add('Images')
        1. Type = Var
        2. Select Function: add (under ItemSearchRequest varItemSearchRequest >Collection(string): ResponseGroup)
        3. Parameter:
          1. Type = Data
          2. Type Images as the value
      5. varItemSearch.Request.add(varItemSearchRequest)
        1. Type = Var
        2. Select Function: add (under ItemSearch varItemSearch > Collection(ItemSearchRequest): Request)
        3. Parameter
          1. Type = Var
          2. Select ItemSearchRequest varItemSearchRequest
      6. amazonECS.ItemSearch(varItemSearch,varItemSearchResponse)
        1. Type = Path
        2. Select SoapFunction: ItemSearch under AWSECommerceService amazonECS)
        3. First parameter
          1. Type = Var
          2. Select ItemSearch varItemSearch
        4. Second parameter
          1. Type = Var
          2. Select ItemSearchResponse varItemSearchResponse
    4. Add a collection iteration
      1. For each CurrentElement in varItemSearchResponse.Items
        1. Type = Var
        2. Select Collection(Items): Items (under ItemSearchResponse varItemSearchResponse)
      2. Inside collection iteration add a call function
        1. searchResults.addCollection(CurrentElement.Item)
          1. Type = Path
          2. Select Function: addCollection under Collection(Item): searchResults)
        2. Parameter
          1. Type = Var
          2. Select Collection(Item): Item (under Items CurrentElement)
  7. Add a form to clsAmazon

    (Concept: Understanding Forms)

    1. Name: frmSearch
    2. Layout: 3 rows x 2 columns (the controls are added in Step 8, below)
      1. Top row--one column: Will contain a HorizontalBox control, in which a TextEdit control (for product term entry) and a Button (to initiate the function that gets the product list) will be placed.
      2. Center row--two columns: Will contain a DynamicForm control in the left column and a DynamicFormList control in the right column).
      3. Bottom row---one column: Will contain an HTML control.
  8. Add and bind controls to the form

    (Concept: Understanding Forms)
    (Concept: Understanding Controls)

    Note A DynamicForm is used in this tutorial to facilitate making changes in the next tutorial (where a displayed form is selected among several possible forms). If selection among multiple forms was not being implemented, you could use a DynamicFormList control instead of the DynamicForm control.

    1. HorizontalBox
      1. Location: Top row
      2. Binding: None
    2. TextEdit
      1. Location: Left side of top row (in the HorizontalBox container)
      2. Binding: string keywords
    3. Button
      1. Location: To the right of the TextEdit control (in the HorizontalBox container)
      2. Label (Button Label property): Search
      3. Binding: ECSSearch
    4. DynamicForm
      1. Location: Left column of second row (display the DynamicFormList)
      2. Bind to clsAmazon
      3. Select Show Border (under Style)
      4. Add a form adapter to connect the DynamicForm control and the frmDFL form (frmDFLAdapter)
        1. Add adapter to: TypeLib: AmazonECS
        2. Name: frmDFLAdapter
        3. Type: Form Adapter
      5. Add connection to clsAmazon (DynamicFormConnection: DynamicFormAdapter)
        1. Add connection to: clsAmazon
        2. Select ConnectionAdapter: DynamicFormAdapter (under TypeLib: AmazonECS > Dependencies > Runtime > TypeLib: ControlAdapter)
        3. Set public formAdapter to FormAdapter: DFLAdapter
        4. Select Linked
    5. DynamicFormList
      1. Location: Right column of second row
      2. Binding: Collection(Item): savedProducts
      3. Select Show Border (under Style)
      4. Implement Drop Zones (under Behavior)
        1. For Name, type DFLResults (this name can be any name you like, but it must match the name used for the Drag Zone in Step 9, below)
        2. For Action, select copy
    6. HTML
      1. Location: Bottom row
      2. Binding: string DetailPageURL (under Item selectedProduct)
  9. Add a form for the DynamicForm control

    (Concept: Understanding Forms)
    (Concept: Understanding Adapters and Connections)
    (Concept: Understanding Controls)

    Because you're using a DynamicForm control, you must define a form for the DynamicForm control to display.

    1. Add form to clsAmazon
      1. Name: frmDFL
      2. Layout: one row by one column
    2. For Adapter List property, add the frmDFLAdapter adapter (under TypeLib: AmazonECS)
    3. Add DynamicFormList control to form (bind to Collection(Item): searchResults)
    4. Define Drag Zone (under Behavior)
      1. For Name, type DFLResults (if you used a differenet name in Step 8E, above, be sure to use it here instead of DFLResults)
      2. For Action, select copy
  10. Bind selection (add connection) for the DynamicFormList controls

    (Concept: Understanding Adapters and Connections)

    You bind the selection for the DynamicFormList controls so that the selected object is "captured." In binding the selection, the Bungee automatically implements an adapter for the control by instantiating a connection. For the connection, you then set where the selected element will store the object, in this case it will be stored in the selectedProduct field (created earlier). Because the field is set to the same type as the response from the service, the entire object will be stored in this field. Even though you may not select or even display all the elements that are a part of that object, they are still being placed into this field. For example, your form is not displaying the URL for the detail page, but it is being stored in this field and used by the HTML control.
    1. In frmSearch, select either of the DynamicFormList controls.
    2. Click the green button in the upper, right corner and select Bind Selection. The adapter opens in the Design pane.
    3. Select Object selectedElement (in the Design Editor).
    4. In the Property Editor, click the ellipsis button next to Path. In the dialog box that's displayed, select Item selectedProduct.
    5. In the Property Editor, select Linked.
  11. Add form to Item (in the WSDL project) for display within the DynamicFormList controls

    (Concept: Understanding Forms)
    (Concept: Understanding Controls)

    Because the DynamicFormList control only displays forms, you must define a form for the controls to display. Add a form to the Item Class (in the WSDL project).
    1. Add form (to the Item class under the WSDL project)
      1. Name: frmResults
      2. Layout: one row by one column
      3. Add Label (bind to ItemAttributes.Title under WSDL: AmazonECSvc)
  12. Add a form adapter for the DyanmicFormList controls

    (Concept: Understanding Adapters and Connections)

    1. Add adapter to: TypeLib: AmazonECS
    2. Name: frmResultsAdapter
    3. Type: Form Adapter
    4. For frmResults
      1. For the Adapter List property, add frmResultsAdapter (under TypeLib: AmazonECS)
    5. For frmDFL
      1. Set the Element Form property (under Adapter) to frmResultsAdapter for both DynamicFormList controls
  13. Run the form

    (Concept: Understanding Simulate)

    1. In the text box, type a keyword, such as golf and click Search.
    2. Drag keywords from the left side to the right side. As you select new words, the Web page for the word is shown at the bottom of the form.
  14. Additional modifications
    1. Add a Remove button to the saved-keywords area (Hint: Expand savedProducts to locate the remove function)
    2. Add a Remove All button to the saved-keywords area
    3. Add a Saved form with a notes capability to the DynamicFormList control used for saved keywords
    4. Modify the forms so that the form displaying the results and the form displaying the saved items display the data in different ways (e.g., a smaller picture in one of the forms).

 

    Copyright © 2005 - 2007 Bungee Labs. All rights reserved.