javascript 使用 node-soap 在 Node.js 中通过 Soap 发送参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16006988/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Sending arguments via Soap in Node.js using node-soap
提问by Caleb Larsen
I am just getting started with NodeJS and I digging into talking to a SOAP service using milewise's node-soap. I am using a basic email address validation SOAP API as my test case.
我刚刚开始使用NodeJS,我正在研究使用milewise 的 node-soap与 SOAP 服务进行对话。我使用基本的电子邮件地址验证 SOAP API 作为我的测试用例。
I don't seem to understand the correct way to format my arguments lists.
我似乎不明白格式化参数列表的正确方法。
My SOAP client code:
我的 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);
});
});
The client.describe() command tells me how the API would like its input formatted, and how it will return its output. This is what is says:
client.describe() 命令告诉我 API 如何对其输入进行格式化,以及它将如何返回其输出。这就是所说的:
{ input: { 'request[]': 'xs:string' },
output: { 'ValidateResult[]': 'xs:boolean' } }
{ input: { 'request[]': 'xs:string' },
output: { 'ValidateResult[]': 'xs:boolean' } }
However when I send the arguments as an object: {request:"[email protected]"}
但是,当我将参数作为对象发送时: {request:"[email protected]"}
I feel like my problems lies in how I am defining the arguments object...what do the brackets in request[]
mean?
我觉得我的问题在于我如何定义参数对象......括号request[]
是什么意思?
回答by Andy Cheng
It should work, if you add namespace on request argument. This is a sample code.
如果您在请求参数上添加命名空间,它应该可以工作。这是一个示例代码。
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);
});
});
However, it returns "Access is denied".
但是,它返回“访问被拒绝”。
I use soapUI to test this web service, it returns the same result.
我使用soapUI 来测试这个Web 服务,它返回相同的结果。
I try another web service, and it works.
我尝试了另一个网络服务,它工作正常。
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);
});
});
回答by hakan
ValidateResult
takes an array request. That is what request[]
means. If it was an object it should just be request. Therefore, if you try args as follows, it may work:
ValidateResult
接受一个数组请求。就是这个request[]
意思。如果它是一个对象,它应该只是请求。因此,如果您按如下方式尝试 args,它可能会起作用:
var args = {request[]: ["[email protected]", "another email adress if you
want"]};
回答by Sujit Shrestha
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?