phpsoapsoap-clientsoapserver

Cannot get response from PHP Soapclient


I am trying to fetch response from sending PHP SoapClient request. My understanding is that in Soap, the class exists on the Soap-server and is specified and fetched as an argument to Soapclient, pointing out the wsdl file.

I am using following link references:

Webservices:

PHP Soapclient:

How to make a PHP SOAP call using the SoapClient class


My code:

<? php
$client = new SoapClient("https://swea.riksbank.se/sweaWS/wsdl/sweaWS_ssl.wsdl");

$params = array (
    "year" => 2010,
    "month" => 4
);

$response = $client->__soapCall('getAnnualAverageExchangeRates()', array($params));

var_dump($response);

The error message:

PHP Fatal error:  Uncaught Error: Class 'SoapClient' not found in /[path/Xxx.php:4
Stack trace:
#0 {main}
  thrown in /path/Xxx.php on line 4
    var_dump($response)

Solution

  • First of all you need to enable Soap extention from php.ini. Restart Apache. Then check phpinfo() to ensure extension is loaded.

    $option = array('trace' => 1, 'keep_alive' => true,'connection_timeout' => 60);// add options here
    $client = new SoapClient("https://swea.riksbank.se/sweaWS/wsdl/sweaWS_ssl.wsdl", $option);
    
    $params = array (
        "year" => 2010,
        "month" => 4,
        "languageid" => 1 //language id may differ.
    );
    
    // you can directly call function from  wsdl.
    $response = $client->getAnnualAverageExchangeRates(array($params));
    
    var_dump($response);