[英]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.