项目开发中须要请求webservice服务,前端主要使用node.js 做为运行环境,所以能够使用soap进行请求。前端
使用SOAP请求webservice服务的流程以下:node
一、进入项目目录,安装 soap 模块web
> npm install soap --save-devnpm
二、在项目的 node_modules 目录下找到soap模块下的 lib > client.js,segmentfault
修改代码:ui
soapAction = ((ns.lastIndexOf("/") !== ns.length - 1) ? ns + "/" : ns) + name;
为:url
soapAction = method.soapAction || (((ns.lastIndexOf('/') !== ns.length - 1) ? ns + '/': ns) + name);
三、请求代码spa
1 var soap = require('soap'); 2 var url = 'http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl'; 3 var args = { byProvinceName: '浙江'}; 4 soap.createClient(url, function(err, client) { 5 client.getSupportCity(args, function(err, result) { 6 if (err) { 7 console.log(err); 8 }else { 9 console.log(result); 10 } 11 }); 12 });
四、运行代码,在命令行窗口查看结果.net
除了soap模块,还有strong-soap, easysoap 等模块均可以请求webservice服务。使用方法相似。命令行
关于webservice、SOAP、WSDL的相关知识,能够查看如下连接:
http://blog.csdn.net/u014511737/article/details/46986389
http://www.jianshu.com/p/5443f90e36de