2017-08-06 61 views
6

我正在使用强大的soap节点模块我想调用webservice,我有wsdl文件。如何通过节点j消费wsdl webservice

var soap = require('strong-soap').soap; 
var WSDL = soap.WSDL; 
var path = require('path'); 
var options = {}; 
WSDL.open('./wsdls/RateService_v22.wsdl',options, 
    function(err, wsdl) { 
    // You should be able to get to any information of this WSDL from this object. Traverse 
    // the WSDL tree to get bindings, operations, services, portTypes, messages, 
    // parts, and XSD elements/Attributes. 

    var service = wsdl.definitions.services['RateService']; 
    //console.log(service.Definitions.call()); 
    //how to Call rateService ?? 
}); 
+0

对我的答案有任何反馈? – ffeast

回答

3

允许使用以下sample SOAP service

获取域名注册记录的主机名/域名(WHOIS)

从代码判断您想使用a .wsdl文件在本地可用,因此保存它:

mkdir wsdl && curl 'http://www.webservicex.net/whois.asmx?WSDL' > wsdl/whois.wsdl 

现在让我们用下面的代码进行查询:

'use strict'; 

var soap = require('strong-soap').soap; 
var url = './wsdl/whois.wsdl'; 

var requestArgs = { 
    HostName: 'webservicex.net' 
}; 

var options = {}; 
soap.createClient(url, options, function(err, client) { 
    var method = client['GetWhoIS']; 
    method(requestArgs, function(err, result, envelope, soapHeader) { 
    //response envelope 
    console.log('Response Envelope: \n' + envelope); 
    //'result' is the response body 
    console.log('Result: \n' + JSON.stringify(result)); 
    }); 
}); 

它会产生一些有意义的结果。 WSDL.open你想用的是meant for与WSDL结构

加载WSDL加工成树的形式。遍历WSDL树以获得绑定,服务,端口,操作等。

你不一定需要它来调用服务

6

我不知道如何strong-soap作品。 但是,我一直在使用node-soap

SOAP一些实现基本上与node-soap包使用Promises保持请求并发性。

var soap = require('soap'); 
    var url = 'http://www.webservicex.net/whois.asmx?WSDL'; 
    var args = {name: 'value'}; 
    soap.createClient(url, function(err, client) { 
     client.GetWhoIS(args, function(err, result) { 
      console.log(result); 
     }); 
    });