问题
Hi can anyone help me out.
how to request soap web service and get the xml response. Senario: Using soap ui im sending wsdl url with username, password authentication and also i will send soap xml data and i gets reponse. Same thing how to achive using nodejs or sails.
In SoapUi My soap xml request is like
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tier="http://HCSLN9191-GMS.gois.ito.unisys.com/Tier1ICLStd:Tier1ICLMB_StdDispatch">
<soapenv:Header/>
<soapenv:Body>
<tier:UnisysMB_Dispatch>
<PayLoad>SomeData</PayLoad>
</tier:UnisysMB_Dispatch>
</soapenv:Body>
</soapenv:Envelope>
And My Soap Authentication is like
$UserName : xyz & password:xyz
My wsdl url is http://esbuatt1wm.ito.xyz.com:7001/ws/Tier1ICLStd_New:Tier1ICLMB_StdDispatch_New?WSDL
After provides this information i am getting xml response like
<ser-root:CommAck xmlns:ser-root="http://HCSLN1181-GMS.gois.ito.unisys.com/Tier1ICLStd_New:Tier1ICLMB_StdDispatch_New" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<CommAck>
<MB_UUID>cbbb683d-e9b1-4d12-b0db-8006134aad27</MB_UUID>
<ServiceID>McDonalds</ServiceID>
<Acknowledge>0</Acknowledge>
<Comment>Payload does not contain the pattermatch xpath.</Comment>
</CommAck>
</ser-root:CommAck>
My Question is How to get that above xml response using node easy soap, i am new to soap concept. can anyboud help me out to give me the proper snippet for the above senario.....
回答1:
You can use this package https://www.npmjs.com/package/soap. Examples are in the same link. I have pasted below some of the contents:
Install with npm:
npm install soap
Example:
var soap = require('soap');
var url = 'http://example.com/wsdl?wsdl';
var args = {name: 'value'};
soap.createClient(url, function(err, client) {
client.MyFunction(args, function(err, result) {
console.log(result);
});
});
BasicAuthSecurity
client.setSecurity(new soap.BasicAuthSecurity('username', 'password'));
回答2:
You can use Axios a promise based Nodejs package.
an Example:
const baseURL = '';
const apiKey = '';
const xmlBody = `XML body here // you can also add api key using ${apiKey} like this if needed`;
axios.post(BaseURL,xmlBody,{
headers: {
'Content-Type': 'text/xml'
}
}
).then(response => {console.log(response.data)}
).catch(err => {console.log(err)});
回答3:
You can use the soap module. I had to eventually use it so documented it below in the link provided. for username and password, if your WSDL is password protected then you would also need to set the correct wsdl_headers in the client that you would create with node-soap
check out this answer:https://stackoverflow.com/a/29036380/4157003
Additionally, You also need to set the correct security mechanism before using any service
client.setSecurity(new soap.BasicAuthSecurity('username', 'password'));
You can check this link for more info https://codecalls.com/2020/05/17/using-soap-with-node-js/
来源:https://stackoverflow.com/questions/42686370/soap-request-using-nodejs