0
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <SubmitRequest xmlns="http://tripauthority.com/hotel">
      <siteID>string</siteID>
      <username>string</username>
      <password>string</password>
      <xmlFormattedString>string</xmlFormattedString>
    </SubmitRequest>
  </soap:Body>
</soap:Envelope>

we have to call above soap xml. i have siteID, username, password. where string is below

<ArnRequest><Availability DisplayCurrency="USD" SearchTimeout="15"><HotelAvailability InDate="2007-04-26" OutDate="2007-04-29" Rooms="1" Adults="2" Children="0"><Hotel HotelID="8800"/></HotelAvailability></Availability></ArnRequest>

i have no idea on soap request. Please help with this to get response on above soap xml in PHP. The above xml is of ARN(Alliance reservations) thanks in advance.

Amrish Khatri
  • 120
  • 1
  • 1
  • 7
  • 1
    The [***TripAuthority Web Services API***](http://www.alliancereservations.com/xml-web-services.html) is very clear about problems like yours: *" XML integration is for serious businesses only; it will require major development and is not suitable for a part time developer or first time developer attempting to learn on the job."* and they continue: *"We charge a $5000 integration fee before you're allowed access to the API to begin development."* - If you just want to do a Soap Request with PHP I suggest you just orient with many of the duplicate questions. – hakre Jul 19 '14 at 14:48

4 Answers4

4

Calling webservices is quite easy, if you just want to send a prepared raw xml request. You could for instance use CURL for this.

Here the code which uses the php soapclient. I get "invalid credentials", but this should be ok as you'd put your valid ones in there.

<?

$string ='<ArnRequest><Availability DisplayCurrency="USD" SearchTimeout="15"><HotelAvailability InDate="2007-04-26" OutDate="2007-04-29" Rooms="1" Adults="2" Children="0"><Hotel HotelID="8800"/></HotelAvailability></Availability></ArnRequest>';

$xmlrequest = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:hot="http://tripauthority.com/hotel">
   <soapenv:Header/>
   <soapenv:Body>
      <hot:SubmitRequestDoc>
         <!--Optional:-->
         <hot:siteID>string</hot:siteID>
         <!--Optional:-->
         <hot:aUserName>string</hot:aUserName>
         <!--Optional:-->
         <hot:aPassword>string</hot:aPassword>
         <!--Optional:-->
         <hot:aRequestDoc>
'.$string.'
</hot:aRequestDoc>
      </hot:SubmitRequestDoc>
   </soapenv:Body>
</soapenv:Envelope>';


//Change this variables.
$location_URL = 'http://tripauthority.com/hotel.asmx';
$action_URL = "http://tripauthority.com/hotel/SubmitRequestDoc";

$client = new SoapClient(null, array(
'location' => $location_URL,
'uri'      => "http://tripauthority.com/hotel",
'trace'    => 1,
));

$order_return = $client->__doRequest($xmlrequest,$location_URL,$action_URL,1);

//Get response from here
print_r($order_return);

?>
Aydin K.
  • 3,309
  • 36
  • 44
  • hi aydinK thanks for your answer but when i am running above code with right credentials i am getting `null is not allowed as a predicate value, use Sql.IsNull instead for field UserName ` as response, not able to find out problem where is it. Here i am not seeing header included `POST /hotel.asmx HTTP/1.1 Host: tripauthority.com Content-Type: application/soap+xml; charset=utf-8 Content-Length: length` is this also we have to mention in our code. please help – Amrish Khatri Jul 19 '14 at 08:43
2

I have solve my question if any body in future have any problem they this code works for him, please check-

<?php
error_reporting(E_ALL);

define('API_SITEID',    $your_siteid);
define('API_USERNAME',  $your_uname);
define('API_PASSWORD',  $your_pass);
define('API_WSDL',      'http://tripauthority.com/hotel.asmx?WSDL');
ini_set("soap.wsdl_cache_enabled", "0");

$xmlReq = '<ArnRequest>
<Availability DisplayCurrency="USD" SearchTimeout="15">
    <HotelAvailability InDate="2014-09-26" OutDate="2014-09-27" Rooms="1" Adults="1" Children="0">
    <Hotel HotelID="8800"/>
    </HotelAvailability>
</Availability>
</ArnRequest>';
echo '<form action="" method="post">
    <strong>XML Request:</strong>
    <p>
    <textarea style="width:100%;height:400px;" id="xmlReq" name="xmlReq">'.$xmlReq.'</textarea>
    </p>
    <input type="submit" name="submit" id="submit" value="Test Request">
    <input type="hidden" name="avail" id="avail" value="y">
</form>';

if($_POST['avail'] == "y") {
    $xmlRes = doSoapRequest((($_POST['xmlReq']) ? $_POST['xmlReq'] : $xmlReq));
    echo '<strong>XML Response:</strong>
    <p>
    <textarea style="width:100%;height:400px;" id="xmlRes" name="xmlRes">'.$xmlRes.'</textarea>
    </p>';
}

function doSoapRequest($xmlReq) {
        try {
    $client = new SoapClient(API_WSDL);
    return $client->SubmitRequestRpc(API_SITEID, API_USERNAME, API_PASSWORD, $xmlReq);
    } catch(SoapFault $exception) {
    return "Fault Code: {$exception->getMessage()}";
    }
}

?>

Thanks

Amrish Khatri
  • 120
  • 1
  • 1
  • 7
1

php has a built in Soap Client as of 5: http://php.net/manual/en/class.soapclient.php

$wsdl = '
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <SubmitRequest xmlns="http://tripauthority.com/hotel">
      <siteID>string</siteID>
      <username>string</username>
      <password>string</password>
      <xmlFormattedString>string</xmlFormattedString>
    </SubmitRequest>
  </soap:Body>
</soap:Envelope>
';

try {

     $client = @new SOAPClient($wsdl);  // or preferably, use a url for $wsdl

    // Be sure to replace soapMethodToUse with a mouthed for this specific web service.
    $response = $client->soapMethodToUse(array('key' => 'val')); // Any params for this method

} catch (Exception $e) {  

    echo $e->getMessage(); 

}

die(var_dump($response));
c-griffin
  • 2,938
  • 1
  • 18
  • 25
  • 1
    thanks for the reply c-griffin. i tried your code and get something error. `SOAP-ERROR: Parsing WSDL: Couldn't load from ' siteid uname pass ' : failed to load external entity "` can you help me with this to resolve and run with some response where siteid , uname, pass is unique parameter which i have – Amrish Khatri Jul 18 '14 at 16:30
  • Try putting the xml in a file, then passing the file path when instantiating the SoapClient. new SOAPClient('file.wsdl'); Or, a lot of Web Service providers will give you a url to your WSDL, you can pass that URL as well. – c-griffin Jul 18 '14 at 16:43
  • also try as your suggestion but not able to get fruitfull result do we have to mention `POST /hotel.asmx HTTP/1.1 Host: tripauthority.com Content-Type: application/soap+xml; charset=utf-8 Content-Length: length` above header in our code as i am not finding this code in our page.. please help – Amrish Khatri Jul 19 '14 at 08:45
0

You may try to modify request with help of __doRequest function.

<?php
require_once("MySoapClient.php");
$client = new MySoapClient($wsdUrl,array(
                                       'location' => "http://tripauthority.com/hotel",
                                       'trace'    => 1,
                                       'cache_wsdl' =>  WSDL_CACHE_NONE
                                       )
                         );
$parameters=array('siteID'=>'string','username'=>'string','password'=>'string');
$err=0;
try{
    $info = $client->__soapCall("SubmitRequest",array($parameters));
}
catch (SoapFault $e) {
    echo "<pre>faultcode: '".$e->faultcode."'</pre>";
    echo "<pre>faultstring: '".$e->getMessage()."'</pre>";
    $err=1;
}
if($err==0)
    print_r($info);
else
    echo $client->__getLastRequest();
?>

MySoapClient.php

<?php
class MySoapClient extends SoapClient
{
    function __doRequest($request, $location, $action, $version, $one_way = 0) {
        $request=str_replace('</SubmitRequest>','<xmlFormattedString>string</xmlFormattedString></SubmitRequest>',$request);
        return $request;
    }
}
?>