java spring webservice中如何在soap头中添加子元素。
我尝试了两种方法,但没有任何效果请建议我需要做什么?
第一种方法:-
soapHeaderString.append("<tem:Culture>en_Us</tem:Culture><tem:AgentCode>PumpkinSafari</tem:AgentCode><tem:PartnerID></tem:PartnerID><tem:Password>PMP22#in</tem:Password>");
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
// Here we create a Source Tree
StringSource stringSource = new StringSource(soapHeaderString.toString());
transformer.transform(stringSource, soapHeader.getResult());
但它给了我错误
The prefix "tem" for element "tem:Culture" is not bound.
第二种方法:-
SoapHeaderElement headerElement=soapMessage.getSoapHeader().addHeaderElement(new QName("http://tempuri.org/", "SOAPHeaderAuth","tem"));
headerElement.setText(soapHeaderString.toString());
它会产生未转义的序列,因此服务提供商会给出错误,因为它无法理解请求。
请帮助我解决问题需要做些什么。