我在java中创建一个soap请求。基本上我从我的休息api呼叫肥皂服务。 我必须创建一个应该这样的请求。
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:impl="http://impl.service.payment.wallet.paytm.com/">
<SOAP-ENV:Header>
<mid>125FD26C</mid>
<phone>9958127957</phone>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<impl:withdraw>
<operationType>WITHDRAW_MONEY</operationType>
<request>
<currencyCode>INR</currencyCode>
</request>
</impl:withdraw>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我在创建标题方面遇到了问题。
SOAPHeader soapHeader = envelope.getHeader();
soapHeader.addChildElement("mid").addTextNode(merchantGuid);
soapHeader.addChildElement("phone").addTextNode("9958127957");
但这给了我HeaderElements must be namespace qualified
的错误。
答案 0 :(得分:0)
处理XML文档非常复杂,但这就是你需要做的事情。
SOAPHeader header = request.getSOAPHeader();
//Get the document
Document doc=header.getOwnerDocument();
//Create first tag mid and its value
Element el1=doc.createElement("mid");
el1.setTextContent(merchantGuid);
//Create second tag and its value
Element el2=doc.createElement("phone");
el2.setTextContent("9958127957");
//Add both tags to the SOAPHeader
header.appendChild(el1);
header.appendChild(el2);