Soap Web Service Server

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.

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.

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.

Thank you very much , it’s helpful for me .

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);

[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]