oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

Creating an Application from Scratch, Part 2
Pages: 1, 2, 3, 4

Setting Up the Request

The code shown above handles the response. The actual query requires creating three objects, provided by the Amazon proxy. I downloaded (as part of their code sample) the file AWSECommerceService.cs which I placed in my App_Code directory as shown in Figure 4.

Figure 4
Figure 4. The downloaded AWSECommerceService.cs file

This gives me full access to their objects. To set up the query, I create the following member variables:

private AWSECommerceService amazonService = new AWSECommerceService();

private CustomerContentLookup customerLookup = new CustomerContentLookup();
private CustomerContentLookupRequest customerLookupRequest =
   new CustomerContentLookupRequest();
private CustomerContentLookupResponse customerLookupResponse;

private string subscriptionID = "XXXXXXXXX";
private string associateTag = "XXXXXXX";
 Example 2
  • AWSECommerceService is the service proxy.
  • CustomerContentLookup is an object used to hold my AssociateTag and SubscriptionID (assigned to me by Amazon).
  • CustomerContentLookupRequest holds the attributes of the query I want to make.

The LookupRequest object has a ResponseGroup property which is an array of strings that specify what type of response you want; in our case, based on the documentation we want CustomerFull. The code to make the inquiry is shown in Example 3:

customerLookup.AssociateTag = this.associateTag;
customerLookup.SubscriptionId = this.subscriptionID;
customerLookupRequest.CustomerId = searchCustomerTextBox.Text;
myReviewerID = customerLookupRequest.CustomerId;
int pageNumber = 1, totalPages = 1, totalReviews = 0;
lblMessage.Text = "Searching...";

while ( pageNumber <= totalPages )
   customerLookupRequest.ReviewPage = pageNumber.ToString();
   customerLookupRequest.ResponseGroup = new string[] { "CustomerFull" };
   customerLookup.Request =
      new CustomerContentLookupRequest[] { customerLookupRequest };
      customerLookupResponse =
         amazonService.CustomerContentLookup( customerLookup );
   catch ( Exception ex )
      lblMessage.Text = ex.Message;
 Example 3

The response object has a property Customers which is an array whose first member is itself an array (misleadingly called Customer). That array should have one member with a property CustomerReviews (again an array, this time of one CustomerReviews object) which has two important properties: TotalReviewPages and TotalReviews. The TotalReviewPages property is used to set the totalPages variable so that we can request all of the pages (you receive up to ten reviews per page, and up to ten pages). I haven't yet figured out what you do if the reviewer has more than 100 reviews.

This code depends on having a text box (named searchCustomerTextBox) which is filled with the user's Amazon ID. So far, all I've implemented is a test that gets all my own reviews, I haven't yet gone on to the next step of getting all CustomerIDs for all the customers who reviewed the books I reviewed, and then getting all their reviews, so of course this code will change very soon to allow a CustomerID to be passed in as a parameter.

Pages: 1, 2, 3, 4

Next Pagearrow