Introduction
This is a demonstration of web services using Amazon.com's implementation.
Web services can be thought of as the transaction processing equivalent of the world wide web. The web provided a relatively easy and standardized way to create distributed hypertext. Web Services is a set of standards which aims to provide easy and standardized distributed transaction processing.
Just as the web trades off functionality and efficiency for ease of use, so does web services. It is not yet clear if this is a tradeoff which applications developers are willing to make. Applications like the simple one show below are easy to produce, but how much harder will more complex applications be?
Simple Web Services Query
In this example a request is made via HTTP to the Amazon.com database, for books with the keywords "tom worthington". Click on the request to run the transaction:
Search for books with "tom" and "worthington"
What the request contains
Request Description http: Address of the service: xml.amazon.com/onca/xml3 dev-t= Identifier of business partner KeywordSearch= Search for "tom" and "Worthington" mode=books Search for books. type=lite Use the lite transaction type page=1 Display the first set of records (by default 10) f=xml Return the results in XML format
Results in XML
The results are returned formatted in XML. A sample of the output is available, if you can't get the query to run.
The result is an XML document, containing data from the Amazon.com database:
<Asin>0759614245</Asin>
<ProductName>Universal Service: Telecommunications Policy
and People With Disabilities</ProductName>
<Catalog>Book</Catalog>
<Authors>
<Author>Michael J. Bourk</Author>
<Author>Tom Worthington</Author>
</Authors>
<ReleaseDate>January, 2001</ReleaseDate>
<Manufacturer>1stBooks Library</Manufacturer>
<ImageUrlSmall>http://images.amazon.com/images/
P/0759614245.01.THUMBZZZ.jpg</ImageUrlSmall>
This data can then be used as input to another transaction.
Web Services Metadata
Amazon provide the choice of two subsets of data ("lite" and "heavy"), with the metadata in two formats:
- DTD:
- XML Schema:
A SOAP interface is also supplied <http://soap.amazon.com/schemas2/AmazonWebServices.wsdl>. This provides a set of operations, including "KeywordSearchRequest", but is not used for this demonstration.
Metadata as a DTD
The DTDs and XML Schemas represent the same metadata in different formats:
DTD:
<?xml version="1.0" encoding="UTF-8"?> ...
<!-- ...................................................................... -->
<!-- File: developer-lite.dtd -->
<!-- ...................................................................... -->
<!-- DTD for developer.amazon.com xml -->
<!ELEMENT ProductInfo (Details*, ShoppingCart?, ErrorMsg?)>
<!ATTLIST Details url CDATA #REQUIRED >
<!-- url is the url of the product page -->
<!ELEMENT Artist (#PCDATA)>
<!ELEMENT Artists (Artist+)>...
Metadata as XML Schema
<?xml version="1.0" encoding="UTF-8" ?> -
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:element name="Actor" type="xs:string" /> <xs:element name="Artist" type="xs:string" />
- <xs:element name="Artists">
- <xs:complexType> - <xs:sequence>
<xs:element ref="Artist" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
...
The XML Schema is easier to use in an automated system, but DTDs are older and so more widely supported at present.
XML to HTML transformation
The XML produced from the Amazon.com database is intended as input to another system, rather than being displayed directly. To make it easier to display on a conventional (HTML) web page, Amazon provide a process for transforming the XML output into HTML, using a XSL style sheet supplied as part of the request. The only change to the query is to replace the "xml" of the format ("f=xml") with the specific address of the XSL transformation document.
A example XML to HTML transformation document (based on one provided by Amazon) is available: http://www.tomw.net.au/2002/ws/simple.xsl
With this XSL definition, the transaction becomes:
A sample of the output is available, if you can't get the query to run.
Creation of HTML by XSLT
The XSL stylesheet creates some static HTML, such as the document title:
<title>Some Books From Amazon.com</title>.
For each book found, it extracts details, such as the product identifier (Asin), URL of an image of the product (ImageUrlMedium) and ProductName :
...
<xsl:template match="Details">
<p>
<a href="http://www.amazon.com/exec/obidos/ASIN/{Asin}/universalservice">
<img src="{ImageUrlMedium}" width="107" height="140" align="left" alt=""/>
<xsl:value-of select="ProductName"/></a>...
Data values are substituted
The data values are substituted into the HTML code to produce:
<a href="http://www.amazon.com/exec/obidos/ASIN/0759614245/universalservice"><img src="http://images.amazon.com/images/P/0759614245.01.MZZZZZZZ.jpg" width="107" height="140" align="left" alt="">Universal Service: Telecommunications Policy and People With Disabilities</a>,
Data values substituted
In this case:
Field | Value |
---|---|
Asin | 0759614245 |
ImageUrlMedium | http://images.amazon.com/images/P/0759614245.01.MZZZZZZZ.jpg |
ProductName | Universal Service: Telecommunications Policy and People With Disabilities |
Web browser renders HTML with images
When rendered by a web browser, the HTML will produce an image of the cover of the book, the book title, with a hypertext link to the item on the Amazon web site:
Universal Service: Telecommunications Policy and People With Disabilities,
Some points to note
- Small Transactions: The web pages generated display images, but these images are not processed as part of the XML transaction. The URLs of the images are extracted from the database and included in the HTML. It is the end-user's browser which then requests the image file, based on the URLs. The result is that a relatively small XML transaction can produce a large and impressive looking web page.
- Caching: For efficiency the Amazon server currently caches the XSL file for six hours. If testing a changed XSL file, it is therefore necessary to save it with another name to see the effect of changes immediately.
- Format: The XML or HTML generated can be specified to conform whatever design is required.
- Efficiency: The XML format used by Web Services is relatively inefficient compared to binary formats used by traditional database systems. The XML data may be compressed while in transit on a network, but must be created at one end and interpreted at the other, consuming system resources.
- Security: This example provides no security to ensure the transaction is from an authorized usrer, is to the authorized web service and that data in transit has not been tampered with. There are a number of security models proposed for web services.
Acknowledgements
Thanks to Steve Jenkin and Frank van Praag for getting the XSL to work.