Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to consume wsdl webservice through node js

I am using strong-soap node module i want to make call to webservice, I have wsdl file.

var soap = require('strong-soap').soap;
var WSDL = soap.WSDL;
var path = require('path');
var options = {};
WSDL.open('./wsdls/RateService_v22.wsdl',options,
  function(err, wsdl) {
    // You should be able to get to any information of this WSDL from this object. Traverse
    // the WSDL tree to get  bindings, operations, services, portTypes, messages,
    // parts, and XSD elements/Attributes.

    var service = wsdl.definitions.services['RateService'];
    //console.log(service.Definitions.call());
    //how to Call rateService ??
});
like image 959
harish Avatar asked Aug 06 '17 18:08

harish


People also ask

How do I find the WSDL of a SOAP web service?

The interface to a SOAP web service is captured in WSDL. JAXB provides a way to generate Java classes from WSDL (or rather, the XSD contained in the <Types/> section of the WSDL). You can find the WSDL for the country service at http://localhost:8080/ws/countries.wsdl .


2 Answers

I'm not sure about how strong-soap works. But, I have some implementations of SOAP using node-soap

Basically, with the node-soap package uses Promises to keep the request concurrencies.

var soap = require('soap');
  var url = 'http://www.webservicex.net/whois.asmx?WSDL';
  var args = {name: 'value'};
  soap.createClient(url, function(err, client) {
      client.GetWhoIS(args, function(err, result) {
          console.log(result);
      });
  });
like image 51
Benjamin RD Avatar answered Oct 16 '22 00:10

Benjamin RD


Lets use the following sample SOAP service:

Get domain name registration record by Host Name / Domain Name (WhoIS)

To judge from your code you'd like to use a .wsdl file available locally, so saving it:

mkdir wsdl && curl 'http://www.webservicex.net/whois.asmx?WSDL' > wsdl/whois.wsdl

Now lets use the following code to query it:

'use strict';

var soap = require('strong-soap').soap;
var url = './wsdl/whois.wsdl';

var requestArgs = {
    HostName: 'webservicex.net'
};

var options = {};
soap.createClient(url, options, function(err, client) {
  var method = client['GetWhoIS'];
  method(requestArgs, function(err, result, envelope, soapHeader) {
    //response envelope
    console.log('Response Envelope: \n' + envelope);
    //'result' is the response body
    console.log('Result: \n' + JSON.stringify(result));
  });
});

It would produce some meaningful results. WSDL.open you're trying to use is meant for working with WSDL structure

Loads WSDL into a tree form. Traverse through WSDL tree to get to bindings, services, ports, operations, and so on.

You don't necessarily need it to call a service

like image 32
ffeast Avatar answered Oct 16 '22 00:10

ffeast