Web Services 如何通过节点js使用wsdl webservice

w46czmvw  于 2022-11-15  发布在  其他
关注(0)|答案(2)|浏览(242)

我正在使用强soap节点模块,我想调用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 ??
});
i34xakig

i34xakig1#

我不确定strong-soap是如何工作的,但是我有一些SOAP的实现,使用node-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);
    });
});
qzlgjiam

qzlgjiam2#

让我们使用以下sample SOAP service
按主机名/域名(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树以获取绑定、服务、端口、操作等。
调用服务不一定需要它

相关问题