我正在使用Spring-WS调用SOAP webservice。这个webservice要求我在SOAP标头中传递一些信息,如下所示:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<CustomHeaderElement>
<clientID>xyz</clientID>
<wsdlVersion>1.0</wsdlVersion>
<serviceType>ExampleService_v1</serviceType>
</CustomHeaderElement>
</soapenv:Header>
<soapenv:Body>
...
</soapenv:Body>
</soapenv:Envelope>
我已经弄清楚如何添加顶级CustomHeaderElement了,但是我没有在Spring-WS API中看到任何允许我添加子元素的内容。以下是我目前的代码:
WebServiceTemplate template = ...;
template.marshalSendAndReceive(request, new WebServiceMessageCallback(){
public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException{
SoapMessage soapMessage = (SoapMessage)message;
SoapHeader soapHeader = soapMessage.getSoapHeader();
QName qName = new QName("CustomHeaderElement");
SOAPHeaderElement headerElement = soapHeader.addHeaderElement(qName);
//would like to do something like headerElement.addChild(clientIdNode);
}
});
问题是headerElement似乎没有任何方式来添加子元素。我知道可以添加属性,但这并不适用于此服务调用。是否有人知道如何向我的自定义头部添加必要的子元素?