[英]Error when trying to call a SOAP function in PHP
現在,在嘗試用PHP調用SOAP函數時,我停留了幾個星期。
錯誤:
Server was unable to process request. ---> Object reference not set to an instance of an object
XML:
POST /example.com/example.asmx HTTP/1.1
Host: URL
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.example.com/action"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<AuthenticationHeader xmlns="http://www.example.com/">
<username>string</username>
<password>string</password>
<Id>long</Id>
</AuthenticationHeader>
</soap:Header>
<soap:Body>
<GetCardInfo xmlns="http://www.example.com/">
<cardnumber>string</cardnumber>
<pincode>string</pincode>
</GetCardInfo>
</soap:Body>
</soap:Envelope>
我正在使用以下代碼來調用該函數:
$client = new SoapClient("http://example.com/example.asmx?WSDL", array('trace' => 1));
$card = array(
'cardnumber' => 'example card number',
'pincode' => 'example pin code'
);
try {
$result = $client->__soapCall('GetCardInfo', $card);
print_r($result);
}
catch (SoapFault $q)
{
print_R($q);
}
如果您想了解更多信息,請詢問我。 我是這個社區的新手。
我解決了它,我不得不將SoapHeader放在stdClass對象中,並將其轉換為數組。 我不知道為什么它起作用,但它確實起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.