PHP | How to call SOAP based web services from php

Author - Rita

We were working on codeigniter website project. We had wsdl web services available to access our backend functionality. We had configured a WSDL Client in our php code but it was not working.

Sample Code:

try
{
$testSoapClient = new SoapClient(TYPE_WSDL_PATH_HERE, array('trace' => 1));
}
catch (Exception $e)
{
echo ‘Provider not available. Please come back later !';
exit;
}

We were getting exception “Provider not available”.

Solution:

$testSoapClient = new SoapClient(TYPE_WSDL_PATH_HERE, array('trace' => 1));

Main problem with the above code was that we were calling SoapClient (existing library class) but it was not installed.

SOAP is the php extension not apache module. Try one of the below commands to check whether it is available or not :

1. Ubuntu Command:

php -i | grep -i soap

Output:

soap
Soap Client => enabled
Soap Server => enabled
soap.wsdl_cache => 1 => 1
soap.wsdl_cache_dir => /tmp => /tmp
soap.wsdl_cache_enabled => 1 => 1
soap.wsdl_cache_limit => 5 => 5
soap.wsdl_cache_ttl => 86400 => 86400

2. Run phpinfo(); provided by php to check whether soap is available or not.
If it is installed you get something like below in the output:

soap
Soap Client => enabled
Soap Server => enabled
Directive => Local Value => Master Value
soap.wsdl_cache => 1 => 1
soap.wsdl_cache_dir => /tmp => /tmp
soap.wsdl_cache_enabled => 1 => 1
soap.wsdl_cache_limit => 5 => 5
soap.wsdl_cache_ttl => 86400 => 86400

If you see above response then that means everything is fine. If not, then first install
php-soap extension.

Ubuntu Command:

sudo apt-get install php-soap

After running above command it will work.

Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at dev@webners.com for your Insurance, eLearning and Salesforce applications.

Leave a Reply

Your email address will not be published. Required fields are marked *

Send your message