O'Reilly logo

Java and SOAP by Robert Englander

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

8.2. Literal Encoding

We've seen how to use SOAP for RPC-type services, as well as how to pass around XML data in the less restrictive world of SOAP messaging services. But another possibility is to pass XML using RPC services. The problem is that RPC services rely on a type mapping mechanism to convert between XML elements and Java classes. It would be nice if you could use an RPC-style method invocation to pass parameters, with the result being standard XML. Well, you can. To do it, you need to use XML literal encoding, which tells the underlying SOAP framework that the data is XML and should remain that way.

Let's go back to the world of finance. We'll create a service that provides corporate information on companies in an XML format. The service is called urn:CorporateDataService, which has a method called getDataForSymbol . The service is an RPC service, and the method takes a stock symbol as the parameter. The data returned can include the company name, company address, year of incorporation, number of employees, and the high and low trading price for the past 52 weeks. This service will pull its data from another system that already keeps corporate data in XML format in a database. So it's not the responsibility of the service to format the data, only to pass it back to the caller. This scenario is perfect for using XML literal encoding. If the service were going to process the data in some way, it might just as well be designed to return a complex type that can be ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required