4

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

mahesh bhagirath
  • 151
  • 1
  • 1
  • 11

4 Answers4

5

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'));
manishg
  • 9,520
  • 1
  • 16
  • 19
  • 2
    Hi manishg i am new to soap concept, what will be the args we need to paas over there in your ex..? – mahesh bhagirath Mar 09 '17 at 06:44
  • Hi @maheshbhagirath the args is the object which your wsdl accepts. If it takes nothing then send empty object. The soap will convert that object to xml. – Vikas Chandra Oct 10 '17 at 09:08
  • 2
    Is `MyFunction` is that defined on the wsdl? Also, this example taken from the soap readme doesn't really answer the question as it doesn't use any XML that the question provided. – Michael Brawn Jul 31 '19 at 21:35
  • This doesn't answer the question , you are just copy pasting document from npm soap package https://www.npmjs.com/package/soap . Which is used to create soap client and server (a socket based listener and client). Not to make an http request. – Akshay Hazari Feb 19 '20 at 13:07
  • I did mention that in my answer that I have pasted contents from that package. Soap uses ‘http’ – manishg Feb 19 '20 at 13:15
0

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

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/

Nitin Khare
  • 147
  • 2
  • 10
0

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

ToniG
  • 111
  • 1
  • 5