By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,587 Members | 1,047 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,587 IT Pros & Developers. It's quick & easy.

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

P: 1
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:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. class LicenseInformation {
  3.     public $AssigneeId;
  4.     public $ToolVersion;    
  5.     public $Count;
  6.     public $Duration;
  7.     public $AutoRenewal;
  8.     public $IsFloating;
  9. }
  10.  
Next, here's the client php with only the relevant code in it:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  include_once('LicenseInformation.class.php');    
  3.  $wsdl = 'http://fspqs13.fs.cummins.com/services/server/oms?wsdl';
  4.  $client = new SoapClient($wsdl, array('trace'=>true));
  5.  
  6.  $count = 0;
  7.  $License = new LicenseInformation();
  8.  $License->AssigneeId = 'bl651';
  9.  $License->Count = '4';
  10.  $Licenses[] = $License;
  11.  
  12.  try {
  13.   $result = $client->CreateOrder('bl651', 'INSITE', $Licenses, 1);
  14.  } catch (SoapFault $e) {
  15.        $result = new stdClass;
  16.        $result->Return_Code = '2';
  17.            $result->Return_Message = $e->getMessage();
  18.        $result->SoapFault = TRUE;
  19.        echo $result;
  20.  }        
  21. >
  22.  
Finally, here's the service side php page with only the relevant code:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  include_once('LicenseInformation.class.php');
  3.  
  4.  class EtoService {
  5.   /*
  6.    * Creates New ETO Licenses.
  7.    *
  8.    * @param string $RequesterId
  9.    * @param string $ToolName
  10.    * @param LicenseInformation[] LicenseOrders
  11.    * @param int $RecordCount
  12.    * @return string
  13.    */
  14.    public function CreateOrder($RequesterId,                                           $ToolName,$LicenseOrders, $RecordCount) {
  15.    for ($i = 0; $i <= $RecordCount; $i++) {
  16.     $AssigneeId = $LicenseOrders[$i]->AssigneeId;
  17.     $Count = $LicenseOrders[$i]->Count;
  18.    }
  19. }
  20. ?>
  21.  
Jan 31 '12 #1
Share this Question
Share on Google+
1 Reply


dlite922
Expert 100+
P: 1,584
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
Jan 31 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.