I recently had the opportunity to work with Sabre’s Global Distribution System SOAP web service. The Sabre GDS powers everything from hotel bookings, to flights and cruises. Most hotels and airlines add inventory into Sabre allowing booking agencies and travel websites to display this data to customers and book travel plans through the GDS. Sabre is old and some of its client systems look almost VAX like, so working with it can be difficult at times.
If you are reading this post you’ve probably concluded that PHPs native SOAP client cannot easily consume Sabre’s GDS web service. I gave up on it after about a day. I had gone this route to replace a pre-existing solution that resulted in socket timeout errors. The current solution for PHP developers floating around the internet is slow and unreliable. After digging deep into the PHP SOAP Client documentation I discovered a middle ground approach between consuming the WSDL (which doesn’t work) and writing raw socket connections (which barely works).
The approach is pretty nifty and not a bad approach if you really hate dealing with WSDL’s in general as you can get most of the benefits of the native PHP Soap Client without a lot of the fuss. The trick is to use SoapClient::__doRequest. This allows you to use raw XML and still transport the data to the SOAP server using native SOAP code built into PHP. Below I’ll post some code that initiates a new Sabre session using SoapClient::__doRequest.
$xmlStr = '<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext" xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/12/utility">
<Source PseudoCityCode="'.$pcc.'" />
$client = new SoapClient(null, array(
'location' => $sabreSoapServer,
'uri' => $sabreSoapServer,
'trace' => 1,
'exceptions' => true,
'use' => 'wse'
$response = $client->__doRequest($xmlStr,$sabreSoapServer,$sabreSoapServer,'1');
Prior to this we need to set $sabreSoapServer, $username, $password, and $pcc variables according to the authentication data provided by the Sabre web service team. Next we create a raw soap envelope and store it in $xmlString. Then create an instance of SoapClient as $client and make our call to __doRequest. This will return a raw soap response that we can parse with simplexml_load_string or any other xml library. I titled this done right, but perhaps its only done better. Please reply to this if you found a better way of handling this. Happy coding!