从Node.js调用SOAP服务

时间:2015-05-29 17:55:00

标签: javascript node.js web-services soap

我刚开始使用Node.js,我正在尝试使用节点soap扩展来使用SOAP服务。我现在正在使用示例服务调用,但似乎无法启动并运行。

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

这是我得到的错误:

{ [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)

2 个答案:

答案 0 :(得分:4)

检查出来

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

答案 1 :(得分:-1)

试试这个

SELECT p.id, name, 
   count(distinct lwho.id) delivered_likes, 
   count(distinct lwhom.id) received_likes, 
   count(distinct lmut.id) mutual_likes
FROM people AS p
LEFT JOIN likes AS lwho ON p.id = lwho.who
LEFT JOIN likes AS lwhom ON p.id = lwhom.whom
LEFT JOIN likes AS lmut ON lwhom.who = lmut.whom AND lwhom.whom = lmut.who
GROUP BY p.id,p.name;