fleuryc
(Clement Fleury)
August 12, 2013, 2:04pm
1
Hi!
I’m struggling to write a SOAP web service (my very first one). Here is my controller (from tuto) :
<?php
class StockController extends CController
{
public function actions()
{
return array(
'quote'=>array(
'class'=>'CWebServiceAction',
),
);
}
/**
* @param string $symbol the symbol of the stock
* @param string $toto toto
* @return string the stock price
* @soap
*/
public function getPrice($symbol, $toto='toto')
{
$prices=array('IBM'=>100, 'GOOGLE'=>111);
$return = isset($prices[$symbol])?$prices[$symbol]:0;
return $return.' '.$toto;
}
}
and here is my client (plain PHP) :
<?php
$client=new SoapClient('http://lde_pef.local/stock/quote');
echo $client->getPrice('GOOGLE', 'titi'); // returns '111 '
echo $client->getPrice('GOOGLE'); // returns '111 '
It is as if my second parameter is just rudely ingnored…
Why so? What am I getting wrong?
Thanks for your kind help.
fleuryc
(Clement Fleury)
August 13, 2013, 1:01pm
2
Is my question THAT stupid?
I looked over you code and it looks similar to my WebService controllers. Maybe your client cached some older WSDL?
Try this:
$client=new SoapClient('http://lde_pef.local/stock/quote', array(
'soap_version' => SOAP_1_2, // or try SOAP_1_1
'cache_wsdl' => WSDL_CACHE_NONE, // WSDL_CACHE_BOTH in production
'trace' => 1,
));
echo $client->getPrice('GOOGLE', 'titi');
echo $client->__getLastRequest();
echo $client->__getLastResponse();
Check if the request message contains the value of second parameter.
fleuryc
(Clement Fleury)
August 14, 2013, 9:54am
4
Thanks @nineinchnick !
That did the trick, must have been some cache issue indeed!
Cheers!
Remember that disabling cache will result in generating it and downloading each time you instantiate the soap client. Don’t do that in production. On Linux PHP caches wsdl in the /tmp directory, you could just remove those files to force refreshing the WSDL.
andybegin
(Zhexiao)
August 14, 2013, 7:30pm
6
Thank you very much , it’s helpful for me .
smiffy6969
(Paul Smith)
October 28, 2014, 11:21am
7
Try this at the top of your client code, ensure you only do this in development, do not push to live environment or you will disable caching…
// ensure the wsdl cache is clear
ini_set("soap.wsdl_cache_enabled", 0);
nishathul
(Nishathul)
January 7, 2015, 1:30pm
8
[color="#555555 "][font="Arial,"] set[/font][/color]
[color="#555555 "][font="Arial,"]
soap.wsdl_cache_enabled = 0
, [/font][/color]
[color="#555555 "][font="Arial,"]
[/font][/color]
[color="#555555 "][font="Arial,"]and empty the /tmp folder.[/font][/color]