April 1, 2011, 12:37 p.m.
posted by max
Overview of Web Service Standards
Standards differ from technologies. Standards are a collection of specifications, rules, and guidelines formulated and accepted by the leading market participants. While these rules and guidelines prescribe a common way to achieve the standard's stated goal, they do not prescribe implementation details. Individual participants devise their own implementations of an accepted standard according to the standard's guidelines and rules. These various implementations of a standard by different vendors give rise to a variety of technologies. However, despite the implementation detail differences, the technologies can work together if they have been developed according to the standard's specifications.
For Web services to be successful, the Web service standards must be widely accepted. To enable such wide acceptance, the standards used for Web services and the technologies that implement those standards should meet the following criteria:
Although they do not exhaustively discuss these basic standards, the next sections provide enough information about the standards to enable further discussion about the J2EE technologies that implement them. For complete details, see the reference section at the end of this chapter. In addition to these basic standards, more complex Web services that implement enterprise-level processes need standards for security, transactions, process flow control, and so forth.
1 Extensible Markup Language
The eXtensible Markup Language (XML), a standard accepted throughout the industry, enables service providers and requestors to communicate with each other in a common language. XML is not dependent on a proprietary platform or technology, and messages in XML can be communicated over the Internet using standard Internet protocols such as HTTP. Because XML is a product of the World Wide Web Consortium (W3C) body, changes to it will be supported by all leading players. This ensures that as XML evolves, Web services can also evolve without backward compatibility concerns.
XML is a simple, flexible, text-based markup language. XML data is marked using tags enclosed in angled brackets. The tags contain the meaning of the data they mark. Such markup allows different systems to easily exchange data with each other. This differs from tag usage in HTML, which is oriented to displaying data. Unlike HTML, display is not inherent in XML. Code Figure shows the code from an XML document representing an individual's contact information.
1. XML Document Example
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?> <ContactInformation> <Name>John Doe</Name> <Address> <Street>4140 Network Circle</Street> <City>Santa Clara</City> <State>California</State> <Country>USA</Country> </Address> <HomePhone>123-456-7890</HomePhone> <EMail>[email protected]</EMail> </ContactInformation>
A Document Type Definition (DTD) or XML Schema Definition (XSD) describes the structure of an XML document. It has information on the tags the corresponding XML document can have, the order of those tags, and so forth. An XML document can be validated against its DTD or its XSD. Validating an XML document ensures that the document follows the structure defined in its DTD or XSD and that it has no invalid XML tags. Thus, systems exchanging XML documents for some purpose can agree on a single DTD or XSD and validate all XML documents received for that purpose against the agreed-upon DTD/XSD before processing the document. Code Figure is the DTD for the XML document in Code Figure.
2. Document Type Definition
<!ELEMENT ContactInformation (Name, Address, HomePhone, EMail)> <!ELEMENT Name (#PCDATA)> <!ELEMENT Address (Street, City, State, Country)> <!ELEMENT Street (#PCDATA)> <!ELEMENT City (#PCDATA)> <!ELEMENT State (#PCDATA)> <!ELEMENT Country (#PCDATA)> <!ELEMENT HomePhone (#PCDATA)> <!ELEMENT EMail (#PCDATA)>
Unfortunately, DTDs are an inadequate way to define XML document formats. For example, DTDs provide no real facility to express data types or complex structural relationships. XML schema definitions standardize the format definitions of XML documents. Code Figure shows the XSD schema for the sample XML document in Code Figure.
3. XML Document
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?> <ContactInformation xmlns="http://simple.example.com/CInfoXmlDoc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http://simple.example.com/CInfoXmlDoc file:./CInfoXmlDoc.xsd"> <Name>John doe</Name> <Address> <Street>4140 Network Circle</Street> <City>Santa Clara</City> <State>California</State> <Country>USA</Country> </Address> <HomePhone>123-456-7890</HomePhone> <EMail>[email protected]</EMail> </ContactInformation>
4. XSD Schema
<?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://simple.example.com/CInfoXmlDoc" xmlns=" http://simple.example.com/CInfoXmlDoc" elementFormDefault="qualified"> <xsd:element name="ContactInformation"> <xsd:complexType> <xsd:sequence> <xsd:element name="Name" type="xsd:string" /> <xsd:element name="Address"> <xsd:complexType> <xsd:sequence> <xsd:element name="Street" type="xsd:string" /> <xsd:element name="City" type="xsd:string" /> <xsd:element name="State" type="xsd:string" /> <xsd:element name="Country" type="xsd:string" /> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="HomePhone" type="xsd:string" /> <xsd:element name="EMail" type="xsd:string" /> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema>
When considering XML schemas, it is important to understand the concept of XML namespaces. To enable using the same name with different meanings in different contexts, XML schemas may define a namespace. A namespace is a set of unique names that are defined for a particular context and that conform to rules specific for the namespace. Since a namespace is specific to a particular context, each namespace is unrelated to any other namespace. Thus, the same name can be used in different namespaces without causing a duplicate name conflict. XML documents, which conform to an XML schema and have multiple elements and attributes, often rely on namespaces to avoid a collision in tag or attribute names or to be able to use the same tag or attribute name in different contexts.
Technically speaking, an XML namespace defines a collection of names and is identified by a URI reference. (Notice in Code Figure the code xmlns="http://simple.example.com/CInfoXmlDoc". Code such as this indicates that the XML schema defines a namespace for the various elements and attributes in the document.) Names in the namespace can be used as element types or attributes in an XML document. The combination of URI and element type or attribute name comprises a unique universal name that avoids collisions.
For example, in Code Figure, there is a namespace that defines the ContactInformation document's element types, such as Name and Address. These element types are unique within the contact information context. If the document included another namespace context, such as BankInformation that defined its own Name and Address element types, these two namespaces would be separate and distinct. That is, a Name and Address used in the context of BankInformation would not conflict with a name and address used in the context of ContactInformation.
2 Simple Object Access Protocol
XML solves the need for a common language, and the Simple Object Access Protocol (SOAP) fills the need for a common messaging format. SOAP enables objects not known to one another to communicate; that is, to exchange messages. SOAP, a wire protocol similar to Internet Inter-ORB Protocol (IIOP) and Java Remote Method Protocol (JRMP), is a text-based protocol that uses an XML-based data encoding format and HTTP/SMTP to transport messages. SOAP is independent of both the programming language and the operational platform, and it does not require any specific technology at its endpoints, making it completely agnostic to vendors, platforms, and technologies. Its text format also makes SOAP a firewall-friendly protocol. Moreover, SOAP is backed by leading industrial players and can be expected to have universal support.
To enable message exchanges, SOAP defines an envelope, which contains a SOAP body, within which the message is included, and an optional SOAP-specific header. The whole envelope—body plus header—is one complete XML document. (See Figure.)
1. SOAP Message Structure
The header entries may contain information of use to recipients, and these header entries may also be of use to intermediate processors since they enable advanced features. The body, which contains the message contents, is consumed by the recipient. SOAP is agnostic about the message contents; the only restriction is that the message be in XML format.
Code Figure shows a simple but complete example of a SOAP request for obtaining a stock quote.
5. Example SOAP Request
<SOAP-ENV:Envelope xmlns:SOAP-ENV="SoapEnvelopeURI" SOAP-ENV:encodingStyle="SoapEncodingURI"> <SOAP-ENV:Header> </SOAP-ENV:Header> <SOAP-ENV:Body> <m:GetLastTradePrice xmlns:m="ServiceURI"> <tickerSymbol>SUNW</tickerSymbol> </m:GetLastTradePrice> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
This example shows how a SOAP message is encoded using XML and illustrates some SOAP elements and attributes. All SOAP messages must have an Envelope element and must define two namespaces: One namespace connotes the SOAP envelope (xmlns:SOAP-ENV) and the other indicates the SOAP encoding (SOAP-ENV:encodingStyle). SOAP messages without proper namespace specification are considered invalid messages. The encodingStyle attribute is important, as it is used to specify serialization rules for the SOAP message. Moreover, there can be no DTD referrals from within SOAP messages.
While optional, the Header element when used should be the first immediate child after the Envelope. The Header element provides a way to extend the SOAP message by specifying additional information such as authentication and transactions. Specifying this additional information as part of the Header tells the message recipient how to handle the message.
There are many attributes that can be used in the SOAP Header element. For example, the actor attribute of the Header element enables a SOAP message to be passed through intermediate processes enroute to its ultimate destination. When the actor attribute is absent, the recipient is the final destination of the SOAP message. Similarly, many other attributes may be used. However, this chapter does not address these details.
The Body element, which must be present in all SOAP messages, must follow immediately after the Header element, if it is present. Otherwise, the Body element must follow immediately after the start of the Envelope element. The Body contains the specification of the actual request (such as method calls). The Fault element in the SOAP Body enables error handling for message requests.
Note that this chapter does not discuss details of Header elements, attributes, and other additional features, such as SOAP with attachments and binding HTTP, although they are part of the SOAP standard. Interested readers should refer to the SOAP specifications.
3 Registry Standards
The Universal Description, Discovery, and Integration (UDDI) specification defines a standard way for registering, deregistering, and looking up Web services. UDDI is a standards-based specification for Web service registration, description, and discovery. Similar to a telephone system's yellow pages, a UDDI registry's sole purpose is to enable providers to register their services and requestors to find services. Once a requestor finds a service, the registry has no more role to play between the requestor and the provider.
Figure shows how UDDI enables dynamic description, discovery, and integration of Web services. A Web service provider registers its services with the UDDI registry. A Web service requestor looks up required services in the UDDI registry and, when it finds a service, the requestor binds directly with the provider to use the service.
2. Role of a Registry in a Web Service
The UDDI specification defines an XML schema for SOAP messages and APIs for applications wanting to use the registry. A provider registering a Web service with UDDI must furnish business, service, binding, and technical information about the service. This information is stored in a common format that consists of three parts:
The UDDI specification includes two categories of APIs for accessing UDDI services from applications:
UDDI APIs behave in a synchronous manner. In addition, to ensure that a Web service provider or requestor can use the registry, UDDI uses SOAP as the base protocol. Note that UDDI is a specification for a registry, not a repository. As a registry it functions like a catalog, allowing requestors to find available services. A registry is not a repository because it does not contain the services itself.
4 Web Services Description Language
The Web Services Description Language (WSDL) defines a standard way for specifying the details of a Web service. It is a general-purpose XML schema that can be used to specify details of Web service interfaces, bindings, and other deployment details. By having such a standard way to specify details of a service, clients who have no prior knowledge of the service can still use that Web service.
WSDL specifies a grammar that describes Web services as a collection of communication endpoints, called ports. The data being exchanged are specified as part of messages. Every type of action allowed at an endpoint is considered an operation. Collections of operations possible on an endpoint are grouped together into port types. The messages, operations, and port types are all abstract definitions, which means the definitions do not carry deployment-specific details to enable their reuse.
The protocol and data format specifications for a particular port type are specified as a binding. A port is defined by associating a network address with a reusable binding, and a collection of ports define a service. In addition, WSDL specifies a common binding mechanism to bring together all protocol and data formats with an abstract message, operation, or endpoint. See Figure.
3. WSDL Service Description
Code Figure shows a WSDL document for a weather Web service that returns a given city's weather information. The Web service, which uses SOAP as the communication protocol, expects to receive the city name as String type data and sends String type data as its response.
6. WSDL Document for Weather Web Service
<?xml version="1.0" encoding="UTF-8"?> <definitions name="WeatherWebService" targetNamespace="urn:WeatherWebService" xmlns:tns="urn:WeatherWebService" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"> <types/> <message name="WeatherService_getWeather"> <part name="String_1" type="xsd:string"/> </message> <message name="WeatherService_getWeatherResponse"> <part name="result" type="xsd:string"/> </message> <portType name="WeatherService"> <operation name="getWeather" parameterOrder="String_1"> <input message="tns:WeatherService_getWeather"/> <output message="tns:WeatherService_getWeatherResponse"/> </operation> </portType> <binding name="WeatherServiceBinding" type="tns:WeatherService"> <operation name="getWeather"> <input> <soap:body use="literal" namespace="urn:WeatherWebService"/> </input> <output> <soap:body use="literal" namespace="urn:WeatherWebService"/> </output> <soap:operation soapAction=""/></operation> <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/> </binding> <service name="WeatherWebService"> <port name="WeatherServicePort" binding="tns:WeatherServiceBinding"> <soap:address location="http://mycompany.com/weatherservice"/> </port> </service> </definitions>
A complete WSDL document consists of a set of definitions starting with a root definitions element followed by six individual element definitions—types, message, portType, binding, port, and service—that describe the services.
This description is for a simple WSDL document. Each element definition has various attributes and WSDL has additional features, such as fault handling. WSDL also specifies how to bind directly with HTTP/MIME, SMTP/MIME, and so forth, but these are beyond the scope of the current discussion. For more details, see the WSDL specification available at http://www.w3c.org/TR/wsdl.
5 Emerging Standards
So far we have examined existing standards, which meet the needs of simple Web services. Organizations that cross various industries have been formed to create and promote cross-platform standards. The Web Services Interoperability Organization (WS-I) is one such group. WS-I has published a WS-I Basic Profile that defines a set of cross-platform standards, such as those just examined, to promote and ensure interoperability. But other standards are required to address issues for Web services that handle complex business processes. These issues include strict security requirements, business processes interacting with other business processes and having long-lived transactions or transactions that span multiple business processes, or business processes nested within other processes. These business processes must also execute properly even when run on different platforms. Various standards bodies and organizations such as WS-I are currently working on these standards. Since these standards are still being defined and it is not yet clear which standards will be accepted as universal, we do not go into the details of emerging standards.
Now that we have examined the Web service standards, let's go on to see how J2EE supports these accepted standards.