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

我刚刚开始使用NodeJS,并开始使用milewise的node-soap与SOAP服务进行交谈 。 我正在使用基本的电子邮件地址validationSOAP API作为我的testing用例。

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

我的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格式化,以及如何返回输出。 这就是说:

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

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

我使用soapUI来testing这个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[]意思。 如果它是一个对象,它应该是请求。 因此,如果您尝试如下的参数,它可能会工作:

 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?