【问题标题】:I want to pass my custom object in soap body element , how to do it?我想在soap body element中传递我的自定义对象,怎么做?
【发布时间】:2012-03-13 11:24:21
【问题描述】:

我正在尝试使用 JAXB SAAJ 调用 Web 服务。我使用 wsdl2java 创建 Web 服务对象。现在我想在soap调用中传递这个对象之一。我怎样才能做到这一点?我想在soap body element中传递我的自定义对象,怎么做?

我的代码:

SOAPBody soapbody = soapmessage.getSOAPBody();
SOAPBodyElement element = soapbody.addBodyElement(soapbodyName);
element.addChildElement(myCustomObject); <-- it gives error here that I can not pass my object here.

【问题讨论】:

    标签: java web-services soap jaxb saaj


    【解决方案1】:

    您需要使用 JAXBElement 和 wsdl2java 生成的 ObjectFactory 将其编组到 SOAPBody:

    JAXBElement<MyCustomObject> myCustomObjectElement = 
        new ObjectFactory().createMyCustomObject(myCustomObject);
    jaxbContext.createMarshaller().marshal(myCustomObjectElement, soapbody);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-02
      相关资源
      最近更新 更多