Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SOAP server doesn't get all the arguments

Tags:

php

soap

I am using PHP and I use SOAP class that is bundled with PHP. I spent all day trying to figure out why this wasn't working.

I wrote this on client side:

 $client = new SoapClient("Audit.wsdl");                              
 $params=array('SerialNumber'=>'PB4LAX6JLJT7M','PercentProgress'=>'50','ResultID'=>'5');
 $result=$client->__soapCall('HardDriveStatusUpdate',array($params));

I then wrote this on server side:

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();

I noticed that nothing was happening. To debug, I had the function to write to a file with "$serialNumber, $percentProgress, $resultID". It turns out that it was getting only the first argument, but the second and third argument were empty. (it showed "PB4LAX6JLJT7M,,") Why?

WSDL says:

 <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>

Was there something wrong with how I constructed the parameters?

Tested with __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>

The real problem is definitely the server side. The function is NOT getting the arguments even though all parameters are already been sent in SOAP request. Why is that? I tried a different method and it still fails to get the second argument. It only works with the FIRST argument.

like image 786
netrox Avatar asked Aug 10 '12 23:08

netrox


1 Answers

I tried your code with the wsdl you provided, the arguments are sent in a single object, so here are the changes you need to do:

function HardDriveStatusUpdate($myObject)
{
    $serialNumber = $myObject->SerialNumber;
    $percentProgress = $myObject->PercentProgress;
    $resultID = $myObject->ResultID; 
    // process with variables 
    return array('HardDriveStatusUpdateResult' => true);
}

I tested it in SoapUi ( with print_r($myObject); die(); ) and here is the result

:enter image description here

like image 155
Anas Avatar answered Oct 27 '22 18:10

Anas