6

我正在使用强肥皂节点模块,我想调用 web 服务,我有 wsdl 文件。

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 ??
});
4

2 回答 2

10

我不确定它是如何strong-soap工作的。但是,我有一些SOAP使用node-soap的实现

基本上,使用node-soapPromises来保持请求的并发性。

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);
      });
  });
于 2018-02-16T16:16:48.900 回答
3

让我们使用以下示例 SOAP 服务

通过主机名/域名(WhoIS)获取域名注册记录

从您的代码判断您想使用本地可用的.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您尝试使用的是用于使用 WSDL 结构的

将 WSDL 加载到树形中。遍历 WSDL 树以获取绑定、服务、端口、操作等。

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

于 2018-02-12T18:18:01.963 回答