I am trying to integrate web services using soap.
This is the xml file:
http://uatapiout.islandhopper.in/Service1.svc?wsdl
And this is code which I am trying:
<?php
$wsdl = 'http://uatapiout.islandhopper.in/Service1.svc?wsdl';
$xml_array["RequestType"] = "AvailabilityRQ";
$xml_array["Login"] = array("UserName"=>"test","Password"=>"test","Version"=>"3.0");
$xml_array["CheckAvailabilityCriteria"] = array("CheckIn" => "07/05/2017","CheckOut"=> "07/11/2017","CountryID"=> "MAU","CityID" => "MAU","Currency" => "USD","Adult" => "2","Rooms"=>array("Room"=>array("Adult"=>"2","Child"=>"0")));
$trace = true;
$exceptions = true;
try
{
$client = new SoapClient($wsdl, array('trace' => 1));
$response = $client->HotelSearch($xml_array );
print_r($client->__getLastRequest());
print_r($client->__getLastResponse());
}
catch (Exception $e)
{
echo "Error!";
echo $e ->getMessage ();
echo 'Last response: '. $client->__getLastResponse();
}
And $client->__getLastRequest() always gives me blank body:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/"><SOAP-ENV:Body><ns1:HotelSearch/></SOAP-ENV:Body></SOAP-ENV:Envelope>
So, the question is that why this request has a blank body.
Please suggest me, what am I doing wrong?
Thanks in advance.
Edit:
This is sample xml request:
<XMLRequest>
<RequestType>AvailabilityRQ</RequestType>
<Login>
<UserName>UserName</UserName>
<Password>Password</Password>
<Version>3.0</Version>
</Login>
<CheckAvailabilityCriteria>
<CheckIn>07/05/2016</CheckIn>
<CheckOut>07/11/2016</CheckOut>
<CountryID>MAU</CountryID>
<CityID>MAU</CityID>
<Currency>USD</Currency>
<HotelCode></HotelCode>
<HotelName></HotelName>
<ClientNationality></ClientNationality>
<Rooms>
<Room>
<Adult>2</Adult>
<Child>2</Child>
<ChildAges>
<ChildAge>7</ChildAge>
<ChildAge>14</ChildAge>
</ChildAges>
</Room>
<Room>
<Adult>2</Adult>
<Child>0</Child>
</Room>
</Rooms>
</CheckAvailabilityCriteria>
</XMLRequest>
Thank you all for your support.
Now, I am doing that using nusaop lib.
This is the code:
require_once('nusoap/lib/nusoap.php');
$wsdl = 'wdls url';
$xml_array["RequestType"] = "AvailabilityRQ";
$xml_array["Login"] = array("UserName"=>"username","Password"=>"password","Version"=>"version");
$xml_array["CheckAvailabilityCriteria"] = array("CheckIn" => "07/05/2017","CheckOut"=> "07/11/2017","CountryID"=> "MAU","CityID" => "MAU","Currency" => "USD","Rooms"=>array("Room"=>array("Adult"=>"2","Child"=>"0")));
$xml_array1['XMLRequest'] =$xml_array;
$client = new nusoap_client($wsdl, false);
$client->soap_defencoding = 'UTF-8';
$err = $client->getError();
if ($err)
{
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->getDebug(), ENT_QUOTES) . '</pre>';
exit();
}
$result = $client->call('HotelSearch', $xml_array1,'','http://tempuri.org/IService1/HotelSearch',false,false,'','');
if ($client->fault)
{
echo '<h2>Fault (Expect - The request contains an invalid SOAP body)</h2>';
}
else
{
$err = $client->getError();
if ($err)
{
echo '<h2>Error</h2><pre>' . $err . '</pre>';
}
else
{
$result_count = $array_result['TotalResult'];
if($result_count)
{
$hotels_list = $array_result['AvailHotels']['Hotel'];
for($i=0; $i<count($hotels_list);$i++)
{
$hotel_name = $hotels_list[$i]['@attributes']['Name'];
$hotel_code = $hotels_list[$i]['@attributes']['Code'];
echo "Hotel name is <i>$hotel_name</i> and hotel code is <i>$hotel_code</i>";
echo "</br></br>";
}
}
}
}
Hope, this will help someone :)