如何格式化args JSON以获得SOAP响应?

时间:2017-06-01 10:25:15

标签: node.js soap protractor soapui

以下是我尝试的代码:

fetchUserDetails: function () {
    var url = 'http://ldniguiapp02.eur.ad.tullib.com/matchbox-forwarddeal/services/RefDataWebServices?wsdl';
    var args = {'args0':
        {
            'mnemonic':'ttan',
            'postingId':'75655',
            'customerId':'180816',
            'organisation':{
                'customerId':'180816',
                'firmName':'POLITICAL.GROUP'
            },
            'userType':'TRADER'
        }};
    var defered = q.defer();
    soap.createClient(url, CreateClient);
    function CreateClient(err, client) {
        client.getUserDetails(args, function (err, result) {
            if (err) {
                defered.reject(err);
            }else{
                defered.resolve(result);
            }
            console.log(result);
        });
    }
    return defered.promise;
}

来自SOAP UI的等效SOAP请求如下所示:

soapUI request

如何格式化args json以获得预期结果?

1 个答案:

答案 0 :(得分:1)

你应该在xml中转换你的json

您可以在线执行此操作(检查/验证/测试)http://convertjson.com/json-to-xml.htm

当然还有一个npm模块就是这样做的:

https://www.npmjs.com/package/jsontoxml

...
var jsonxml = require('jsontoxml');

var xmlArgs = jsonxml(args);
...
client.getUserDetails(xmlArgs, function (err, result) {
...
})
...

我希望这会有所帮助