[英]NODEJS / PHP WSDL SOAP: Object reference not set to an instance of an object
未捕獲的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: \n' + envelope);
//'result' is the response body
console.log('Result: \n' + JSON.stringify(result));
console.log('Soap Header: \n', 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'
}
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.