[英]Creating a soap Request in java
I am creating a soap request in java. 我在Java中创建一个肥皂请求。 Basically I am calling a soap service from my rest api.
基本上,我从其余的api调用肥皂服务。 I have to create a request which should like this.
我必须创建一个这样的请求。
<?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>
I am having problem in creating Headers. 我在创建标题时遇到问题。
SOAPHeader soapHeader = envelope.getHeader();
soapHeader.addChildElement("mid").addTextNode(merchantGuid);
soapHeader.addChildElement("phone").addTextNode("9958127957");
But this is giving me error that HeaderElements must be namespace qualified
. 但这给我的错误是
HeaderElements must be namespace qualified
。
Its quite complex to deal with XML Documents, but this is how, you need to do. 处理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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.