SOAP方法中的数组通过JAX-WS生成的参数? [英] Arrays in SOAP method Parameters generated via JAX-WS?

查看:92
本文介绍了SOAP方法中的数组通过JAX-WS生成的参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Java JAX-WS批注构建SOAP服务.除其他外,我想知道如何在我的方法中注释数组参数.当我从带注释的接口中生成wsdl,然后再次从该wsdl中生成Java类时(我在两种情况下都使用Apache cxf进行了测试),它将生成用于保存数组参数的类.

I am building a SOAP service in Java with JAX-WS annotations. Among other things I wonder how to annotate array parameters in my methods. At the moment when I generate a wsdl from my annotated interface and then generate java classes again from that wsdl (I do that for testing, in both cases using Apache cxf), it will generate Classes to hold the array parameters.

示例:

 @WebService(name="sillyService",
    ...
)
@SOAPBinding(style=SOAPBinding.Style.DOCUMENT, use=SOAPBinding.Use.LITERAL, parameterStyle=SOAPBinding.ParameterStyle.BARE)
public interface SillyService {
    public String doSillyThings(
         @WebParameter(name = "stupid") StupidData[] stupid;
    );
}

其中StupidData将是另一个这样注释的类

Where StupidData would be another class annotated like this

@XmlAccessorType(XmlAccessType.FIELD)

@XmlRootElement(name = "StupidData")
public class StupidData {
@XmlElement(name = "datapoint")
String datapoint;
}

然后,在生成的类中,Parameter代替数组,成为新的StupidDataArray类,该类具有一个文件,即StupidData数组.

Then instead of an Array, in the generated classes the Parameter becomes a new class StupidDataArray which has a filed that is the array of StupidData.

有什么方法可以使其直接接受数组作为参数?谢谢...

Any way to make it accept the array as parameter directly? Thanks...

推荐答案

就我而言,Apache CXF从WSDL文件生成的代码包括ArrayOfXXX类,其中一个getXXX()方法返回了List. 此方法的自动生成的Javadoc指出:

In my case, the code generated by apache CXF from the WSDL files includes ArrayOfXXX classes, with a single getXXX() method returning a List. The autogenerated javadoc of this method states:

此访问器方法返回对活动列表的引用, 不是快照.因此,您对 返回的列表将出现在JAXB对象中. 这就是为什么guid属性没有 set 方法的原因. 例如,要添加新项目,请执行以下操作: getXXX().add(newItem);

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 set method for the guid property. For example, to add a new item, do as follows: getXXX().add(newItem);

要回答您的问题,您不能将本机数组传递给方法,但是可以在将元素添加到其基础列表之后传递Array类.为此,您可以使用getXXX()从数组包装器中检索封装的List,并向其中添加元素.

To answer your question, you can't pass a native array to the method but you can pass the Array class after you have added elements to its underlying list. To do that, you retrieve the encapsulated List from the array wrapper using getXXX() and add elements to it.

这篇关于SOAP方法中的数组通过JAX-WS生成的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆