How to use ArrayList in Java Web Service

Hi frenz,

i am having a web service that is having 3 operations. They are all working fine.

now i want to add the forth operation with a return type of "ArrayList".

i tried, but it thrown an error:

error: Collection types are not supported in literal mode - Type: "java.util.ArrayList"

This is my wsdl file.

<?xml version="1.0" encoding="UTF-8"?>

<definitions name="palms" targetNamespace="urn:palms/wsdl" xmlns:tns="urn:palms/wsdl" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:ns2="urn:palms/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">

<types>

<schema targetNamespace="urn:palms/types" xmlns:tns="urn:palms/types" xmlns:soap11-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://www.w3.org/2001/XMLSchema">

<complexType name="enroll">

<sequence>

<element name="String_1" type="string" nillable="true"/>

<element name="arrayOfbyte_2" type="base64Binary" nillable="true"/></sequence></complexType>

<complexType name="enrollResponse">

<sequence>

<element name="result" type="boolean"/></sequence></complexType>

<complexType name="loadLIb">

<sequence/></complexType>

<complexType name="loadLIbResponse">

<sequence/></complexType>

<complexType name="verify">

<sequence>

<element name="String_1" type="string" nillable="true"/></sequence></complexType>

<complexType name="verifyResponse">

<sequence>

<element name="result" type="base64Binary" nillable="true"/></sequence></complexType>

<element name="enroll" type="tns:enroll"/>

<element name="enrollResponse" type="tns:enrollResponse"/>

<element name="loadLIb" type="tns:loadLIb"/>

<element name="loadLIbResponse" type="tns:loadLIbResponse"/>

<element name="verify" type="tns:verify"/>

<element name="verifyResponse" type="tns:verifyResponse"/></schema></types>

<message name="palmsSEI_enroll">

<part name="parameters" element="ns2:enroll"/></message>

<message name="palmsSEI_enrollResponse">

<part name="result" element="ns2:enrollResponse"/></message>

<message name="palmsSEI_loadLIb">

<part name="parameters" element="ns2:loadLIb"/></message>

<message name="palmsSEI_loadLIbResponse">

<part name="result" element="ns2:loadLIbResponse"/></message>

<message name="palmsSEI_verify">

<part name="parameters" element="ns2:verify"/></message>

<message name="palmsSEI_verifyResponse">

<part name="result" element="ns2:verifyResponse"/></message>

<portType name="palmsSEI">

<operation name="enroll">

<input message="tns:palmsSEI_enroll"/>

<output message="tns:palmsSEI_enrollResponse"/></operation>

<operation name="loadLIb">

<input message="tns:palmsSEI_loadLIb"/>

<output message="tns:palmsSEI_loadLIbResponse"/></operation>

<operation name="verify">

<input message="tns:palmsSEI_verify"/>

<output message="tns:palmsSEI_verifyResponse"/></operation></portType>

<binding name="palmsSEIBinding" type="tns:palmsSEI">

<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>

<operation name="enroll">

<soap:operation soapAction=""/>

<input>

<soap:body use="literal"/></input>

<output>

<soap:body use="literal"/></output></operation>

<operation name="loadLIb">

<soap:operation soapAction=""/>

<input>

<soap:body use="literal"/></input>

<output>

<soap:body use="literal"/></output></operation>

<operation name="verify">

<soap:operation soapAction=""/>

<input>

<soap:body use="literal"/></input>

<output>

<soap:body use="literal"/></output></operation></binding>

<service name="Palms">

<port name="palmsSEIPort" binding="tns:palmsSEIBinding">

<soap:address location="REPLACE_WITH_ACTUAL_URL"/></port></service></definitions>

can somebody help me?

thanx

--Subbu

[6899 byte] By [Subbu_javaa] at [2007-11-27 10:47:01]
# 1

Try using java.util.List<java.lang.Object> instead.

restevesa at 2007-7-28 20:22:29 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

Hi Subbu,

Java custom objects are not supported by the web services as the serialization mechanism is different.

If you use an ArrayList of Strings or other primitve types it will work with Web Services, but not an ArrayList of User defined objects.

The solution for this :

USE ARRAYS INSTEAD!!!

vinayak_ra at 2007-7-28 20:22:29 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

You can pass custom objects in WS.

Just have to obey a few rules, such as (but not only):

- implement a simple constructer (ex: public myclass(){}) .

- only constructors, getters and setters will be accessible.

- in the wsdl all custom classes used by the custom objects must be specified.

If you have a class like

public class myCollection{

private Vector v = new Vector();

public myCollection(){

}

setter and getter

public int size(){

return v.size();

}

}

public class myCollectionElement{

private String key="";

private String value="";

constructor and getters and setters

}

it will pass and be accessible on the ws consumer, only the method size() wont appear.

restevesa at 2007-7-28 20:22:29 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...