Requesting Services with SOAP

Let's assume we have two web services: Web Service A and Web Service B. Each web service is an application running on a dedicated server. Let's also assume that Service B implements a simple customer lookup service, which accepts an integer number that represents the customer identifier and returns two fields in an array: the name of the customer and the contact telephone number. Service A is an application that acts as a client and requests details from Service B.

When Service A (wants to find out details about the customer. it constructs the SOAP message shown in Listing 2-2 and sends it to Service B as an HTTP POST request.

Listing 2-2. A SOAP request message

<?xml version="1.0" encoding="UTF-8" ?> <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema"> <SOAP-ENV:Body>

<ns1:getCustomerDetails xmlns:ns1="urn:CustomerSoapServices">

<param1 xsi:type="xsd:int">213307</param1> </ns1:getCustomerDetails> </SOAP-ENV:Body> </SOAP-ENV:Envelope>

Next, Service B (server) would perform the lookup, encapsulate the result in an SOAP message and send it back. The response message (Listing 2-3) would be served as an HTTP response to the original POST request.

Listing 2-3. A SOAP response message

<?xml version="1.0" encoding="UTF-8" ?> <SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Body>

<ns1: getCustomerDetailsResponse xmlns:ns1="urn:CustomerSoapServices"

SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <return xmlns:ns2="http://schemas.xmlsoap.org/soap/encoding/"

xsi:type="ns2:Array"

ns2:arrayType="xsd:string[2]">

<item xsi:type="xsd:string">John Palmer</item> <item xsi:type="xsd:string">+44-(0)306-999-0033</item> </return> </ns1:getCustomerDetailsResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope>

As you can see from the example, SOAP conversation is very chatty. All that extra information (including namespace definitions and field data types) is required so that both client and server know how to parse and validate data.

Was this article helpful?

0 0

Post a comment