< web  portfolio >

Brenda C. Mondragon

< Main Page >


ASP.NET :: Consume Amazon Web Services


An example of consuming a web service (provided by Amazon.com) on an ASP.NET web site.


The functionality is encapsulated in a web user control which can be re-used multiple times on multiple pages throughout a site. The particular queries to send to Amazon.com are contained in an XML file, and the data can be cached for a specified amount of time.

Including the user control in a page is as simple as:


<%@ Register TagPrefix="uc" TagName="amazon_search" Src="/common/controls/uc_amazon_search.ascx" %>
<uc:amazon_search id="uc_amazon_search" runat="server" xmlqueryfile="/data/publications/amazon_queries.xml" />

This shows a simple example of the XML "query file" which the user control reads from:


<?xml version="1.0" encoding="utf-8" ?>
<amazon associatetag="....." subscriptionid="....." showcachedatetime="true" cachehours="6">
  <keywords keywords='school testing' power='false' searchindex='Books' sort='salesrank' />
</amazon>

A (very) small sample of code from the user control which creates an appropriate object (based upon code provided by Amazon) and grabs the Amazon Web Services ("AWSECommerceService") response:


  ItemSearchResponse response;
  AWSECommerceService aws = new AWSECommerceService();
  ItemSearchRequest request = new ItemSearchRequest();
  if (this.strSubscriptionId == null || this.strSubscriptionId == string.Empty) { throw new Exception("Amazon Web Services : SubscriptionId is Required"); }
...
  ItemSearch itemSearch = new ItemSearch();
  itemSearch.AssociateTag = strAssociateTag;
  itemSearch.SubscriptionId = strSubscriptionId;
  itemSearch.Request = requests;

  response = null;
  try
  {
    response = aws.ItemSearch(itemSearch);
...

Categories:



< Main Page >

This portfolio powered by Blosxom

All content Copyright © 1995 - 2024 Brenda C. Mondragon