Returning an ArrayList from a WebService in Java

Viewed 31519

I am having a problem returning an ArrayList from my web service (Java).

I have written a test web service and client which consumes it. All appears to work fine - that is the client is calling the server and the server receives the operation request.

However, I have written a simple method that I want it to return an ArrayList.

I have my interface definition as follows:

@WebService
@SOAPBinding(style = Style.RPC)
public interface ISQLServerConnectionWS {

    @WebMethod
    ArrayList getSimpleArrayList();
}

I have my server side implementation to return the ArrayList:

@WebService(endpointInterface="WebServices.ISQLServerConnectionWS")
public class SQLConnectionWSServer
    implements ISQLServerConnectionWS {

    @Override
    public ArrayList getSimpleArrayList() {
        ArrayList al = new ArrayList();
        al.add( "This" );
        al.add( "is" );
        al.add( "a" );
        al.add( "test" );
        return al;
    }
}

And finally my client call to it:

ArrayList results = server.getSimpleArrayList();

The server populates the array list fine. However, back at the client side, the ArrayList is empty. It has a size of 0.

If I examine the WSDL at my URL (http://127.0.0.1:9876/myservice-sql?wsdl) for the executeSelectSQL, it looks like:

<message name="executeSelectSQLResponse">
    <part name="return" type="tns:arrayList"/>
</message>

Am I missing something obvious?

Edit:

However, if I have a web method defines in the interface as:

@WebMethod
String getAString();

and the server implementation:

@Override
public String getAString() {
    return "hello there";
}

then this works fine - "hello there" is received on the client.

2 Answers
Related