Listing 3. The CustomerService class using a simple array. - Web Services
This article introduces a couple of techniques that you can use to build interoperable Web services that take and return object collections. This is the first of a series of articles covering this subject. Future articles will cover more detailed scenarios. (This intermediate-level article was first published by IBM developerWorks, May 28, 2004, at http://www.ibm.com/developerWorks).
public class TheCustomerService { public Customer[] getCustomers(String queryString) { Customer customer1, customer2; /* ... retrieve customers for query ... */ /* create an array large enough to hold the result set */ Customer[] customers = new Customer[2]; /* iterate over the result set assigning to the array */ customers[0] = customer1; customers[1] = customer2; return customers; } }
As you can see, we have replaced the LinkedList with an array of type Customer. Listing 4 shows the resulting XML Schema in the WSDL definition:
Listing 4. The updated XML Schema for the CustomerService class.