【问题标题】:Arrays as parameters in Axis2 POJO Webservices?数组作为 Axis2 POJO Web 服务中的参数?
【发布时间】:2011-07-25 09:44:51
【问题描述】:

我是一个 Axis2 / Webservice 新手,我正在尝试将一个简单的 POJO 转换为一个 Web 服务(代码如下)。 PieceInfo 类用 @XmlRootElement 注释,我有一个 ObjectFactory 类,它在方法中返回一个 PieceInfo(下面的代码)。使用PieceInfo 的方法有效,使用List<PieceInfo>PieceInfo[] 作为参数的方法会抛出java.util.List is not known to this context 等JAXB 异常。我认为列表或数组应该可以正常工作。我做错了什么?

@WebService (name="KMPService",targetNamespace="http://www.ict.ie.tss/")
@MTOM
public interface KMPServiceInterface {

@WebMethod
void updateRootInfo(String username, String password, PieceInfo info);

@WebMethod
PieceInfo getRootInfo(String username, String password);

@WebMethod
void put(String username, String password, List<PieceInfo> infoList);

@WebMethod
PieceInfo[] get(String username, String password,
    PieceInfo[] infoList);

@WebMethod
void deleteEntries(String username, String password,
    PieceInfo[] infoList);

}

ObjectFactry:

@XmlRegistry
public class ObjectFactory {

public PieceInfo createPieceInfo(){
    return new PieceInfo();
}

 }

【问题讨论】:

    标签: web-services axis2 pojo


    【解决方案1】:

    似乎答案是:不要使用 Axis2。现在使用 cxf snd 一切都适用于开箱即用的列表和数组。

    【讨论】:

    • 你有关于这个 Axis2 限制的官方文档参考吗?在我的公司,我需要支持 Websphere 应用服务器上的项目,我面临同样的问题。
    【解决方案2】:

    使用数组而不是 java.util.List。

    请记住,Web 服务应该与所有事物互操作,例如 .Net Web 服务客户端,他们不知道如何构建 java.util.List 对象,但应该能够弄清楚如何构建数组PieceInfo 对象。

    希望这可以消除您的“在此上下文中未知”的问题。还要确保 PieceInfo 具有零参数构造函数,以便 Axis 框架可以创建一个。

    【讨论】:

    • 数组也不起作用。如果我使用数组,我会得到:[...model.PieceInfo; is not known to this context]。如果我只使用一个 PieceInfo 对象,它就可以正常工作。只是不是它们的数组或它们的列表。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多