NODEJS SOAP:对象引用未设置为对象的实例

NODEJS SOAP: Object reference not set to an instance of an object

我收到一个错误:

Object reference not set to an instance of an object

我在请求中遗漏了一些东西,但无法弄清楚。感谢任何帮助。

我尝试使用 soap 模块和 strong-soap 模块,但两者都出现相同的错误。所以这可能是请求参数的错误。

Object reference not set to an instance of an object

代码:

"use strict";

var soap = require('strong-soap').soap;

var url = 'http://test.eprabhu.com/Api/Utility.svc?wsdl&UserName=CLIENT';
var requestArgs = {
    'UserName': 'CLIENT',
    'Password': 'CLIENT12',
    'OperatorCode': 2,
    'MobileNumber': '9803111111',
    'Amount': 100,
    'PartnerTxnId': 'P201904220218335187'
};

var options = {
  'user-agent': 'sampleTest',
  'Content-Type': 'text/xml;charset=UTF-8',
  // 'soapAction': 'http://test.eprabhu.com/Api/Utility.svc?wsdl#MobileTopup',
  'soapAction': 'http://tempuri.org/IUtility/MobileTopup'
};

soap.createClient(url, options, function(err, client) {

    var method = client['MobileTopup'];
    method(requestArgs, function(err, result, envelope, soapHeader) {
        //response envelope
        console.log('Response Envelope: \n' + envelope);
        //'result' is the response body
        console.log('Result: \n' + JSON.stringify(result));

        console.log('Soap Header: \n', soapHeader);
    });
});

如有任何帮助,我们将不胜感激。谢谢

将您的参数更改为:

var requestArgs = {
  MobileTopupRequest: {
    UserName: 'CLIENT',
    Password: 'CLIENT12',
    OperatorCode: 2,
    MobileNumber: '9803111111',
    Amount: 1,
    PartnerTxnId: 'P201904220218335187'
  }
};