Node.js: how to consume SOAP XML web service Node.js: how to consume SOAP XML web service xml xml

Node.js: how to consume SOAP XML web service


You don't have that many options.

You'll probably want to use one of:


I think that an alternative would be to:

Yes, this is a rather dirty and low level approach but it should work without problems


If node-soap doesn't work for you, just use node request module and then convert the xml to json if needed.

My request wasn't working with node-soap and there is no support for that module beyond the paid support, which was beyond my resources. So i did the following:

  1. downloaded SoapUI on my Linux machine.
  2. copied the WSDL xml to a local file
    curl http://192.168.0.28:10005/MainService/WindowsService?wsdl > wsdl_file.xml
  3. In SoapUI I went to File > New Soap project and uploaded my wsdl_file.xml.
  4. In the navigator i expanded one of the services and right clickedthe request and clicked on Show Request Editor.

From there I could send a request and make sure it worked and I could also use the Raw or HTML data to help me build an external request.

Raw from SoapUI for my request

POST http://192.168.0.28:10005/MainService/WindowsService HTTP/1.1Accept-Encoding: gzip,deflateContent-Type: text/xml;charset=UTF-8SOAPAction: "http://Main.Service/AUserService/GetUsers"Content-Length: 303Host: 192.168.0.28:10005Connection: Keep-AliveUser-Agent: Apache-HttpClient/4.1.1 (java 1.5)

XML from SoapUI

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:qtre="http://Main.Service">   <soapenv:Header/>   <soapenv:Body>      <qtre:GetUsers>         <qtre:sSearchText></qtre:sSearchText>      </qtre:GetUsers>   </soapenv:Body></soapenv:Envelope> 

I used the above to build the following node request:

var request = require('request');let xml =`<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:qtre="http://Main.Service">   <soapenv:Header/>   <soapenv:Body>      <qtre:GetUsers>         <qtre:sSearchText></qtre:sSearchText>      </qtre:GetUsers>   </soapenv:Body></soapenv:Envelope>`var options = {  url: 'http://192.168.0.28:10005/MainService/WindowsService?wsdl',  method: 'POST',  body: xml,  headers: {    'Content-Type':'text/xml;charset=utf-8',    'Accept-Encoding': 'gzip,deflate',    'Content-Length':xml.length,    'SOAPAction':"http://Main.Service/AUserService/GetUsers"  }};let callback = (error, response, body) => {  if (!error && response.statusCode == 200) {    console.log('Raw result', body);    var xml2js = require('xml2js');    var parser = new xml2js.Parser({explicitArray: false, trim: true});    parser.parseString(body, (err, result) => {      console.log('JSON result', result);    });  };  console.log('E', response.statusCode, response.statusMessage);  };request(options, callback);