Web services with drupal

In the recent times, we worked on a travel website where we needed to fetch the flights results from a third party web service. nuSoap was the solution we used for integrating our website with an external web service. All we need to do is to just download Soap Client and save it in our sites/all/modules(or any other contributed modules) directory. Then follow the documentation written on the project page of Soap Client. After preparing the complete environment, we just need to write a function in some module. The sample code is given below:
function mymodule_servicecall() {
define('MYMODULE_SERVICE_USERNAME', 'test_user_name');
define('MYMODULE_SERVICE_PASSWD', 'test_pass');
$arr_request = array('argument1' => 'test1', 'argument2' => 'sample2');
$service_url = 'http://ws.example.com/';
$output = '';
$options = array();
$options['use'] = 'encoded';
$options['style'] = 'rpc';
$options['headers'] = '
' . MYMODULE_SERVICE_USERNAME . '
' . MYMODULE_SERVICE_PASSWD . '
';
$soap_obj = soapclient_init_client($service_url . "sample_call.asmx?WSDL", 1, $options);
if (!$soap_obj['#return']) {
drupal_set_message('An error occured while creating soap object', 'error');
return;
}
$arguments = array(
'testrequest' => $arr_request, //XML will be 'test1sample2'
);
$result = $soap_obj['#return']->call('TestServiceFunction', $arguments);
print_r($result);
}
































