Web Service + Iwebserviceprovider + Exceptions

Hi there,

I am having trouble trying to add some behaviour to my web service. I want my controller to check whether a method can be executed or not, and if not, a SoapFault exception must be thrown.

I have made my controller to implement IWebServiceProvider interface and then the beforeWebMethod method. The problem is when I try to throw a SoapFault exception from it. The SOAP XML is not what it should be (it does not show the fault code and the fault message includes the stack trace).

Here is my code:




	public function beforeWebMethod($service) {

            if ($service->methodName === 'method')

            {

                return true;

            }

            else

            {

                if (<someCondition>)

                {

                    throw new SoapFault("Server", "message");

                }

                return true;

            }

        }



And the SOAP response:




<SOAP-ENV:Envelope xmlns:SOAP-ENV="htp://schemas.xmlsoap.org/soap/envelope/">

   <SOAP-ENV:Body>

      <SOAP-ENV:Fault>

         <faultcode>SoapFault</faultcode>

         <faultstring>message (/Applications/MAMP/htdocs/project/protected/modules/mod/controllers/ControlController.php:51)

#0 /Applications/MAMP/htdocs/yii/framework/web/services/CWebService.php(184): ControlController->beforeWebMethod(Object(CWebService))

#1 /Applications/MAMP/htdocs/yii/framework/web/services/CWebServiceAction.php(104): CWebService->run()

#2 /Applications/MAMP/htdocs/yii/framework/web/actions/CAction.php(75): CWebServiceAction->run()

#3 /Applications/MAMP/htdocs/yii/framework/web/CController.php(309): CAction->runWithParams(Array)

#4 /Applications/MAMP/htdocs/yii/framework/web/CController.php(287): CController->runAction(Object(CWebServiceAction))

#5 /Applications/MAMP/htdocs/yii/framework/web/CController.php(266): CController->runActionWithFilters(Object(CWebServiceAction), Array)

#6 /Applications/MAMP/htdocs/yii/framework/web/CWebApplication.php(283): CController->run('consultas')

#7 /Applications/MAMP/htdocs/yii/framework/web/CWebApplication.php(142): CWebApplication->runController('acceso/control/...')

#8 /Applications/MAMP/htdocs/yii/framework/base/CApplication.php(162): CWebApplication->processRequest()

#9 /Applications/MAMP/htdocs/project/index.php(15): CApplication->run()

#10 {main}</faultstring>

      </SOAP-ENV:Fault>

   </SOAP-ENV:Body>

</SOAP-ENV:Envelope>



Nevertheless, it does work when I throw the SoapFault from a SOAP method.

Is there a way I can throw a SoapFault exception before executing every method and without modifying my already coded web service methods?

Thanks in advance.

Juan

There’s an open issue about that. You could extend CWebService to apply the fix until it’s fixed in the framework.

Ok. Thank you.