我正在使用apache axis2处理Web服务,并且我已生成所需的客户端代码。客户端请求应如下所示:
`<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:v2="http://www.huawei.com.cn/schema/common/v2_1"
xmlns:loc="http://www.csapi.org/schema/parlayx/sms/notification_manager/v2_3/local">
<soapenv:Header>
<RequestSOAPHeader xmlns="http://www.huawei.com.cn/schema/common/v2_1">
<spId>35000001</spId>
<spPassword>de96d901b3bad1db2aab76b7b0b202f2</spPassword>
<serviceId>0003062000001100</serviceId>
<timeStamp>20120731064245</timeStamp>
</RequestSOAPHeader>
</soapenv:Header>
<soapenv:Body>
<loc:startSmsNotification>
<loc:reference>
<endpoint>>http://10.138.30.153:9080/notify</endpoint>
<interfaceName>notifySmsReception</interfaceName>
<correlator>1232</correlator>
</loc:reference>
<loc:smsServiceActivationNumber>23424
</loc:smsServiceActivationNumber> <!--Optional: -->
<loc:criteria>Love</loc:criteria>
</loc:startSmsNotification>
</soapenv:Body>
</soapenv:Envelope>`
我能够在我的请求中添加正文消息,但不能添加soap标头信息。标头信息是验证请求所必需的。如何在生成的客户端代码中将soap标头信息添加到我的soap请求中?
答案 0 :(得分:2)
嗨,马丁,SDP材料在互联网上不是现成的,但请试着跟随。
OMFactory fac = OMAbstractFactory.getOMFactory();
SOAPFactory sfac = OMAbstractFactory.getSOAP11Factory();
OMNamespace omNs = fac.createOMNamespace(nameSpace, "ns1");
SOAPHeaderBlock block_RequestSOAPHeader = sfac.createSOAPHeaderBlock(
SOAPHEADER_RequestSOAPHeader, omNs);
try
{
SOAPHeaderBlock block_spId = sfac.createSOAPHeaderBlock(SOAPHEADER_SPID, omNs);
block_spId.addChild(sfac.createOMText(spId));
String md_password = md5Digest(spId, spPassword, timeStamp);
SOAPHeaderBlock block_spPassword = sfac.createSOAPHeaderBlock(SOAPHEADER_SPPASSWORD, omNs);
block_spPassword.addChild(sfac.createOMText(md_password));
SOAPHeaderBlock block_timeStamp = sfac.createSOAPHeaderBlock(SOAPHEADER_TIMESTAMP, omNs);
block_timeStamp.addChild(sfac.createOMText(timeStamp));
SOAPHeaderBlock block_serviceId = sfac.createSOAPHeaderBlock(SOAPHEADER_SERVICEID, omNs);
block_serviceId.addChild(sfac.createOMText("your text"));
SOAPHeaderBlock block_linkId = sfac.createSOAPHeaderBlock(SOAPHEADER_LINKID, omNs);
block_linkId.addChild(sfac.createOMText(linkID));
SOAPHeaderBlock block_OA = sfac.createSOAPHeaderBlock(SOAPHEADER_OA, omNs);
block_OA.addChild(sfac.createOMText(OA));
SOAPHeaderBlock block_FA = sfac.createSOAPHeaderBlock(SOAPHEADER_FA, omNs);
block_FA.addChild(sfac.createOMText(FA));
block_RequestSOAPHeader.addChild(block_spId);
block_RequestSOAPHeader.addChild(block_spPassword);
block_RequestSOAPHeader.addChild(block_serviceId);
block_RequestSOAPHeader.addChild(block_timeStamp);
block_RequestSOAPHeader.addChild(block_linkId);
block_RequestSOAPHeader.addChild(block_OA);
block_RequestSOAPHeader.addChild(block_FA);
/*
*
* <soapenv:Header>
* <ns1:RequestSOAPHeader xmlns:ns1="http://www.xxxxxxxx.xxxxxx.xxxxxx/common/v2_1">
* <ns1:spId>your spid</tns:spId>
* <ns1:spPassword>your password</tns:spPassword>
* <ns1:timeStamp>your timestamp</tns:timeStamp>
* <ns1:linkId>your linkid</tns:linkId>
* <ns1:OA>tel:your msisdn1</tns:OA>
* <ns1:FA>tel:msisdn1</tns:FA>
* </ns1:RequestSOAPHeader>
* </soapenv:Header>
*/
serviceClient.addHeader(block_RequestSOAPHeader);