Node.js 使用 soap 模組請求 WebService 服務介面

來源:互聯網
上載者:User

標籤: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 服務介面

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.