Web Services Demonstration

by Tom Worthington FACS

Director, TomW Communications Pty Ltd and Visiting Fellow, Australian National University

For: Australian National University students of Metadata and Data Management

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"

http://xml.amazon.com/onca/xml3?locale=us& amp;t=universalservice&dev-t=D1XUYSABAOWG8G&
KeywordSearch=tom%20worthington&mode=books&
sort=+pmrank&offer=All&type=lite&page=1&f=xml

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:

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:

http://xml.amazon.com/onca/xml3?locale=us&t=universalservice&dev-t=D1XUYSABAOWG8G&
KeywordSearch=tom%20worthington&
mode=books&sort=+pmrank&offer=All&
type=lite&page=1&
f=http://www.tomw.net.au/2002/ws/simple.xsl

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

Acknowledgements

Thanks to Steve Jenkin and Frank van Praag for getting the XSL to work.

See also:

http://www.tomw.net.au/2004/dm/index.html (2 August 2004).
Copyright © Tom Worthington 2002-2004.

ANU No Ads.