help with SOAP

Thanks for your help, if you can, this is rather urgent:

I have a demo SOAP app which is built upon the Yii default app. The Controller for the SOAP calls also has a test client in it (See ver simple code below)

The controller is returning XML correctly, but if I go to url http://localhost:888…vices/testLogin

I get a an error:

SoapFault

Description

Function ("login") is not a valid method for this service

Why is ("login") is not a valid method? After all, it is marked with @soap.

This controller should work out of the box if used with the default app.

jq




 

 <?php

 

 class WebServicesController extends CController

 {

     public $defaultAction='demo';

     /**

      * Declares class-based actions.

      */

     public function actions()

     {

         return array(

             'demo'=>array(

             'class'=>'CWebServiceAction')

             

         );

     }

 

 

 /**

  * This action serves as a test SOAP client to verify our Web service

  * login method.

  */

 public function actionTestLogin()

 {

   //use the Yii application to build the proper request url format

   $wsdlUrl=Yii::app()->request->hostInfo.$this->createUrl('demo');

 

   //create the php soap client passing in a parameter to instruct

   //it not to cache the wsdl for testing purposes

   $client=new SoapClient($wsdlUrl, array('cache_wsdl' => 0));                             

 

   echo "<pre>";

   echo "login...\n";

   if($client->login('admin','admin')) echo "Successful Login!";

   else echo "Sorry, the username and/or password supplied is invalid.";

   echo "</pre>";

 }

 

 

 /**

  * @param string username

  * @param string password         

  * @return boolean whether login is valid    

  * @soap

  */

 public function login($username,$password)

 {

     $identity=new UserIdentity($username,$password);

     if($identity->authenticate())

         Yii::app()->user->login($identity);

     return $identity->isAuthenticated;  

 }

 } 

Are you sure you wanted to name the last method as ‘login’ and not ‘actionLogin’?

The way I set things up is by putting each SOAP web service in its own controller. Here you are using a SOAP client to call the web service in which it is instantiated. I don’t really understand how you’re trying to set things up here.

For example, to test in some controller:




public function actionIndex() {

    $post_client = new SoapClient('http://blah/webservice/post/service');

    $this->render('index', array('posts' => $post_client->getPosts()));

}



The webservice, in another controller:




class PostController extends CController {


    public function actions() {

        return array(

            'service'=>array(

                'class'=>'CWebServiceAction',

                'classMap'=>array('Post'=>'Post'),

            ),

        );

    }


    /**

     * @return Post[] a list of posts

     * @soap

     */

    public function getPosts() {

	return Post::model()->findAll();

    }

}



yes, I’m sure.

It turns out that all the code is correct, and it works on my provider’s site. If I try to run it locally under MAMP, I get these errors. In another post on this subject, there is a solution with modifying the /etc/host file. This however did not work for me. I’m getting closer to the solution after nearly 6 hours of research. It has to be a server configuration issue of some kind. too tired now …

thanks for your kind answer

jq

Thanks for your helpful suggestion.

I only have things in the same controller for testing purposes. The client will be a Flex app.

The Code I posted works just fine on my provider’s server, so this seems to be a server configuration issue. It might be worth mentioning this issue in the docs, since the example in the Yii docs (whis is basically the same as mine) produces the same problem. I’m using MAMP under OSX. remaping addresses in /etc/hosts did not help, btw.

If i crack this one, I’ll post the results.

Anyone else have an idea?

best,

jq

I just noticed that you haven’t implemented IWebService. You need to implement this to provide the loginRequest, loginResponse and login operation.

Just check your WSDL and you’ll see it’s not there.

I just tried seperating the controllers. I it didn’t help. I’m certain it’s a server/network configuration problem now, since it works on another server.

thanks again,

jq

thanks again.

that doesn’t seem to be the problem, since it works on another server. The Yii IWebService documentation is so sparse, I don’t know what it does, I’m afraid.

here’s my raw output:




<definitions name="WebServicesController" targetNamespace="urn:WebServicesControllerwsdl">

−

<wsdl:message name="loginRequest">

<wsdl:part name="username" type="xsd:string"/>

<wsdl:part name="password" type="xsd:string"/>

</wsdl:message>

−

<wsdl:message name="loginResponse">

<wsdl:part name="return" type="xsd:boolean"/>

</wsdl:message>

−

<wsdl:portType name="WebServicesControllerPortType">

−

<wsdl:operation name="login">

<wsdl:documentation/>

<wsdl:input message="tns:loginRequest"/>

<wsdl:output message="tns:loginResponse"/>

</wsdl:operation>

</wsdl:portType>

−

<wsdl:binding name="WebServicesControllerBinding" type="tns:WebServicesControllerPortType">

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

−

<wsdl:operation name="login">

<soap:operation soapAction="urn:WebServicesControllerwsdl#login" style="rpc"/>

−

<wsdl:input>

<soap:body use="encoded" namespace="urn:WebServicesControllerwsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>

</wsdl:input>

−

<wsdl:output>

<soap:body use="encoded" namespace="urn:WebServicesControllerwsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>

</wsdl:output>

</wsdl:operation>

</wsdl:binding>

−

<wsdl:service name="WebServicesControllerService">

−

<wsdl:port name="WebServicesControllerPort" binding="tns:WebServicesControllerBinding">

<soap:address location="http://glyphtestlocal.de:8888/index.php?r=webservices/demo&ws=1"/>

</wsdl:port>

</wsdl:service>

</definitions>



OK, the problem is with MAMP, though I haven’t figured out what it is. I tried XAMP instead, and the example worked perfectly. I do wont to stick to MAMP if possible, so If any one has any ideas what the issue is, I would appreciate any help. In any case I will post the solution if I find it.

thanks again,

jq

OK, I solved this problem. I installed a new MAMP, and then it worked, but other things did not.

concerning soap, the old php.ini file had the following uncommented:

wzend_extension="/Applications/MAMP/bin/php5/lib/php/extensions/no-debug-non-zts-20050922/eaccelerator.so"

the new one (which works with soap) had it commented and the follwoing uncommented at the end of the file instead.

zend_extension=/Applications/MAMP/bin/php5/zend/lib/ZendExtensionManager.so

Another issue came up however with the new file:

if I have errors set to error_reporting = E_ALL, then I get an error when I call Yii::app()->language. God knows why.

So I had to set error_reporting = E_ALL & ~E_NOTICE.

I hope all this will help someone.

jq