2013-04-15 70 views
5

我刚刚开始使用NodeJS,并且我正在使用milewise's node-soap开始与SOAP服务通话。我正在使用基本的电子邮件地址验证SOAP API作为我的测试用例。使用node-soap通过Soap在Soap中发送参数

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

我的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:"[email protected]"}, function(err, result){ 
      console.log(result); 
    }); 
}); 

的client.describe()命令告诉我的API是怎么想它的输入格式,以及它将如何返回它的输出。这是什么,是说:

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

然而,当我送参数作为一个对象:{request:"[email protected]"}

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

回答

9

它应该工作,如果你添加命名空间的请求参数。 这是一个示例代码。

var soap = require('soap'); 

var url = "http://www.restfulwebservices.net/wcf/EmailValidationService.svc?wsdl"; 

var args = {"tns:request":"[email protected]"}; 

soap.createClient(url, function(err, client){ 
    client.EmailValidationService.BasicHttpBinding_IEmailValidationService.Validate(args, function(err, result){ 
      if (err) throw err; 
      console.log(result); 
    }); 
}); 

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

我用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); 
    }); 
}); 
1

ValidateResult需要一个数组请求。这就是request[]的含义。如果它是一个对象,它应该只是请求。因此,如果你尝试ARGS如下,它可能工作:

var args = {request[]: ["[email protected]", "another email adress if you 
want"]}; 
-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? 
+0

这并没有真正回答这个问题。如果您有不同的问题,可以通过单击[提问](https://stackoverflow.com/questions/ask)来提问。您可以[添加赏金](https://stackoverflow.com/help/privileges/set-bounties)在您拥有足够的[声誉](https://stackoverflow.com/help/)后引起对此问题的更多关注什么声誉)。 - [来自评论](/ review/low-quality-posts/17793753) – Psi