<?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
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 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',
),
);
}
}
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