在Node.js中使用node-soap通过Soap发送参数

Sending arguments via Soap in Node.js using node-soap

本文关键字:Soap 通过 参数 node-soap Node js      更新时间:2023-09-26

我刚刚开始使用NodeJS,我正在研究使用mile的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[]中的括号是什么意思?

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

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

但是,它返回"Access is denied"。

我使用soapUI测试这个web服务,它返回相同的结果。

我尝试了另一个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);
    });
});

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

var args = {request[]: ["my@emailadress.com", "another email adress if you
want"]};
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?