Chapter 5. Working with Complex Data Types

In the previous chapter, we created RPC-style services in Java. Those services dealt only with simple data types. Simple data types may suffice in many situations, but you’ll eventually need to use more complex data types, like those you’re familiar with in your day-to-day Java programming. In this chapter we’ll look at creating services with method parameters and return values that are arrays and Java beans. We’ll hold off on custom data types until the next chapter, since it’s possible that any custom types you create would use the complex data types we’ll be discussing here.

Passing Arrays as Parameters

Let’s face it — arrays are probably the most common complex data type in programming. They’re everywhere, so their use in SOAP is critical. We covered the details of SOAP arrays back in Chapter 3, so you should be aware of how arrays are encoded. So let’s get right into writing some Java code for services that use arrays.

We’ve been working with stock market examples, so let’s stick with that theme. It might be useful to have a service that returns information about a collection of stock symbols. It might provide the total volume of shares traded for the day, the average trading price of those stocks, the number of stocks trading higher for the day, etc. There are lots of possibilities. Let’s start out with a service that returns the total number of shares traded for the day. The service is called urn:BasicTradingService, and it ...

Get Java and SOAP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.