Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

To Pass a ArrayList using WebServices

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This article on how to send collections over SOAP might be helpful.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic