標籤:detail 環境 support art console modules service mod install
項目開發中需要請求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、請求代碼
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 });
4、運行代碼,在命令列視窗查看結果
除了soap模組,還有strong-soap, easysoap 等模組都可以請求webservice服務。使用方法類似。
關於webservice、SOAP、WSDL的相關知識,可以查看以下連結:
http://blog.csdn.net/u014511737/article/details/46986389
http://www.jianshu.com/p/5443f90e36de
1190000006807566
http://download.csdn.net/detail/zxktxj/8643733
Node.js 使用 soap 模組請求 WebService 服務介面