Use collection types with SOAP and JAX-RPC - Listing 3. The CustomerService class using a simple array. (Page 3 of 5 )
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.
<schema elementFormDefault="qualified"
targetNamespace=http://pack
xmlns=http://www.w3.org/2001/XMLSchema
xmlns:apachesoap="http://xml.apache.org/xml-soap"
xmlns:impl="http://pack" xmlns:intf="http://pack"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<element name="getCustomers">
<complexType>
<sequence>
<element name="queryString"
nillable="true"
type="xsd:string"/>
</sequence>
</complexType>
</element>
<complexType name="Customer">
<sequence>
<element name="customerID"
nillable="true"
type="xsd:string"/>
</sequence>
</complexType>
<element name="getCustomersResponse">
<complexType>
<sequence>
<element maxOccurs="unbounded"
name="getCustomersReturn"
type="impl:Customer"/>
</sequence>
</complexType>
</element>
</schema>
This resulting schema definition and the SOAP message that is generated for this service are language-neutral and follow the WS-I Basic Profile.
Next: Create a wrapper interface >>
More Web Services Articles
More By developerWorks