[英]PHP SOAP call issue using the SoapClient class
我在創建客戶端以使用此WSDL方面陷入了困境。 (在PHP中使用Web服務時,我是一個新手。)(出於保密原因,我必須創建一個副本XML。希望您能理解。)
我使用以下代碼打印出函數和類型:
$client = new SoapClient("http://brique.in/wsdl.xml");
var_dump($client->__getFunctions());
var_dump($client->__getTypes());
我正在嘗試編寫php代碼來調用方法inwardProcess 。 它接受XML文件作為輸入。 我嘗試了以下方法:
$xmlInput = htmlentities('<XML><Refno>H9999999</Refno><Type>getDetails</Type><UserID>BO</UserID></XML>');
$result = $client->__soapCall("inwardProcess", array($xmlInput));
沒用 在查看了WSDL規范之后,我還嘗試了,
$xmlInput = htmlentities('<XML><Refno>H9999999</Refno><Type>getDetails</Type><UserID>BO</UserID></XML>');
class inwardProcess {
function inwardProcess($xmlInput)
{
$this->xmlInput = $xmlInput;
}
}
$inwardProcess = new inwardProcess($xmlInput);
$webservice = new SoapClient($url, $soap_options);
echo "Attempting Inward<br/>";
try {
var_dump($webservice->__getTypes());
//I also tried passing just $inwardProcess Object in place of array($inwardProcess)
$result = $webservice->__soapCall("inwardProcess", array($inwardProcess));
var_dump($result);
} catch (SOAPFault $f) {
echo "SOAPFault".$f;
}
我不斷收到錯誤
Server was unable to process request. ---> Object reference not set to an instance of an object
不知何故我無法解決。 自從我在最后期限之前,任何幫助將不勝感激。
當結構如此復雜時:
<s:element name="inwardProcess">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="xmlInput">
<s:complexType mixed="true">
<s:sequence>
<s:any/>
</s:sequence>
</s:complexType>
</s:element>
</s:sequence>
</s:complexType>
</s:element>
和像
<s:element name="inwardProcessResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="inwardProcessResult">
<s:complexType mixed="true">
<s:sequence>
<s:any/>
</s:sequence>
</s:complexType>
</s:element>
</s:sequence>
</s:complexType>
</s:element>
您必須為每個結構創建一個類。 在這種情況下,它將是:
class xmlInput
{
public $any = null;
public function __construct($any)
{
$this->any = $any;
}
}
class inwardProcess
{
public $xmlInput = null;
public function __construct($xmlInput)
{
$this->xmlInput = $xmlInput;
}
}
class inwardProcessResponse
{
public $inwardProcessResult = null;
public function __construct($inwardProcessResult)
{
$this->inwardProcessResult = $inwardProcessResult;
}
}
最后打電話給...
$xmlInput = new xmlInput('<XML><Refno>H9999999</Refno><Type>getDetails</Type><UserID>BO</UserID></XML>');
$inwardProcess = new inwardProcess($xmlInput);
$soap_options = array(
'trace' => 1, // traces let us look at the actual SOAP messages later
'exceptions' => 1 );
$url = "<WSDL URL>";
$client = new SoapClient($url, $soap_options);
try {
$result = $client->__soapCall("inwardProcess", array($inwardProcess));
echo htmlentities($result->inwardProcessResult->any);
} catch (SOAPFault $f) {
echo "-1";
}
工作了!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.