我正在使用PHP,并且我使用的是PHP捆绑的SOAP类。我一整天都在尝试弄明白为什么这不起作用。
我在客户端上编写了以下内容:
$client = new SoapClient("Audit.wsdl");
$params=array('SerialNumber'=>'PB4LAX6JLJT7M','PercentProgress'=>'50','ResultID'=>'5');
$result=$client->__soapCall('HardDriveStatusUpdate',array($params));
我在服务器端编写了以下内容:
function HardDriveStatusUpdate($sn, $p, $rs)
{
$serialNumber=$sn->SerialNumber;
$percentProgress=$p->PercentProgress;
$resultID=$rs->ResultID;
// process with variables
return array('HardDriveStatusUpdateResult' => '$result');
}
$server=new SoapServer('Audit.wsdl');
$server->addFunction('HardDriveStatusUpdate');
$server->handle();
我注意到什么都没有发生。为了调试,我让该函数用"$serialNumber, $percentProgress, $resultID"写入文件。结果只获取了第一个参数,而第二个和第三个参数为空。(它显示为"PB4LAX6JLJT7M,,") 为什么?
WSDL说:
<s:element name="HardDriveStatusUpdate">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="SerialNumber" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="PercentProgress" type="s:int" />
<s:element minOccurs="1" maxOccurs="1" name="ResultID" type="s:int" />
</s:sequence>
</s:complexType>
</s:element>
我构造参数的方式有问题吗?
使用__getLastRequest()进行测试:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://127.0.0.1/soap/">
<SOAP-ENV:Body>
<ns1:HardDriveStatusUpdate>
<ns1:SerialNumber>PB4LAX6JLJT7M</ns1:SerialNumber>
<ns1:PercentProgress>50</ns1:PercentProgress>
<ns1:ResultID>5</ns1:ResultID>
</ns1:HardDriveStatusUpdate>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
真正的问题肯定是在服务器端。即使所有参数都已经在SOAP请求中发送,但该函数仍未获取到这些参数。为什么会这样?我尝试了另一种方法,仍然无法获得第二个参数。只有第一个参数有效。
die();
放入你的代码中,它们会在SoapUI中显示。 - Anas