如何通过节点js使用wsdl webservice

时间:2017-08-06 18:44:26

标签: node.js web-services soap wsdl strong-soap

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

2 个答案:

答案 0 :(得分:7)

我不确定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);
      });
  });

答案 1 :(得分:3)

让我们使用以下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.openmeant for使用WSDL结构

  

将WSDL加载到树形式中。遍历WSDL树到达   绑定,服务,端口,操作等。

您不一定需要它来呼叫服务