Listing 1: Amazon-search-simple.cfm

<!---
Name: amazon-search-simple.cfm
Author: Charlie Arehart, in ColdFusion Dev Journal, Apr 2003
Desc: Uses a URL variable called "keyword" to do a search of the Amazon site using Amazon Web Services.


If none is provided, presumes a search of "ColdFusion" by default.
Notes: This is a very simple example. A more complete example is offered as amazon-search-enhanced.cfm.
--->
<cfparam name="url.keyword" default="ColdFusion">
<cfscript>
aKeywordRequest = structnew();
aKeywordRequest.devtag="yourtag";
aKeywordRequest.keyword=url.keyword;
aKeywordRequest.mode="books";
aKeywordRequest.page="1";
// aKeywordRequest.sort="+salesrank";
aKeywordRequest.tag="webservices-20";
aKeywordRequest.type="lite";
</cfscript>
<cfinvoke
webservice=
"http://soap.amazon.com/schemas2/AmazonWebServices.wsdl"
method="KeywordSearchRequest"
returnvariable="aProductInfo">
<cfinvokeargument name="KeywordSearchRequest"
value="#aKeywordRequest#"/>
</cfinvoke>


<cfoutput>
Total Found: #aProductInfo.TotalResults#<br>
Searched for: #url.keyword#
</cfoutput>
<table border="2">
<tr><td></td><td><strong>Title</strong></td><td>
<strong>Author</strong></td></tr>
<cfoutput>
<cfloop index="i" from="1" to="#arraylen(aProductInfo.details)#"
step="1" >
<tr>
<td><img src="#aProductInfo.details[i].ImageUrlSmall#"></td>
<td>#aProductInfo.details[i].ProductName#</td>
<td>#aProductInfo.details[i].authors[1]#</td>
</tr>
</cfloop>
</cfoutput>
</table>




Listing 2: Some of the SOAP XML for AWS

<wsdl:definitions xmlns:typens="http://soap.amazon.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/"
targetNamespace="http://soap.amazon.com" name="AmazonSearch">
<wsdl:types>
<xsd:schema xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://soap.amazon.com">
<xsd:complexType name="ProductLineArray">
<xsd:complexContent>
<xsd:restriction base="soapenc:Array">
<xsd:attribute ref="soapenc:arrayType" wsdl:arrayType="type
ns:ProductLine[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="ProductLine">
<xsd:all>
<xsd:element name="Mode" type="xsd:string" minOccurs="0"/>
<xsd:element name="ProductInfo" type="typens:ProductInfo"
minOccurs="0"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="ProductInfo">
<xsd:all>
<xsd:element name="TotalResults" type="xsd:string"
minOccurs="0"/>
<!-- Total number of Search Results -->
<xsd:element name="TotalPages" type="xsd:string"
minOccurs="0"/>
<!-- Total number of Pages of Search Results -->
<xsd:element name="ListName" type="xsd:string" minOccurs="0"/>
<!-- Listmania list name -->
<xsd:element name="Details" type="typens:DetailsArray"
minOccurs="0"/>
</xsd:all>
</xsd:complexType>

<!--- There is much more. View it by entering http://soap.amazon.com/schemas2/AmazonWebServices.wsdl into a browser--->




Listing 3: An Enhanced Example

<!---
Name: amazon-search-enhanced.cfm
Author: Charlie Arehart, in ColdFusion Dev Journal, Apr 2003
Desc: Uses a URL variable called "keyword" to do a search of the Amazon site using Amazon Web Services.

If none is provided, presumes a search of "ColdFusion" by default.
Notes: This is an enhanced example as compared to the simpler example offered as amazon-search-simple.cfm.

This version performs scrolling through records and shows handling multiple or zero authors.


There are still more things that could be done, such as having a form for inputs and controlling other aspects like the page, etc.


It could also perform caching of the Web service, so as not to visit it too often when data may not change.


This isn't a trivial problem, but it is one worth exploring.

--->

<cfparam name="url.keyword" default="ColdFusion">
<cfparam name="url.page" default="1">

<cfscript>
aKeywordRequest = structnew();
aKeywordRequest.devtag="yourtag";
aKeywordRequest.keyword=url.keyword;
aKeywordRequest.mode="books";
aKeywordRequest.page="#url.page#";
// aKeywordRequest.sort="+salesrank";
aKeywordRequest.tag="webservices-20";
aKeywordRequest.type="lite";
</cfscript>

<cfinvoke
webservice=
"http://soap.amazon.com/schemas2/AmazonWebServices.wsdl"
method="keywordSearchRequest"
returnvariable="aProductInfo">
<cfinvokeargument name="KeywordSearchRequest" value="#aKeywordRequest#"/>
</cfinvoke>

<cfoutput>
Total Found: #aProductInfo.TotalResults#<br>
Searched for: #url.keyword#
</cfoutput>
<table border="2">
<tr><td></td><td><strong>Title</strong></td><td>
<strong>Author</strong></td></tr>
<cfoutput>
<cfloop index="i" from="1" to="#arraylen(aProductInfo.details)#"
step="1" >
<tr>
<td><img src="#aProductInfo.details[i].ImageUrlSmall#"></td>
<td>#aProductInfo.details[i].ProductName#</td>
<td><cftry><cfloop from="1"
to="#arraylen(aProductInfo.details[i].authors)#"
index="z">#aProductInfo.details[i].authors[z]#<br>
</cfloop><cfcatch>&nbsp;</cfcatch></cftry></td>
</tr>
</cfloop>
</cfoutput>
</table>

<cfset numpages = aProductInfo.TotalResults/10>
<cfif url.page gt 1>
<cfoutput>
&lt;<a href="#cgi.script_name#?page=#url.page-1#">prev</a>&gt;
</cfoutput>
</cfif>

<cfif numpages gt url.page>
<cfoutput>
&lt;<a href="#cgi.script_name#?page=#url.page+1#">next</a>&gt;
</cfoutput>
</cfif>