Node.js soap请求从参数中删除命名空间

时间:2015-11-09 12:01:25

标签: node.js soap node-soap

我无法向服务发送正确的参数。

使用的代码:

var soap = require('soap');
var url = 'http://example.com';

soap.WSDL.prototype.ignoredNamespaces = ['targetNamespace', 'typedNamespace'];

var args = {'name':'test'};

soap.createClient(url, function(err, client) {
    client.Hello(args, function(err,result,res){
        console.log(result);
        console.log(client.lastRequest);
    });
});

Hello函数应返回字符串“Hello test!”。但是,我得到了:

'Hello null !'

发送的请求是:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ....><soap:Body>
<tns:Hello xmlns:tns="http://example/">
    <tns:name>test</tns:name>
</tns:Hello></soap:Body></soap:Envelope>

,其中     测试 是有趣的部分。该服务期待

<name>test</name>

没有命名空间(我用http://www.soapclient.com/测试了这个)

所以,问题是:如何在没有附加tns的情况下发送请求参数? (tns:name =&gt; name)谢谢!

2 个答案:

答案 0 :(得分:2)

覆盖命名空间的正确方法是发送如下参数:

var params = { ':name' : 'test' }

它在文档中:Overriding the namespace prefix

答案 1 :(得分:0)

在您的代码中,而不是将参数传递为

var args = {'name':'test'};

var args = {arg0: 'testName'};

我不是专家,但在调用SOAP客户端时,我从node.js传递了一个参数。