2
votes

This is my code

 $c = new soapclient('http://www.redbus.in/WS2/BookingService.asmx?wsdl',
     array('authentication' => array('LoginID' => 'x','Password'=>'x')));

  $timezone = new DateTimeZone('UTC');
  $time='2012-04-17T16:50:45';
  $date = new DateTime($time,$timezone);
  $sourceid=array('SourceID'=>'244','DestinationID'=>'477','DateOfJourney' =>$date);
  $stockprice = $c->GetAvailableRoutes($sourceid);

   print_r($stockprint);

it's not working in datetime format datatype variable

it shows error like this

Fatal error: Uncaught SoapFault exception: [soap:Client] Server was unable to read request. ---> There is an error in XML document (2, 252). ---> The string '' is not a valid AllXsd value. in E:\xampplite\htdocs\index1.php:9 Stack trace: #0 [internal function]: SoapClient->__call('GetAvailableRou...', Array) #1 E:\xampplite\htdocs\index1.php(9): SoapClient->GetAvailableRoutes(Array) #2 {main} thrown in E:\xampplite\htdocs\index1.php on line 9

2

2 Answers

1
votes

You need to format it, otherwise you are throwing an DateTime object into your array (which PHP tries to convert to a string, which does not work)

For example:

$date->format('Y.m.d H:i:s');

Usage

$sourceid = array('SourceID'=>'244','DestinationID'=>'477','DateOfJourney' => $date->format('Y.m.d H:i:s'));
10
votes

I had a similar problem when using a SOAP service from PHP. I fixed it using:

$date->format('c');

(ISO 8601 date, added in PHP 5, looks like: 2004-02-12T15:19:21+00:00)