I'm Can not Create web service




<?php


class MsgwsdlController extends Controller

{

	public function actionIndex()

	{

		$this->render('index');

	}

	

	public function testwsdl(){

		return "hello";

	}

	

	public function msgJson()

    {

		$all = Msg::model()->findAll();

        $cjson = CJSON::encode($all);

		return $cjson;

		

    }

	

	public function actionGetmsgs()

    {

        $all = Msg::model()->findAll();

		

		$this->render('getmsg',array('all'=>$all));

    }


	public function actions()

	{

		return array(

			'wsdl' => array(

			  'class' => 'CWebServiceAction',

			  'wsdlUrl' => 'http://172.99.99.83/webservice/index.php?r=msgwsdl/quote',

			  'classMap'=>array(

					'Msg'=>'Msg'

				),			  

			),

		  );

	}

}


result

<definitions name="MsgwsdlController" targetNamespace="urn:MsgwsdlControllerwsdl">

<wsdl:portType name="MsgwsdlControllerPortType"/>

−

<wsdl:binding name="MsgwsdlControllerBinding" type="tns:MsgwsdlControllerPortType">

<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>

</wsdl:binding>

−

<wsdl:service name="MsgwsdlControllerService">

−

<wsdl:port name="MsgwsdlControllerPort" binding="tns:MsgwsdlControllerBinding">

<soap:address location="http://172.99.99.83/webservice/index.php?r=msgwsdl/wsdl&ws=1"/>

</wsdl:port>

</wsdl:service>

</definitions>






client

$wsdl = "http://172.99.99.83/webservice/index.php?r=msgwsdl/quote";

$client = new SoapClient($wsdl);

echo "<pre>".print_r($client->__getFunctions(),true)."</pre>";


result

Array

(

)

have not function


or

$wsdl = "http://172.99.99.83/webservice/index.php?r=msgwsdl/quote";

$client = new SoapClient($wsdl);

echo "<pre>".print_r($client->testwsdl(),true)."</pre>";


result

Fatal error: Uncaught SoapFault exception: [Client] Function ("testwsdl") is not a valid method for this service in /home/httpd/www/html/soap/index.php:5 Stack trace: #0 /home/httpd/www/html/soap/index.php(5): SoapClient->__call('testwsdl', Array) #1 /home/httpd/www/html/soap/index.php(5): SoapClient->testwsdl() #2 {main} thrown in /home/httpd/www/html/soap/index.php on line 5




help me

Have you tried the example getPrice() just to see if it works for you? … http://www.yiiframework.com/doc/guide/1.1/en/topics.webservice

Welcome to the forum!

I don’ understand very well what is your actual probelm.

I can generally advice you to add this line


ini_set ('soap.wsdl_cache_enabled',0);

before


class MsgwsdlController extends Controller

This will avoid the methods to be cached, saving you from lot of headache.

I code follow by example.

so




<?php

ini_set ('soap.wsdl_cache_enabled',0);

class StockController extends Controller

{

	public function actionIndex()

	{

		$this->render('index');

	}	

	public function getPrice($symbol)

    {

        $prices=array('IBM'=>100, 'GOOGLE'=>350);

        return isset($prices[$symbol])?$prices[$symbol]:0;

        //...return stock price for $symbol

    }

	public function actions()

	{

		// return external action classes, e.g.:

		return array(

            'quote'=>array(

                'class'=>'CWebServiceAction',

            ),

        );

	}

}



call =>http://172.99.99.83/yii/testwsdl/index.php?r=stock/quote

result is

<definitions name="StockController" targetNamespace="urn:StockControllerwsdl">

<wsdl:portType name="StockControllerPortType"/>

<wsdl:binding name="StockControllerBinding" type="tns:StockControllerPortType">

<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>

</wsdl:binding>

<wsdl:service name="StockControllerService">

<wsdl:port name="StockControllerPort" binding="tns:StockControllerBinding">

<soap:address location="http://172.99.99.83/yii/testwsdl/index.php?r=stock/quote&ws=1"/>

</wsdl:port>

</wsdl:service>

</definitions>

client is




$client=new SoapClient('http://172.99.99.83/yii/testwsdl/index.php?r=stock/quote');

echo $client->getPrice('GOOGLE');



result of client is

Fatal error: Uncaught SoapFault exception: [Client] Function (“getPrice”) is not a valid method for this service in /home/httpd/www/html/soap/index.php:3 Stack trace: #0 /home/httpd/www/html/soap/index.php(3): SoapClient->__call(‘getPrice’, Array) #1 /home/httpd/www/html/soap/index.php(3): SoapClient->getPrice(‘GOOGLE’) #2 {main} thrown in /home/httpd/www/html/soap/index.php on line 3

I dont know the happen.

Add the getPrice() to accessRules() like:




	public function accessRules()

	{

		return array(

			array('allow',// allow all users to perform 'index' and 'view' actions

				'actions' => array('index','view','quote'),

				'users' => array('*'),

			),

			array('allow',// allow authenticated user to perform 'create' and 'update' actions

				'actions' => array('create','update'),

				'users' => array('@'),

			),

			array('allow',// allow admin user to perform 'admin' and 'delete' actions

				'actions' => array('admin','delete'),

				'users' => array('admin'),

			),

			array('deny',// deny all users

				'users' => array('*'),

			),

		);

	}



I add function ccessRules() on class StockController but the same result is

Fatal error: Uncaught SoapFault exception: [Client] Function (“getPrice”) is not a valid method for this service in /home/httpd/www/html/soap/index.php:7 Stack trace: #0 /home/httpd/www/html/soap/index.php(7): SoapClient->__call(‘getPrice’, Array) #1 /home/httpd/www/html/soap/index.php(7): SoapClient->getPrice(‘GOOGLE’) #2 {main} thrown in /home/httpd/www/html/soap/index.php on line 7




<?php

ini_set ('soap.wsdl_cache_enabled',0);

class StockController extends Controller

{

	public function actionIndex()

	{

		$this->render('index');

	}	

	public function getPrice($symbol)

    {

        $prices=array('IBM'=>100, 'GOOGLE'=>350);

        return isset($prices[$symbol])?$prices[$symbol]:0;

        //...return stock price for $symbol

    }

	public function accessRules()

    {

        return array(

                array('allow',// allow all users to perform 'index' and 'view' actions

                      'actions' => array('index','view','quote'),

                      'users' => array('*'),

                     ),

                array('allow',// allow authenticated user to perform 'create' and 'update' actions

                      'actions' => array('create','update'),

                      'users' => array('@'),

                     ),

                array('allow',// allow admin user to perform 'admin' and 'delete' actions

                      'actions' => array('admin','delete'),

                      'users' => array('admin'),

                     ),

				array('deny',// deny all users

                      'users' => array('*'),

                     ),

            );

        }

	public function actions()

	{

		// return external action classes, e.g.:

		return array(

            'quote'=>array(

                'class'=>'CWebServiceAction',

            ),

        );

	}

}



Sorry for the last post… the access rules are not mandatory…

For soap to work you need to mark the method to be a web service api

This is done in the PHPDoc for the method, like:




  /**

  * @param array the symbol of the stock

  * @return array the stock price

  * @soap

  */

  public function getPrice()

...



Check the docs - http://www.yiiframew…ervice-provider

Thank you vary much

but

step 1

I add method getHello() result is client can call method




/**

* @return string

* @soap

*/

public function getHello(){

	return "Hello";

}



step 2

I add method getMsg($id) result is client cannot call method




/**

* @param integer

* @return string

* @soap

*/

public function getMsg($id){

	$msg = array('abc','edf');

	return $msg[$id];

}



error so




Fatal error: Uncaught SoapFault exception: [Client] Function ("getMsg") is not a valid method for this service in /home/httpd/www/html/soap/index.php:4 Stack trace: #0 /home/httpd/www/html/soap/index.php(4): SoapClient->__call('getMsg', Array) #1 /home/httpd/www/html/soap/index.php(4): SoapClient->getMsg(2) #2 {main} thrown in /home/httpd/www/html/soap/index.php on line 4



step 3

I use $client->__getFunctions();

result is




Array

(

    [0] => string getHello()

)



why ?

now I understanded

because cache of apache

Thank you very much.

Had the same problem.

Solved by disable caching in php.ini for soap