curl改写的请求:
curl -X POST -H "Content-Type: text/xml" -H "Cache-Control: no-cache" -d '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<SMSRequest xmlns="http://aaaaaaaa/">
<USERNAME>test</USERNAME>
<PASSWORD>test</PASSWORD>
</SMSRequest>
</soap:Body>
</soap:Envelope>' "http://bbbbbbbbbbbbbbbbbbbbbb.wsdl"
返回参数
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<SMSResponse>command=MT_RESPONSE&mterrcode=000
</SMSResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Spring主要代码:
Document doc=DocumentHelper.createDocument();
//根节点
Element eleSMSRequest = doc.addElement("SMSRequest","http://aaaaaaaa/");
eleSMSRequest.addElement("USERNAME").setText("test");
eleSMSRequest.addElement("PASSWORD").setText("test");
//从Spring中获取 WebServiceTemplate 协议 SOAP_1_1_PROTOCOL
WebServiceTemplate wst = (WebServiceTemplate)DoradoContext.getCurrent().getWebApplicationContext().getBean("webServiceTemplate");
MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
SaajSoapMessageFactory newSoapMessageFactory = new SaajSoapMessageFactory(messageFactory);
wst.setMessageFactory(newSoapMessageFactory);
//执行发送动作
StreamSource source = new StreamSource(new StringReader(doc.asXML()));
StringResult result = new StringResult();
wst.sendSourceAndReceiveToResult(source, result);