Home > Software design >  Object as parameter for SOAP client in PHP
Object as parameter for SOAP client in PHP

Time:09-17

I have a problem passing an object parameter in php. Maybe you can help me.

I would like to use the method getBookingPairsByPersonID

In Wsdl it looks like this:

   <xsd:element name="getBookingPairsByPersonID" type="tns:getBookingPairsByPersonID"/>
   <xsd:complexType name="getBookingPairsByPersonID">
   <xsd:sequence>
   <xsd:element minOccurs="0" name="arg0" nillable="true" type="xsd:string"/>
   <xsd:element name="arg1" nillable="true" type="tns:ArrayOfString"/>
   <xsd:element minOccurs="0" name="arg2" type="ns0:WSTimestamp"/>
   <xsd:element minOccurs="0" name="arg3" type="ns0:WSTimestamp"/>
   <xsd:element name="arg4" type="xsd:boolean"/>
   <xsd:element name="arg5" type="xsd:int"/>
   </xsd:sequence>
   </xsd:complexType>

This is what the documentation says

java.util.List<WSBookingPair> getBookingPairsByPersonID(java.lang.String session,
                                                       java.lang.String[] personIDs,
                                                       WSTimestamp from,
                                                       WSTimestamp to,
                                                       boolean checked,
                                                       int type)

My PHP code for this:


$wsID  = array ('1063');
$wsInt = 1;
$wschecked = false;
$wsFrom ='28.07.2021 00:00:00';
$wsTo ='28.07.2021 23:59:59';

$wsBooking = $client->getBookingPairsByPersonID(array('arg0' => $session->return, 'arg1' => array('ArrayOfString' => $wsID) , 'arg2' =>  $wsFrom , 'arg3' => $wsTo, 'arg4' => $wschecked, 'arg5'=> $wsInt));

var_dump($wsBooking->return);
echo var_dump($client->__getLastRequest());

Output:

object(stdClass)[21] null

WSTimestamp is structured like this:

Input:

$wsTsNow = $client->getTime(array('arg0' => $session->return));

Output:

object(stdClass)[5]
 public 'return' => 
   object(stdClass)[6]
     public 'TS' => int 1627977040077
     public 'day' => int 3
     public 'hour' => int 9
     public 'min' => int 50
     public 'month' => int 8
     public 'sec' => int 40
     public 'timeInSeconds' => int 1627977040
     public 'timestamp' => string '03.08.2021 09:50:40' (length=19)
     public 'year' => int 2021

I tried to create an object afterwards but that didn't work either

class WSTimestamp{
    public $timestamp;
}

$wsFrom = new WSTimestamp();
$wsFrom->timestamp = "28.07.2021 00:00:00";

$wsTo = new WSTimestamp();
$wsto->timestamp = "28.07.2021 23:59:59";

What I do not understand is that the following method works

Description:


getLevelsEByIdentification
java.util.List<WSExtensibleLevel> getLevelsEByIdentification(java.lang.String session,
                                                             WSLevelIdentification[] ids,
                                                             WSTimestamp timestamp)

Code:


$wsTsNow = $client->getTime(array('arg0' => $session->return));
$wsLevelIdentArray = array('levelID' => 1, 'code' => '17022');
$wsLevelEArray = $client->getLevelsEByIdentification(array('arg0' => $session->return, 'arg1' => array('WSLevelIdentification' => $wsLevelIdentArray), 'arg2' => $wsTsNow));

How can I pass the object parameter correctly?

CodePudding user response:

Now it works:

Input:

$wsInt = 2;
$wschecked = false;
$wsID  = array ("9999");


     class WSTimestamp{
            public $timestamp;
        }

$wsFrom = new WSTimestamp();
$wsFrom->timestamp = "09.07.2021 00:00:00";

$wsTo = new WSTimestamp();
$wsTo->timestamp = "09.07.2021 23:59:59";

$wsBooking = $client->getBookingPairsByPersonID(array('arg0' => $session->return, 'arg1' => $wsID , 'arg2' =>  $wsFrom , 'arg3' => $wsTo, 'arg4' => $wschecked, 'arg5'=> $wsInt));

var_dump($wsBooking->return->WSBookingPair);

Output:

object(stdClass)[20]
  public 'absence' => boolean false
  public 'checked' => boolean false
  public 'complete' => boolean true
  public 'duration' => int 0
  public 'from' => 
    object(stdClass)[21]
      public 'TS' => int 1625828040000
      public 'day' => int 9
      public 'hour' => int 12
      public 'min' => int 54
      public 'month' => int 7
      public 'sec' => int 0
      public 'timeInSeconds' => int 1625828040
      public 'timestamp' => string '09.07.2021 12:54:00' (length=19)
      public 'year' => int 2021
  public 'fromBookingID' => int 1905
  public 'fullDay' => boolean false
  public 'levels' => 
    object(stdClass)[22]
  public 'notice' => string '' (length=0)
  public 'person' => string '9999' (length=4)
  public 'properties' => null
  public 'to' => 
    object(stdClass)[23]
      public 'TS' => int 1625828040000
      public 'day' => int 9
      public 'hour' => int 12
      public 'min' => int 54
      public 'month' => int 7
      public 'sec' => int 0
      public 'timeInSeconds' => int 1625828040
      public 'timestamp' => string '09.07.2021 12:54:00' (length=19)
      public 'year' => int 2021
  public 'toBookingID' => int 1906
  • Related