NODEJS / PHP WSDL SOAP:未将对象引用设置为对象的实例
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了NODEJS / PHP WSDL SOAP:未将对象引用设置为对象的实例相关的知识,希望对你有一定的参考价值。
未捕获的SoapFault异常:[a:InternalServiceFault]未将对象引用设置为对象的实例。排队 ...
已经有很多与此相关的问题,但是我无法解决这个问题,所以再次发布这个可能的重复。
我在请求中遗漏了一些东西,但无法弄清楚。任何帮助表示赞赏。
我在php和NodeJS中尝试了这个,并且两者都发生了同样的错误。
<?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中,也会发生相同的错误。对象引用未设置为对象的实例。
"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:
' + envelope);
//'result' is the response body
console.log('Result:
' + JSON.stringify(result));
console.log('Soap Header:
', soapHeader);
});
});
任何帮助将不胜感激。感谢名单。请优先考虑NodeJS的答案。 ..
答案
根据您的WSDL函数MobileTopup
作为MobileTopup
类型的参数消息:
Array
(
[0] => MobileTopupResponse MobileTopup(MobileTopup $parameters)
[1] => RechargePinsResponse RechargePins(RechargePins $parameters)
...
)
另一方面,类型MobileTopup
定义如下:
Array
(
...
[85] => struct MobileTopup {
InputMobileTopup MobileTopupRequest;
}
...
)
所以你必须像这样调用函数:
$response = $client->__soapCall("MobileTopup", ['MobileTopup' => ['MobileTopupRequest' => $params]]);
这会返回(根据您设置的参数)
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也是如此
UPDATE
在node.js中,问题来自你的requestArgs
对象。它应该是这样的:
var requestArgs = {
MobileTopupRequest: {
UserName: 'CLIENT',
Password: 'CLIENT12',
OperatorCode: 2,
MobileNumber: '9803111111',
Amount: 100,
PartnerTxnId: 'P201904220218335187'
}
};
以上是关于NODEJS / PHP WSDL SOAP:未将对象引用设置为对象的实例的主要内容,如果未能解决你的问题,请参考以下文章