«^»
6.4. Communicating with a Web Service (SOAP)

If an external site wishes to contact a Web Service in order to get some method executed, it needs to indicate to the Web Service the name of the method and the arguments to be passed to the method. And the external site is expecting the Web Service to return a value to the external site.

As a Web Service is being hosted on a webserver, the obvious way of contacting a Web Service is to send an HTTP request to the webserver. In fact, the usual way of contacting a Web Service is to send the webserver an HTTP POST request where the body of the request is coded using an XML language called SOAP (Simple Object Access Protocol) [50]. The reply from the Web Service is sent as an HTTP reply usually with a body coded in SOAP.

If you return to the WWW page containing the zipcode textbox and the Invoke button, i.e. to:
http://www.winisp.net/cheeso/zips/ZipService.asmx?op=ZipTo1CityAndState
you will see this WWW page also gives an example of the HTTP request that can be used to contact the Web Service and an example of the HTTP reply that comes back from the Web Service.

An example of an HTTP request to this Web Service is:

0151: POST /cheeso/zips/ZipService.asmx HTTP/1.1
0152: Host: www.winisp.net
0153: Content-Type: text/xml; charset=utf-8
0154: Content-Length: XXXX
0155: SOAPAction: "http://dinoch.dyndns.org/webservices/ZipTo1CityAndState"
0156: 
0157: <?xml version="1.0" encoding="utf-8"?>
0158: <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
0159:                xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
0160:                xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
0161:   <soap:Body>
0162:     <ZipTo1CityAndState xmlns="http://dinoch.dyndns.org/webservices/">
0163:       <zip>94042</zip>
0164:     </ZipTo1CityAndState>
0165:   </soap:Body>
0166: </soap:Envelope>

The body of this HTTP POST request is written using the notation of the XML language called SOAP. Hiding in all this detail is the fact that we want to contact a webserver on the computer www.winisp.net to visit the page at /cheeso/zips/ZipService.asmx to execute the ZipTo1CityAndState method with an argument having the name zip and value 94042.

The reply from the webserver (after the appropriate method has been executed) is likely to have a body coded using SOAP. An example of a reply from www.winisp.net is:

0167: HTTP/1.1 200 OK
0168: Content-Type: text/xml; charset=utf-8
0169: Content-Length: YYYY
0170: 
0171: <?xml version="1.0" encoding="utf-8"?>
0172: <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
0173:                xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
0174:                xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
0175:   <soap:Body>
0176:     <ZipTo1CityAndStateResponse 
0177:           xmlns="http://dinoch.dyndns.org/webservices/">
0178:       <ZipTo1CityAndStateResult>MOUNTAIN VIEW CA</ZipTo1CityAndStateResult>
0179:     </ZipTo1CityAndStateResponse>
0180:   </soap:Body>
0181: </soap:Envelope>
Hidden away in this XML is the fact that the result of the call is the value MOUNTAIN VIEW CA.

Even though the communication between the external site and the Web Service is coded in SOAP, normally we need not be concerned with the hard work of encoding and decoding the request and the reply: we will find that all of this is done by supporting software.