简体   繁体   中英

SOAP Request using nodejs

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.....

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'));

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)});

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/

You can use the easy-soap-request npm package.

If you want to create the SOAP header passwordDigest in nodejs,

const crypto = require('crypto');

function passwordDigest(created, nonce, pass) {
  // Password_Digest = Base64 ( SHA-1 ( bytes(decode64(nonce)) + bytes(created) + bytes(password) ) )
  let pd = Int8Array.from([...Int8Array.from(Buffer.from(nonce, 'base64')),
                           ...Int8Array.from(Buffer.from(created)),
                           ...Int8Array.from(Buffer.from(pass))]);
  pd = crypto.createHash('sha1').update(pd).digest('base64');
  return pd;
}

More detailed explanation on this post https://stackoverflow.com/a/66824784/15485314

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM