Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

To Pass a ArrayList using WebServices

 
Nikita Rai
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My WebService consists of a method which returns a ArrayList

package com.db.cc;

import java.util.ArrayList;

public class Test {

public ArrayList getArrayList(){
ArrayList list = new ArrayList();
list.add("First");
list.add("Second");
return list;
}

}

My server-config.wsdd contains the following entries

<service name="Test" provider="java:RPC">
<parameter name="className" value="com.db.cc.Test"/>
<parameter name="allowedMethods" value="*"/>
<parameter name="load-on-startup" value="true"/>
<parameter name="activateOnStartup" value="true"/>
</service>

At present the returned value is not getting resolved into an ArrayList as the below client code is throwing a ClassCastException

import java.util.ArrayList;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;

public class TestWebService {
public static void main(String args[]) throws Exception{
String endpoint = "http://127.0.0.1:8080/axis/services/Test?wsdl";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress( new java.net.URL(endpoint) );
call.setOperationName(new QName("http://cc.db.com","getArrayList"));
ArrayList ret = (ArrayList)call.invoke( new Object[] {});

}
}
Can anyone let me know the solution for the above problem
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The solution is don't ever try to send a Java collection when a simple array will do. Just because you have a collection on the service side does NOT mean the the client needs to get a collection. What would a .NET or Perl client know about a Java collection?
You can convert an ArrayList to an array - see the toArray method in the java.util.List Interface.
Bill
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This article on how to send collections over SOAP might be helpful.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!