您的位置:首页 > Web前端 > Node.js

Node.js 使用 soap 模块请求 WebService 服务接口

2016-11-22 18:30 716 查看
项目开发中需要请求webservice服务,前端主要使用node.js 作为运行环境,因此可以使用soap进行请求。

使用SOAP请求webservice服务的流程如下:

1、进入项目目录,安装 soap 模块

> npm install soap --save-dev

2、在项目的 node_modules 目录下找到soap模块下的 lib > client.js,





修改代码:

soapAction = ((ns.lastIndexOf("/") !== ns.length - 1) ? ns + "/" : ns) + name;


为:

soapAction = method.soapAction || (((ns.lastIndexOf('/') !== ns.length - 1) ? ns + '/': ns) + name);




3、请求代码

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.getSupportCity(args, function(err, result) {
if (err) {
console.log(err);
}else {
console.log(result);
}
});
});


4、运行代码,在命令行窗口查看结果



除了soap模块,还有strong-soap, easysoap 等模块都可以请求webservice服务。使用方法类似。

关于webservice、SOAP、WSDL的相关知识,可以查看以下链接:

http://blog.csdn.net/u014511737/article/details/46986389

http://www.jianshu.com/p/5443f90e36de

https://segmentfault.com/a/1190000006807566

http://download.csdn.net/detail/zxktxj/8643733
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: