1

我正在尝试使用 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.
4

1 回答 1

4

您需要使用 a 将其编组到 SOAPBodyJAXBElement并由ObjectFactorywsdl2java 生成:

JAXBElement<MyCustomObject> myCustomObjectElement = 
    new ObjectFactory().createMyCustomObject(myCustomObject);
jaxbContext.createMarshaller().marshal(myCustomObjectElement, soapbody);
于 2012-03-13T12:05:40.520 回答