我正在尝试使用JAXB SAAJ调用Web服务。我使用wsdl2java创建Web服务objetcs。现在,我想在肥皂呼叫中传递此对象之一。我怎样才能做到这一点?我想在肥皂主体元素中传递我的自定义对象,该怎么办?
我的代码:
SOAPBody soapbody = soapmessage.getSOAPBody();
SOAPBodyElement element = soapbody.addBodyElement(soapbodyName);
element.addChildElement(myCustomObject); <-- it gives error here that I can not pass my object here.
最佳答案
您需要使用JAXBElement
和wsdl2java生成的ObjectFactory
将其封送至SOAPBody:
JAXBElement<MyCustomObject> myCustomObjectElement =
new ObjectFactory().createMyCustomObject(myCustomObject);
jaxbContext.createMarshaller().marshal(myCustomObjectElement, soapbody);