Better Software - January 2008 - (Page 21) WHAT ABOUT SOAP? By listening to vendors, one would get the impression that the only proper way to implement a Web service is to use SOAP. This is not true. While SOAP—and the specifications built on top of it, commonly known as WS-*—enables certain features such as security, routing, etc., using it is certainly not a requirement. Recently, new Web services technologies such as Plain Old XML (POX) and Representational State Transfer (REST) have emerged (see the StickyNotes for more information), which are as interoperable as SOAP and WS-*, or perhaps even more so. In this article, we are focusing on POX, meaning that we send plain XML messages over the wire, without any wrapping SOAP envelope. Migrating this POX service to a SOAP service would not be difficult. We could simply use our de- write a service-description document. This document provides instructions to the consumers of our service. We can take two approaches to such a document. The first is an informal document in which we describe the personnel service by way of its messages; such a document would be very useful for human consumers of our service. We can also take a more formal approach by defining a grammar for the personnel service’s messages—something that is more useful for automated consumers. Both description documents are very useful, but the latter approach is the one taken in this article, because, in a way, you can consider this section—together with the examples from Dan’s article—to be an example of the informal document. Formalizing the Angle Brackets There are four ways of defining a grammar for XML. Some are still used because of historic reasons, and others were started in an attempt to be less verbose. They include: • Document type definitions (DTDs) • Relax NG • Schematron • W3C XML schema (XSD) Though still widely used, DTDs are showing their age. For one thing, they lack certain features that we require (e.g., proper fined vacation-request messages within a SOAP envelope, namespace support). And while the grammars created in Relax like so: NG are more readable than the alternatives, its support across Since one of the main reasons for using XML is interoperability, it makes sense to use the grammar that is most interoperable— alternatives, but we gain a lot from it—interoperability and, more importantly, the ability to include the XSD in a WSDL. 2007-07-23 You might think that having WSDL is a requirement for a 2007-08-03 Web service. As with SOAP, this is not the case. The schema de fines the validity of the messages, and since the messages define our service, the schema suffices. The only reason for defining a WSDL for our service would be for reasons of interoperability. Bob Creating a WSDL from an XSD schema is a simple process, Johnson consisting of a few basic steps. You start by including the schema in the WSDL, and then simply define a port type and SOA Developservice that take the messages as input and output for the operament tions. This process can even be automated with an XSLT style sheet (see the StickyNotes for a link). Creating an XSD by hand is a painful process. Luckily, tools are available that can infer a schema from one or more sample XML documents. The output of these tools will probably need to be polished manually, but it is a great starting point. In this article, we are going to use Trang (see the StickyNotes for a link) Thus, we place the vacation request in the SOAP body and to infer an XSD schema out of the sample document. use it as the payload of the SOAP envelope. Feeding the sample vacation request described in the previous section, Trang generates the schema shown in listing 5. Holy angle brackets, Batman! That’s a lot of improve this XSD to make it less intimidating and more specific for our vacation service. Ba 2007-07-23 sically, we are using our knowledge of the 2007-08-03 domain to make the schema more suitable— … something that Trang could not do for us. The first thing to notice is that every type has a Listing 4 www.StickyMinds.com JANUARY/FEBRUARY 2008 BETTER SOFTWARE 21 http://www.StickyMinds.com
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.