gpt4 book ai didi

java - 我想在 soap body 元素中传递我的自定义对象,该怎么做?

转载 作者:行者123 更新时间:2023-11-29 03:48:47 25 4
gpt4 key购买 nike

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

我的代码:

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);

关于java - 我想在 soap body 元素中传递我的自定义对象,该怎么做?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9683032/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com