在Java中的Web服务调用中传递ArrayList
我有一个包含 10 个值的 ArrayList。
ArrayList<String> a=new ArrayList<String>();
a.add("a1");
a.add("a2");
a.add("a3");
我正在调用 WebService 将此 ArrayList 作为输入参数传递。 但是,当我创建一个虚拟客户端并测试 ArrayList 时,我没有得到输出。我正在使用 Apache Axis 2。 我意识到 ArrayList 没有同步,因此可能存在问题......我该如何克服这个问题...... 我正在寻找最简单的解决方案...... 任何人都可以指导我...
服务器端代码是:-
public class TestWebSerrviceForArrayList
{
public String personIdentity="RandomName";
ArrayList<String> personArray=new ArrayList<String>();
public ArrayList<String> addValuesArrayList()
{
personArray.add("Name1");
personArray.add("Name2");
personArray.add("Name3");
personArray.add("Name4");
System.out.println("Added values in person Array " + personArray);
return personArray;
}
public String getName()
{
return personIdentity;
}
}
客户端代码片段是:-
TestWebSerrviceForArrayListStub testWeb=new TestWebSerrviceForArrayListStub();
AddValuesArrayListResponse r=testWeb.(I AM NOT ABLE TO FIND THE FUNCTION NAME)
I have an ArrayList containing 10 values.
ArrayList<String> a=new ArrayList<String>();
a.add("a1");
a.add("a2");
a.add("a3");
I am invoking WebService to pass this ArrayList as an input parameter..
However when I created a dummy client and tested for the ArrayList I am not getting the output.. I am using Apache Axis 2.
I realised that ArrayList is not synchornized and hence there may be a problem...How do I overcome this issue....
I am looking for the simplest solution...
Can anyone please guide me...
The server side code is:-
public class TestWebSerrviceForArrayList
{
public String personIdentity="RandomName";
ArrayList<String> personArray=new ArrayList<String>();
public ArrayList<String> addValuesArrayList()
{
personArray.add("Name1");
personArray.add("Name2");
personArray.add("Name3");
personArray.add("Name4");
System.out.println("Added values in person Array " + personArray);
return personArray;
}
public String getName()
{
return personIdentity;
}
}
The code snippet for Client Side is :-
TestWebSerrviceForArrayListStub testWeb=new TestWebSerrviceForArrayListStub();
AddValuesArrayListResponse r=testWeb.(I AM NOT ABLE TO FIND THE FUNCTION NAME)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Web 服务无法理解
ArrayList
,但List
可以。它与 ArrayList 的同步无关,而是匹配 WSDL 理解的数据类型。如前所述:我会将此方法的返回类型更改为
List
,如下所示(并重新生成 WSDL)。ArrayList
is not understood by the Web Service, butList
is. It's got nothing to do with synchronization ofArrayList
but to match the data types understood by the WSDL.As stated earlier: I would change the return type for this method to
List<String>
as follows (and regenerate the WSDL).