【问题标题】:Sending arguments via Soap in Node.js using node-soap使用 node-soap 在 Node.js 中通过 Soap 发送参数
【发布时间】:2013-04-07 02:00:47
【问题描述】:

我刚刚开始使用 NodeJS,并且正在深入研究使用 milewise's node-soap 与 SOAP 服务通信。我正在使用一个基本的电子邮件地址验证 SOAP API 作为我的测试用例。

我似乎不明白格式化参数列表的正确方法。

我的 SOAP 客户端代码:

    var url = "http://www.restfulwebservices.net/wcf/EmailValidationService.svc?wsdl";
soap.createClient(url, function(err, client){
    console.log(client.describe().EmailValidationService.BasicHttpBinding_IEmailValidationService.Validate);
    client.Validate({result:"my@emailaddress.com"}, function(err, result){
            console.log(result);
    });
});

client.describe() 命令告诉我 API 如何对其输入进行格式化,以及它将如何返回其输出。就是这么说的:

{ input: { 'request[]': 'xs:string' }, output: { 'ValidateResult[]': 'xs:boolean' } }

但是,当我将参数作为对象发送时:{request:"my@emailaddress.com"}

我觉得我的问题在于我如何定义参数对象...request[] 中的括号是什么意思?

【问题讨论】:

    标签: javascript node.js object soap


    【解决方案1】:
    I have similar situation where i have accountId[] , i need to pass multiple accountID, when i pass like "tns:accountId[]": [2321,2345325], it failing saying incorrect request parameter, it comes as <tns:accountId[]>2321</tns:accountId[]>
    <tns:accountId[]>2345325</tns:accountId[]>.
    
    I need to get <tns:accountId>2321</tns:accountId>
    <tns:accountId>2345325</tns:accountId>. When i tried removing "[]", it comes as <accountId> only and  it is failing. Can someone please help me?
    

    【讨论】:

      【解决方案2】:

      ValidateResult 接受一个数组请求。这就是request[] 的意思。如果它是一个对象,它应该只是请求。因此,如果您尝试如下 args,它可能会起作用:

      var args = {request[]: ["my@emailadress.com", "another email adress if you
      want"]};
      

      【讨论】:

        【解决方案3】:

        如果您在请求参数上添加命名空间,它应该可以工作。 这是一个示例代码。

        var soap = require('soap');
        
        var url = "http://www.restfulwebservices.net/wcf/EmailValidationService.svc?wsdl";
        
        var args = {"tns:request":"my@emailaddress.com"};
        
        soap.createClient(url, function(err, client){
            client.EmailValidationService.BasicHttpBinding_IEmailValidationService.Validate(args, function(err, result){
                    if (err) throw err;
                    console.log(result);
            });
        });
        

        但是,它返回“访问被拒绝”。

        我使用soapUI来测试这个web服务,它返回的结果是一样的。

        我尝试了另一个网络服务,它可以工作。

        var soap = require('soap');
        
        var url = "http://www.restfulwebservices.net/wcf/StockQuoteService.svc?wsdl";
        
        var args = {"tns:request":"GOOG"};
        
        soap.createClient(url, function(err, client){
        
            client.StockQuoteService.BasicHttpBinding_IStockQuoteService.GetStockQuote(args, function(err, result){
                    if (err) throw err;
                    console.log(result);
            });
        });
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-10-20
          • 1970-01-01
          • 1970-01-01
          • 2017-11-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多