How do I pass arrays of objects through a web service in PHP?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bl651
    New Member
    • Jan 2012
    • 1

    How do I pass arrays of objects through a web service in PHP?

    Any help on this problem would be much appreciated as I'm out of ideas. Basically, I need to pass an array of objects from the client php page to the web service. Whenever I try this I get the following error: Object of class stdClass could not be converted to string.
    I stripped out all of the code that's not relevant to the problem. Basically, I just need to know how to get the array of objects passed correctly to php server page.

    Here's the code I have.

    First, here's the class I'm using for the object:
    Code:
    <?php
    class LicenseInformation {
    	public $AssigneeId;
    	public $ToolVersion;	
    	public $Count;
    	public $Duration;
    	public $AutoRenewal;
    	public $IsFloating;
    }
    Next, here's the client php with only the relevant code in it:
    Code:
    <?php
     include_once('LicenseInformation.class.php');	
     $wsdl = 'http://fspqs13.fs.cummins.com/services/server/oms?wsdl';
     $client = new SoapClient($wsdl, array('trace'=>true));
    
     $count = 0;
     $License = new LicenseInformation();
     $License->AssigneeId = 'bl651';
     $License->Count = '4';
     $Licenses[] = $License;
    	
     try {
      $result = $client->CreateOrder('bl651', 'INSITE', $Licenses, 1);
     } catch (SoapFault $e) {
    	   $result = new stdClass;
    	   $result->Return_Code = '2';
               $result->Return_Message = $e->getMessage();
    	   $result->SoapFault = TRUE;
    	   echo $result;
     }		
    >
    Finally, here's the service side php page with only the relevant code:
    Code:
    <?php
     include_once('LicenseInformation.class.php');
    
     class EtoService {
      /*
       * Creates New ETO Licenses.
       *
       * @param string $RequesterId
       * @param string $ToolName
       * @param LicenseInformation[] LicenseOrders
       * @param int $RecordCount
       * @return string
       */
       public function CreateOrder($RequesterId,                                           $ToolName,$LicenseOrders, $RecordCount) {
       for ($i = 0; $i <= $RecordCount; $i++) {
        $AssigneeId = $LicenseOrders[$i]->AssigneeId;
        $Count = $LicenseOrders[$i]->Count;
       }
    }
    ?>
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    see the serialize() and unserialize() methods. It converts objects to strings then back to objects again with some LIMITATIONS. Check the manual page http://php.net/serialize

    Dan

    Comment

    Working...