0 follower

CWebServiceAction

Package system.web.services
Inheritance class CWebServiceAction » CAction » CComponent
Implements IAction
Since 1.0
Source Code framework/web/services/CWebServiceAction.php
CWebServiceAction implements an action that provides Web services.

CWebServiceAction serves for two purposes. On the one hand, it displays the WSDL content specifying the Web service APIs. On the other hand, it invokes the requested Web service API. A GET parameter named ws is used to differentiate these two aspects: the existence of the GET parameter indicates performing the latter action.

By default, CWebServiceAction will use the current controller as the Web service provider. See CWsdlGenerator on how to declare methods that can be remotely invoked.

Note, PHP SOAP extension is required for this action.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
classMap array a list of PHP classes that are declared as complex types in WSDL. CWebServiceAction
controller CController the controller who owns this action. CAction
id string id of this action CAction
provider mixed the Web service provider object or class name. CWebServiceAction
service CWebService Returns the Web service instance currently being used. CWebServiceAction
serviceOptions array the initial property values for the CWebService object. CWebServiceAction
serviceUrl string the URL for the Web service. CWebServiceAction
serviceVar string the name of the GET parameter that differentiates a WSDL request from a Web service request. CWebServiceAction
wsdlUrl string the URL for WSDL. CWebServiceAction

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. CComponent
__construct() Constructor. CAction
__get() Returns a property value, an event handler list or a behavior based on its name. CComponent
__isset() Checks if a property value is null. CComponent
__set() Sets value of a component property. CComponent
__unset() Sets a component property to be null. CComponent
asa() Returns the named behavior object. CComponent
attachBehavior() Attaches a behavior to this component. CComponent
attachBehaviors() Attaches a list of behaviors to the component. CComponent
attachEventHandler() Attaches an event handler to an event. CComponent
canGetProperty() Determines whether a property can be read. CComponent
canSetProperty() Determines whether a property can be set. CComponent
detachBehavior() Detaches a behavior from the component. CComponent
detachBehaviors() Detaches all behaviors from the component. CComponent
detachEventHandler() Detaches an existing event handler. CComponent
disableBehavior() Disables an attached behavior. CComponent
disableBehaviors() Disables all behaviors attached to this component. CComponent
enableBehavior() Enables an attached behavior. CComponent
enableBehaviors() Enables all behaviors attached to this component. CComponent
evaluateExpression() Evaluates a PHP expression or callback under the context of this component. CComponent
getController() Returns the controller who owns this action. CAction
getEventHandlers() Returns the list of attached event handlers for an event. CComponent
getId() Returns id of this action CAction
getService() Returns the Web service instance currently being used. CWebServiceAction
hasEvent() Determines whether an event is defined. CComponent
hasEventHandler() Checks whether the named event has attached handlers. CComponent
hasProperty() Determines whether a property is defined. CComponent
raiseEvent() Raises an event. CComponent
run() Runs the action. CWebServiceAction
runWithParams() Runs the action with the supplied request parameters. CAction

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
createWebService() Creates a CWebService instance. CWebServiceAction
runWithParamsInternal() Executes a method of an object with the supplied named parameters. CAction

Property Details

classMap property
public array $classMap;

a list of PHP classes that are declared as complex types in WSDL. This should be an array with WSDL types as keys and names of PHP classes as values. A PHP class can also be specified as a path alias.

provider property
public mixed $provider;

the Web service provider object or class name. If specified as a class name, it can be a path alias. Defaults to null, meaning the current controller is used as the service provider. If the provider implements the interface IWebServiceProvider, it will be able to intercept the remote method invocation and perform additional tasks (e.g. authentication, logging).

service property read-only

Returns the Web service instance currently being used.

serviceOptions property
public array $serviceOptions;

the initial property values for the CWebService object. The array keys are property names of CWebService and the array values are the corresponding property initial values.

serviceUrl property
public string $serviceUrl;

the URL for the Web service. Defaults to null, meaning the URL for this action is used to provide Web services. In this case, a GET parameter named serviceVar will be used to deteremine whether the current request is for WSDL or Web service.

serviceVar property
public string $serviceVar;

the name of the GET parameter that differentiates a WSDL request from a Web service request. If this GET parameter exists, the request is considered as a Web service request; otherwise, it is a WSDL request. Defaults to 'ws'.

wsdlUrl property
public string $wsdlUrl;

the URL for WSDL. Defaults to null, meaning the URL for this action is used to serve WSDL document.

Method Details

createWebService() method
protected CWebService createWebService(mixed $provider, string $wsdlUrl, string $serviceUrl)
$provider mixed the web service provider class name or object
$wsdlUrl string the URL for WSDL.
$serviceUrl string the URL for the Web service.
{return} CWebService the Web service instance
Source Code: framework/web/services/CWebServiceAction.php#127 (show)
protected function createWebService($provider,$wsdlUrl,$serviceUrl)
{
    return new 
CWebService($provider,$wsdlUrl,$serviceUrl);
}

Creates a CWebService instance. You may override this method to customize the created instance.

getService() method
public CWebService getService()
{return} CWebService the Web service instance
Source Code: framework/web/services/CWebServiceAction.php#114 (show)
public function getService()
{
    return 
$this->_service;
}

Returns the Web service instance currently being used.

run() method
public void run()
Source Code: framework/web/services/CWebServiceAction.php#83 (show)
public function run()
{
    
$hostInfo=Yii::app()->getRequest()->getHostInfo();
    
$controller=$this->getController();
    if((
$serviceUrl=$this->serviceUrl)===null)
        
$serviceUrl=$hostInfo.$controller->createUrl($this->getId(),array($this->serviceVar=>1));
    if((
$wsdlUrl=$this->wsdlUrl)===null)
        
$wsdlUrl=$hostInfo.$controller->createUrl($this->getId());
    if((
$provider=$this->provider)===null)
        
$provider=$controller;

    
$this->_service=$this->createWebService($provider,$wsdlUrl,$serviceUrl);

    if(
is_array($this->classMap))
        
$this->_service->classMap=$this->classMap;

    foreach(
$this->serviceOptions as $name=>$value)
        
$this->_service->$name=$value;

    if(isset(
$_GET[$this->serviceVar]))
        
$this->_service->run();
    else
        
$this->_service->renderWsdl();

    
Yii::app()->end();
}

Runs the action. If the GET parameter serviceVar exists, the action handle the remote method invocation. If not, the action will serve WSDL content;