harish
harish

Reputation: 628

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

Upvotes: 7

Views: 6846

Answers (2)

Benjamin RD
Benjamin RD

Reputation: 12034

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

Basically, the node-soap package uses Promises to keep the requests concurrent.

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

Upvotes: 11

Oleg Kuralenko
Oleg Kuralenko

Reputation: 11543

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

Upvotes: 3

Related Questions