jump to navigation

Web services in CakePHP – complex types February 17, 2006

Posted by rossoft in CakePHP.
trackback

I’ve updated the 3 files referenced in the previous post. Now it is easy to pass arrays and structs.

Complete example of usage of server side:

vendor(‘nusoap/web_services_controller’);
class ArticulosServicesController extends WebServicesController
{
    var $name=’ArticulosServices’;
    var $uses=array(‘Articulo’,’Familia’);
   
    var $api=array(
            ‘add’=>array (    ‘doc’=>’agregar articulo’,
                            ‘input’=>array(‘codigo’=>’xsd:string’,
                                            ‘nombre’=>’xsd:string’,
                                            ‘precio’=>’xsd:float’)),
               ‘browse’=>array(‘doc’=>’precio articulo’,                                      
                             ‘output’=>array(‘return’=>’Array_Articulos’)),
                                           
               ‘precio’=>array(‘doc’=>’precio articulo’,
                                ‘input’=>array(‘codigo’=>’xsd:string’),
                             ‘output’=>array(‘return’=>’xsd:integer’))
                );
    var $complexTypes=array(
                ‘Array_Articulos’=>array(‘array’=>’Articulo’),
                ‘Articulo’=>array(‘struct’=>array(
                            ‘codigo’=>’xsd:string’,
                            ‘nombre’=>’xsd:string’,
                            ‘precio’=>’xsd:float’)));
                   
    function add($codigo,$nombre,$precio)
    {
        $data[‘Articulo’][‘codigo’]=$codigo;
        $data[‘Articulo’][‘nombre’]=$nombre;
        $data[‘Articulo’][‘precio_pvp’]=$precio;
        $this->Articulo->save($data);
    }
   
    function precio($codigo)
    {       
        $data=$this->Articulo->findAll(“Articulo.codigo =’$codigo'”);
        if ($data)
        {
            return $data[0][‘Articulo’][‘precio_pvp’];
        }
        else
        {
            return new soap_fault(‘Client’,”,’Este artículo no existe.’,”);
        }
       
    }
   
    function browse()
    {
        $ret=array();
        $data=$this->Articulo->findAll();
        foreach ($data as $art)
        {
            $ret[]=array(‘codigo’=>$art[‘Articulo’][‘codigo’],
                                         ‘nombre’=>$art[‘Articulo’][‘nombre’],
                                         ‘precio’=>$art[‘Articulo’][‘precio_pvp’]);
                         
        }       
        return $ret;            
    }   
}

?>

Advertisements

Comments»

1. Marcin - February 17, 2006

What about WSDL generating, and using webservice server from ex. java where we have mirror of export class methods not calling single adresses servers ????

2. rossoft - February 17, 2006

I don’t understand you…but if you asked if this aproach generates a WSDL file, it does.
When you put the url of the webservice in your webbrowser, and then click on link ‘WSDL’ you obtain a copy of the WSDL file generated.

3. Aku Ma - July 17, 2006

Hi. I keep getting this error when trying to consume a IIS Web Service:

Array
(
[faultcode] => soap:Server
[faultstring] => Server was unable to process request. –> Object reference not set to an instance of an object.
[detail] =>
)

There’s so many people in forums asking for the same thing, but no solution. Can you help me?

4. Aku Ma - July 18, 2006

Hi there, it’s me again. I found the solution here:

http://users.skynet.be/pascalbotte/rcx-ws-doc/nusoapadvanced.htm

I just wanted you to know. 😉

BTW, you have a great site!

Felicitaciones.

5. American History - May 24, 2007

american history, general information, general resources

Nice site with good info!

6. American Life - May 24, 2007

american life, general information, general resources

Just found your site. Will definitely come back soon!

7. American History - May 24, 2007

american history, general information, general resources

More posts like the one above would be greatly appreciated.

8. Skin Care Blog - May 25, 2007

health acne rosacea skincare

great site love the info presented.

9. Hot Tattoos - May 25, 2007

tattoos henna temporary tattoos

great site love the info presented.

10. Rosacea Guy - June 26, 2009

Very interesting post. Thank you for sharing with us.

11. sebastian - November 2, 2010

hi,I keep getting this error when trying to consume

Response not of type text/xml: text/html; charset=utf-8

Can you help me?

12. Binoy - October 14, 2011

Hi, Thanks for the script. How to give multiple models in the complex type ?


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: