浏览 519 次
|
锁定老贴子 主题:有关JWS的一个问题
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
|---|---|
| 作者 | 正文 |
|
时间:2007-04-02 关键字: JWS WEBSERVICE
JDK6.0 自带的WebService中 WebMethod的参数好像不能是ArrayList 或者其他List
传递List需要将List 包装在其他对象内部才行 (个人理解 如有不对请指出) 但是这样的话 在客户端用wsimport生成stub的时候 包装List的对象只有getter 没有setter 如果是其他对象好像又是正常的 不知道是没设置好 还是别的什么原因 虽然修改存跟可以添加setter 但是 如果东西多的话 或者 ws老修改 这样每次都要改挺麻烦的 想写个程序生成存根 然后将存根打包 困与包装List的对象的修改 webService 代码
package test;
import java.util.ArrayList;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.WebParam.Mode;
import javax.jws.soap.SOAPBinding;
@WebService(name = "TransData", targetNamespace = "http://ws.abc.com", serviceName = "TransData")
@SOAPBinding(style=SOAPBinding.Style.RPC)
public class TransData
{
@WebMethod(operationName="setData")
public void setData(
@WebParam(partName="listObject", mode=Mode.IN, targetNamespace="http://ws.abc.com")
ListObject listObject)
{
System.out.println(listObject.getList().toString());
}
@WebMethod(operationName="getData")
public
@WebResult(partName="o", targetNamespace="http://ws.abc.com")
ListObject getData()
{
ArrayList<Object> list = new ArrayList<Object>();
for (int i = 10; i < 10; i++)
{
list.add(i);
}
ListObject o = new ListObject();
o.setList(list);
return o;
}
}
包装List的代码
package test;
import java.util.ArrayList;
public class ListObject
{
protected ArrayList<Object> list;
public ArrayList<Object> getList()
{
return list;
}
public void setList(ArrayList<Object> list)
{
this.list = list;
}
}
用wsimport生成的list包装对象的存根
package com.abc.ws;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for listObject complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType name="listObject">
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="list" type="{http://www.w3.org/2001/XMLSchema}anyType" maxOccurs="unbounded" minOccurs="0"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "listObject", propOrder = {
"list"
})
public class ListObject {
@XmlElement(nillable = true)
protected List<Object> list;
/**
* Gets the value of the list property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the list property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getList().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link Object }
*
*
*/
public List<Object> getList() {
if (list == null) {
list = new ArrayList<Object>();
}
return this.list;
}
}
声明:JavaEye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
|
|
| 返回顶楼 | |


