在SOAP:Body中使用Axis2编码xml数据生成客户端存根

时间:2012-03-28 12:54:22

标签: xml web-services soap axis2

我正面临使用Axis2生成的客户端存根的问题。

它正在编码我在请求中发送的xml数据。

param1valueparam2value

而不是像

那样转换它
<Query><Param1>param1value</Param1><Param2>param2value</Param2></Query>

将其转换为以下声明

<Query><Param1>param1value</Param1><Param2>param2value</Param2></Query>

任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:2)

如果您尝试在soap body中发送XML,请将其包含在CDATA中。

修改存根代码并更改存根创建元素的方式

SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope envelope = factory.getDefaultEnvelope();    
OMElement xmlElement= factory.createOMElement("cdatatoservice", envelope.getDefaultNamespace());
envelope.getBody().addChild(xmlElement);

OMTextImpl omText = (OMTextImpl) xmlElement.getOMFactory().createOMText(xmlElement, xmlForCdata, XMLStreamConstants.CDATA);
xmlElement.addChild(omText);

System.out.println(envelope.toStringWithConsume());