0

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)
Toolbox
  • 2,333
  • 12
  • 26
  • Possible duplicate of https://stackoverflow.com/questions/11391442/fatal-error-class-soapclient-not-found – Muhammed Shihabudeen Labba A Aug 26 '19 at 05:41
  • 1. the function wants three parameters, you only provide two. 2. Omit the brackets in the function name in __soapCall – Honk der Hase Aug 26 '19 at 06:21
  • The main problem was that I did not have soap installed. I do get another error but will open another question for better clarification. – Toolbox Aug 26 '19 at 06:27
  • It is working now. I ommited the brackets in the function name and added "languageid" in the params array. – Toolbox Aug 26 '19 at 06:32
  • Possible duplicate of [Fatal error: Class 'SoapClient' not found](https://stackoverflow.com/questions/11391442/fatal-error-class-soapclient-not-found) – ophychius Aug 28 '19 at 06:17

1 Answers1

0

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);
Sharad Kale
  • 971
  • 1
  • 7
  • 19