Web services exchange messages between a consumer (client or sender) and provider (server or receiver). The provider and consumer are called endpoints. The consumer initiates the exchange with an XML request document; the provider ordinarily returns an XML response document that contains the requested information. If the request message is malformed or the provider can't supply the requested information, a fault occurs. Like other Web-related technologies, Web services are, by definition, loosely coupled. Loosely coupled means that Web services don't rely on a permanent connection between the consumer and provider. Providers listen for incoming SOAP request messages and respond in ad hoc fashion. Windows XP/2000+ use Internet Information Server (IIS) 5.0+ and an Internet Services Application Programming Interface (ISAPI) filter to listen for incoming request messages and route the messages to the appropriate service. Thus, you can set up your own public or private services that run on Windows XP or 2000 Professional, as well as Windows 2000+ server. Web Service Standards and Specifications
Fortunately, you don't need a thorough understanding of the Web services standards and specifications to consume or provide them. WSR automates VBA code generation for Access 2003 Web service consumers. The Microsoft SOAP Toolkit 3.0+ installs an ISAPI SOAP listener for IIS 5.0+ to enable providing Web services. This Toolkit also creates SOAP 1.1 wrappers and generates WSDL files for Visual Basic 6.0 ActiveX components automatically. SOAP Message FormatsSOAP messages consist of an envelope that contains a body and optional header elements. The body contains the request or response message. Header elements typically provide message routing and security-related information for advanced Web services. Most public Web services don't include header elements; if they do, processing the header usually is optional. WSR2 can't handle mandatory headers, so this chapter's examples don't include them. Following is an example of a simplified SOAP 1.1 request message to ZipCodeResolver, a public address-correction Web service provided by EraServer.NET: <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <CorrectedAddressXml xmlns="http://webservices.eraserver.net/"> <accessCode>9999</accessCode> <address>1000 Broadway</address> <city>Oakland</city> <state>CA</state> </CorrectedAddressXml> </soap:Body> <soap:Envelope> The request message invokes a CorrectedAddressXml function (called a Web service method or Web method) that returns the address in standard US Postal Service format with five-digit and ZIP+4 ZIP codes. The Web method sends an HTTP GET request with the address, city, and state to the USPS Web site, which delivers a page that contains the corrected address in an HTML table. The service extracts the required data from the page to a public class (user-defined type) named USPSAddress, which has Street, City, State, ShortZIP and FullZIP members. The process of extracting specific pieces of data from Web pages is known as screen scraping. Transforming an instance of a class to an XML document fragment is called serialization; the reverse is deserialization. Following is the CorrectedAddressXML method's SOAP 1.1 response message: <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <CorrectedAddressXmlResponse xmlns="http://webservices.eraserver.net/"> <CorrectedAddressXmlResult> <Street>1200 BROADWAY</Street> <City>OAKLAND</City> <State>CA</State> <ShortZIP>94612</ShortZIP> <FullZIP>94612-1802</FullZIP> </CorrectedAddressXmlResult> </CorrectedAddressXmlResponse> </soap:Body> </soap:Envelope> A WSDL document defines the format of the SOAP request and response messages, and specifies the Web service's URL. There are two widely used Web service message formats rpc/encoded and document/literal. The first element (rpc or document) specifies the SOAP body's use and the second determines the message style. You determine the format of the request and response messages by inspecting the <operation> node(s) of the WSDL document, as illustrated by the following excerpt for the document/literal CorrectedAddressXml method: <operation name="CorrectedAddressXml"> <soap:operation soapAction="http://webservices.eraserver.net/CorrectedAddressXml" style="document" /> <input> <soap:body use="literal" /> </input> <output> <soap:body use="literal" /> </output> </operation>
Most early Web services employed the rpc/encoded format, which emulates a remote procedure call by encoding specific message data types in accordance with section 5 "SOAP Encoding" of the SOAP 1.1 specification. It turned out to be very difficult to assure service interoperability with the rpc/encoded format, so WS-I's Basic Profile 1.0 specification precludes its use by requiring literal as the value of the use attribute. The literal value requires that message data types conform to the W3C's XML Schema Part 2: Datatypes recommendation. The Basic Profile 1.0 permits two message formats document/literal and rpc/literal. The document/literal format is much more popular; only a few SOAP toolkits support rpc/literal messages. WSDL files for document/literal often abbreviated doc/lit services define the messages, not just datatypes, by XML schemas (XSD). All but one of this chapter's examples are document/literal. |