Chapter 4. SOAP-Based Web Services

JAX-WS is an API for producing and consuming REST-style and SOAP-style web services. Chapter 2 introduced, with a RESTful example, the JAX-WS @WebServiceProvider annotation, which can be used for either a REST-style or a SOAP-based service. This chapter introduces the @WebService annotation, in effect a refinement of @WebServiceProvider; a @WebService is emphatically SOAP-based. JAX-WS is thus sufficiently rich and varied that it might better be described as a collection of APIs. JAX-WS is the successor to JAX-RPC, which derives from the XML-RPC discussed in Chapter 1. The reference implementation for JAX-WS is part of the open source GlassFish project and is named GlassFish Metro or just Metro for short. The current version of JAX-WS is 2.2.x. JAX-WS is officially part of enterprise Java but, with JDK 1.6 or greater, JAX-WS services can be compiled and published using only core Java. SOAP-based services in JAX-WS can be published with a standard Java web server such as Tomcat or Jetty; there is also a convenient Endpoint publisher, used earlier to publish a RESTful service.

Apache Axis2 is an alternative implementation of JAX-WS. Axis2, the successor to Axis, is based on JAX-WS but has additional features. Yet another JAX-WS implementation is Apache CXF. This chapter focuses on the Metro implementation of JAX-WS, but the next chapter includes an Axis2 service and client. The Metro, Axis2, and Apache CXF implementations of JAX-WS are sufficiently close that a programmer fluent in one implementation should be able to move easily into any other implementation.

SOAP is an XML dialect that has two W3C-sanctioned versions: 1.1 and 1.2; SOAP is officially no longer an acronym. The differences between the versions of SOAP are more about infrastructure than API. For example, the media type for a SOAP 1.1 message is text/xml, whereas this type changes in SOAP 1.2 to application/soap+xml. The SOAP 1.2 processing model is more thoroughly and precisely specified than is the SOAP 1.1 model; SOAP 1.2 has an official binding framework that opens the way to using transport protocols other than HTTP for delivering SOAP messages. In practice, however, HTTP remains the dominant transport for both SOAP 1.1 and SOAP 1.2. In the major SOAP frameworks of Java and DotNet, SOAP 1.1 is the default, but both systems support SOAP 1.2 as well.

SOAP has a basic profile, which comes from the WS-I (Web Services Interoperability) consortium to encourage and support interoperability among web service languages and technologies. Beyond the basic profile are various initiatives, some of which are covered in later chapters; these initiatives (for instance, WS-Reliability and WS-Security) often are grouped under the acronym WS-*. WSIT (Web Services Interoperability Technology) is a related set of guidelines that promotes interoperability specifically between Java and DotNet, in particular DotNet’s WCF (Windows Communication Foundation). WCF is a framework for developing service-oriented applications that would include but also go beyond SOAP-based web services ( From time to time, this chapter refers to one or another SOAP specification in order to clarify a particular service or client, but the emphasis in this chapter remains on coding services and their clients. Unless otherwise specified, the examples are in SOAP 1.1.

Get Java Web Services: Up and Running, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.