To illustrate what SOAP messages look like, we'll show an example of a web service used by an online retailer that accepts a unique product identifier and returns details about the product such as the name, description, price, and availability. Listing B-7 shows an example of such a service called GetProductDetails that accepts one parameter called ProductID. The Envelope namespace will always point to http://schemas.xmlsoap.org/soap/envelope, as described in the specification.
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <getProductDetails xmlns="http://www.quickreturns.com/ws"> <productID>5820948</productID> </getProductDetails> </soap:Body> </soap:Envelope> |
The response from the service also has the same structure of an envelope with the two headers. Listing B-8 shows an example of what the response of the previous GetProductDetails will contain. In this example, the service sends some additional attributes such as Product Name, Description, Price, and a Boolean stating whether the product is in stock.
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <getProductDetailsResponse xmlns="http://www.quickreturns.com/ws"> <getProductDetailsResult> <productName>Wireless Keyboard</productName> <productID>123321</productID> <description>RF Wireless Keyboard, available in Black</description> <price>96.50</price> <inStock>true</inStock> </getProductDetailsResult> </getProductDetailsResponse> </soap:Body> </soap:Envelope> |