Anton Cagle
Anton Cagle

Reputation: 27

calling a SOAP service from Node.js

I just started using Node.js, and I am trying to consume a SOAP service using the node soap extension. I am just using a sample service call right now, but can't seem to get it up and running.

var soap = require('soap');
var fs = require('fs');

reqURL = fs.readFile('www.webservicex.net/stockquote.asmx?WSDL', 'UTF-8', function(err, data){
    if(err) console.log(err)
        soap.createClient(data, function(err, client){
            client.StockQuote.StockQuoteSoap.GetQuote({symbol:'NKE'}, function(err, response){
                if(err) console.log(err);
                    console.log(response);
            });
            console.log('Here is the SOAP sent to ' + data + client.lastrequest);
        });
});

here is the error I am getting:

{ [Error: ENOENT, open 'c:\dev\workspace\WebDevClass\node\www.webservicex.net\st
ockquote.asmx?WSDL']
  errno: -4058,
  code: 'ENOENT',
  path: 'c:\\dev\\workspace\\WebDevClass\\node\\www.webservicex.net\\stockquote.
asmx?WSDL' }
fs.js:491
  binding.open(pathModule._makeLong(path),
          ^
TypeError: path must be a string
    at TypeError (native)
    at Object.fs.open (fs.js:491:11)
    at Object.fs.readFile (fs.js:262:6)
    at open_wsdl (c:\dev\workspace\WebDevClass\node\node_modules\soap\lib\wsdl.j
s:1832:8)
    at _requestWSDL (c:\dev\workspace\WebDevClass\node\node_modules\soap\lib\soa
p.js:31:5)
    at Object.createClient (c:\dev\workspace\WebDevClass\node\node_modules\soap\
lib\soap.js:48:3)
    at c:\dev\workspace\WebDevClass\node\cliSoapTest.js:6:14
    at fs.js:263:20
    at FSReqWrap.oncomplete (fs.js:95:15)

Upvotes: 0

Views: 5600

Answers (2)

Rajan Rajan M
Rajan Rajan M

Reputation: 75

Check this out

var soap = require("soap");
var url = 'http://www.webservicex.net/stockquote.asmx?WSDL';

reqURL = soap.createClient(url, function(err, client){
    if(err) {
        console.log(err);
        return;
    }

    client.StockQuote.StockQuoteSoap.GetQuote({symbol:'NKE'}, function(err, response){
            if(err) {
                console.log(err);
                return;
            }

            console.log(response);
    });
});

Upvotes: 5

rprandi
rprandi

Reputation: 127

Try this

var soap = require('soap');
var url = 'www.webservicex.net/stockquote.asmx?WSDL'

reqURL = soap.createClient(url, function(err, client){
    client.StockQuote.StockQuoteSoap.GetQuote({symbol:'NKE'}, function(err, response){
            if(err) console.log(err);
                console.log(response);
        });
    });
});

Upvotes: -1

Related Questions