用soap调用webservice天气接口遇到的问题,请高人帮忙解答
发布于 10 年前 作者 ngivan 6599 次浏览 最后一次编辑是 8 年前 来自 问答

这两周开始学习node,打算做一个天气采集程序,用soap调用接口的时候报错:请高人指点下迷津 TypeError: Cannot call method ‘setSOAPAction’ of undefined at C:\Documents and Settings\wuyfl\webService.js:5:11 at C:\Documents and Settings\wuyfl\node_modules\soap\lib\soap.js:49:5 at C:\Documents and Settings\wuyfl\node_modules\soap\lib\soap.js:33:16 at C:\Documents and Settings\wuyfl\node_modules\soap\lib\wsdl.js:1754:9 at Request._callback (C:\Documents and Settings\wuyfl\node_modules\soap\lib\http.js:49:7) at self.callback (C:\Documents and Settings\wuyfl\node_modules\soap\node_modules\request\request.js:373:22) at Request.emit (events.js:95:17) at Request.onRequestError (C:\Documents and Settings\wuyfl\node_modules\soap\node_modules\request\request.js:971:8) at ClientRequest.emit (events.js:95:17) at Socket.socketErrorListener (http.js:1551:9)

下面代码: var soap = require(‘soap’); var url = ‘http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl’; var args = { byProvinceName: ‘北京’}; soap.createClient(url, function(err, client) { client.setSOAPAction(“http://www.webxml.com.cn/WebServices/WeatherWebService.asmx/getSupport”); client.getSupportCity(args, function(err, result) { if (err) { throw err; } console.log(result);

});

});

3 回复

我之前也想搞过类似的WebService,一样遇到没有方法的错误。。。。还没想通是为何。。。。

client 没有 setSOAPAction方法。 你打印下ERR看看

网上有说将soap模块中lib/client.js 中:soapAction = this.SOAPAction ? this.SOAPAction(ns, name) : (method.soapAction || (((ns.lastIndexOf("/") !== ns.length - 1) ? ns + “/” : ns) + name)), 更改成soapAction = method.soapAction || (((ns.lastIndexOf("/") != ns.length - 1) ? ns + “/” : ns) + name), 测试也ok,你可以试一下,没有具体研究

回到顶部