NODEJS/PHP WSDL SOAP:对象引用未设置为对象的实例 [英] NODEJS / PHP WSDL SOAP: Object reference not set to an instance of an object

查看:171
本文介绍了NODEJS/PHP WSDL SOAP:对象引用未设置为对象的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

未捕获的SoapFault异常:[a:InternalServiceFault]对象引用未设置为对象的实例.在行中...

Uncaught SoapFault exception: [a:InternalServiceFault] Object reference not set to an instance of an object. in Line ...

与此相关的问题很多,但我无法解决,因此请再次发布此可能的重复内容.

Already got lots of question related to this, but I am unable to make it work out, so posting this possible duplicate again.

我在请求中缺少了一些内容,但无法弄清楚.感谢您的帮助.

Im missing something here in the request, but couldn't figure it out. Any help is appreciated.

我在PHP& NodeJS,并且两者都发生相同的错误.

I tried this in both PHP & NodeJS, and same error occurred in both.

<?php     
$wsdl = 'http://test.eprabhu.com/Api/Utility.svc?wsdl';

$params = array(
"UserName" => "CLIENT",
"Password" => "CLIENT12",
"OperatorCode" => 2,
"MobileNumber" => "9803111111",
"Amount" => 100,
"PartnerTxnId" => "P2019042205330171261"
);

$client = new SoapClient($wsdl, ['trace' => true]);
print_r($client->__getFunctions());
// gives
// Array
// (
//     [0] => MobileTopupResponse MobileTopup(MobileTopup $parameters)
//     [1] => RechargePinsResponse RechargePins(RechargePins $parameters)
//     ...
// )
print_r($client->__getTypes());
// gives
// Array
// (
//    [0] => struct InputMobileTopup {
//              string UserName;
//              string Password;
//              int OperatorCode;
//              string MobileNumber;
//              float Amount;
//              string PartnerTxnId;
//    }
//    [1] => struct ReturnTransaction {
//              string Code;
//              string Message;
//              string TransactionId;
//              string Data;
//    }
//    ...
// )

// $r = $client->MobileTopup($params);
// or 
$response = $client->__soapCall("MobileTopup", [$params]);
// gives error Object reference not set to an instance of an object
var_dump($response);
$xml = $soapClient->__getLastRequest();
print_r($xml);

// Also I tried using the class after looking into __getTypes result
$wsdl = 'http://test.eprabhu.com/Api/Utility.svc?wsdl';
class InputMobileTopup {
    public function __construct($UserName, $Password, $OperatorCode, $MobileNumber, $Amount, $PartnerTxnId) {
        $this->UserName = $UserName;
        $this->Password = $Password;
        $this->OperatorCode = $OperatorCode;
        $this->MobileNumber = $MobileNumber;
        $this->Amount = $Amount;
        $this->PartnerTxnId = $PartnerTxnId;
    }  
}

$InputMobileTopup = new InputMobileTopup("CLIENT", "CLIENT12", 2, "9803111111", 1000, "P2019042205330171261");
print_r($InputMobileTopup);

$client = new SoapClient($wsdl, ['trace' => true]);

$response = $client->__soapCall("MobileTopup", [$InputMobileTopup]);
var_dump($response);
$xml = $soapClient->__getLastRequest();
print_r($xml);
// Still the same error.

在NodeJS中也发生相同的错误 对象引用未设置为对象的实例.

In NodeJS too, the same error occurs 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);
    });
});

任何帮助将不胜感激.谢谢. 请优先考虑NodeJS的答案. ..

Any help will be appreciated. Thanx. Please prioritize the answer for NodeJS. ..

推荐答案

根据您的WSDL,函数MobileTopup用作类型为MobileTopup的参数消息:

According to your WSDL the function MobileTopup takes as parameter message of type MobileTopup:

Array
(
    [0] => MobileTopupResponse MobileTopup(MobileTopup $parameters)
    [1] => RechargePinsResponse RechargePins(RechargePins $parameters)
    ...
)

另一方面,类型MobileTopup的定义如下:

on the other hand the type MobileTopup is defined like:

Array
(
    ...
    [85] => struct MobileTopup {
              InputMobileTopup MobileTopupRequest;
            }
    ...
)

所以您必须这样调用函数:

so you have to call the function like this:

$response = $client->__soapCall("MobileTopup", ['MobileTopup' => ['MobileTopupRequest' => $params]]);

这将返回(根据您设置的参数)

this returns (according to the params you have set)

object(stdClass)#3 (1) {
  ["MobileTopupResult"]=>
  object(stdClass)#4 (4) {
    ["Code"]=>
    string(3) "021"
    ["Message"]=>
    string(30) "Duplicate Partner Txn ID Found"
    ["TransactionId"]=>
    string(0) ""
    ["Data"]=>
    string(0) ""
  }
}

我想node.js也是如此

I guess the same is true for node.js

更新

在node.js中,问题出在您的requestArgs对象上.应该是这样的:

In node.js the problem comes from your requestArgs object. it should be like this:

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

这篇关于NODEJS/PHP WSDL SOAP:对象引用未设置为对象的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆