SOAP-Based Web Services and Binary Data

In the examples so far, the SOAP messages contain text that is converted to service-appropriate types such as List<Prediction>. The type conversion is typically automatic, occurring in the JAX-WS infrastructure without application intervention, but handlers could use JAX-B and related technologies for converting text to and from Java types. Even a very simple example illustrates the power of this underlying, automatic conversion. Here is a SOAP response from the RandService, in particular a call to the next1 operation, which returns a randomly generated integer:

<S:Envelope xmlns:S="">
      <ns2:next1Response xmlns:ns2="http://rand/">

The returned value -1691660782 occurs as text in the SOAP message but is converted automatically to an int for a Java client, which does not need to do any explicit type conversion.

Type conversions come to the forefront in the issue of how binary data such as images, movies, and the like can be arguments passed to or values returned from SOAP-based service operations. SOAP-based services can deal with binary payloads but such payloads raise issues of efficiency. There are two general approaches to dealing with binary data in SOAP-based services:

  • The binary data can be encoded using a scheme such as base64 encoding and then transmitted as the payload of the SOAP body—in other words, as text. The ...

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

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