Webservices in CakePHP [other approach] February 16, 2006
Posted by rossoft in CakePHP.trackback
I was thinking other approach for webservices for having the code more clean and easier.
Installation
1. Copy this little hacked version of nusoap to /vendors/nusoap/nusoap.php
2. Copy this controller class to /vendors/nusoap/web_services_controller.php
3. Copy this component (nusoap client) to /app/controllers/components/soap.php
Usage
Developing a server
The services will be in the url http://myhost/customer_services/
(open that url in your browser for see the info of the webservice)
1. The controller
vendor(‘nusoap/web_services_controller’);
class CustomerServicesController extends WebServicesController
{
var $name=’CustomerServices’;
var $uses=array(‘Customer’);
var $api=array(
‘add’=>array ( ’doc’=>’create a customer’,
‘input’=>array(‘code’=>’xsd:integer’,
‘name’=>’xsd:string’)),
‘name’=>array(‘doc’=>’gets the name of a customer’,
‘input’=>array(‘code’=>’xsd:integer’),
‘output’=>array(‘return’=>’xsd:string’)),
);
function add($code,$name)
{
$data['Customer']['id'] = $code;
$data['Customer']['name'] = $name;
$this->Customer->save($data);
}
function name($code)
{
$this->Customer->id=$code;
$data=$this->Customer->read();
return $data[0]['Customer']['name'];
}
}
That’s all!
Developing a client
class TestController extends AppController
{
var $components=array(’aaa’,’bbb’,’soap’);
function test()
{
$url=”http://localhost/customer_services/”;
$func=’delete’;
$param=array(’code’=>’34′);
$name=$this->soap->client($url,$func,$param);
$this->set(’name’,$name); //for the view
}
}
Q: what you had to modify in nusoap?
A: In nusoap you can call a global function or a method of a class. If you call a method of a class, then it will create a new instance of that class and calls the method on that instance. Also, he changes the name of the method of the service to something like ‘CustomerServiceController.add’. It didn’t worked for me, the new instance of the controller didn’t had the model variables set. I changed it passing the $this variable to the register method
Hello
I’m very thankfull for this modifications. That’s exactly what I was searching for. I install everything but noticed one litte error:
If browser the Soap Service and click on WDSL the wrong page ist displayed. The Soap Code used PHP_SELF.
Cheers
Sebastian
please rossft can you see how you’ve passed $this tothe register method?
@felix: see the hacked nusoap version, the link is at the top of this article. I don’t remember the changes…
When using this method the page gets redirected to /webroot/index.php instead of the controller, thus generating an error.
I think it’s because of the PHP_SELF used, but i have no idea how to fix it.
My current fix gives a version mismatch:
web_services_controller.php (line 74 – 76)
$fap = “http://dev.edore.nl/”.$this->params['url']['url'];
$urn=”urn:$wsdl”;
$this->_soap_server->configureWSDL($wsdl, $urn, $fap);
In reply to the previous post, i’ve fixed it.
Correct line: (line 75-76)
$url= FULL_BASE_URL.’/’.$this->params['url']['url'];
$this->_soap_server->configureWSDL($wsdl, $urn, $url);
Also a note: do not use /customer_services/wsdl (wich does work) because the path isn’t correct then. Always use /customer_services?wsdl
hello, is it possible to return an array with this, like from $this->Model->findAll()?
thanks, regards
How I see the request and respond of SOAP working?
Thanks
Bobby
The linking to the files does not seem to be working. Is that a problem or is it just me?
This files not exist, nusoap.php.txt, web_services_controller.php.txt and soap.php.txt.
Someone can place in bakery please.
Thanks.
All the following installation files are not present here
1. Copy this little hacked version of nusoap to /vendors/nusoap/nusoap.php
2. Copy this controller class to /vendors/nusoap/web_services_controller.php
3. Copy this component (nusoap client)
i need to implement a web service in cake, therefore if anyone has all these files plz send them to me… i’ll be very thankful to you.
my email is: hafeez2cool@yahoo.com
i implemented webservices but i got error anybody send me sample files in zip plz help me
send me at : rajkumar.sakti@gmail.com
with regards
rajkumar
Hi everybody,
For those who need them, Here are some mirrors of the files that are used in this post, because the links were not working.
Hola a todos,
Para aquellos que los necesiten, aqui estan los archivos usados en este post, ya que los links no funcionaban:
file/archivo: webservices.zip
http://www.megaupload.com/es/?d=MIKS8CHC
http://www.mediafire.com/?1yugcgmz3le
http://rapidshare.com/files/81559834/webservices.zip.html
http://www.divshare.com/download/3363283-01b
Installation
1. Copy this little hacked version of nusoap to /vendors/nusoap/nusoap.php
2. Copy this controller class to /vendors/nusoap/web_services_controller.php
3. Copy this component (nusoap client) to /app/controllers/components/soap.php
where i can get those files mentioned on the installation guide?
Thanks to Ross and Franck
I’ve implemented successfully this tutorial of phpcake+nusoap. The code is available for download at
http://lab.lemontech.cl/example_project.tar.gz
thanks again!
Pangui
———————————————-
Gracias a Ross y Franck
Implementé con éxito este tutorial de phpcake y nusoap. El código que utilice está disponible para descarga en
http://lab.lemontech.cl/example_project.tar.gz
gracias otra vez!
Pangui
The client component is missing from the zip posted.
Can’t find any other info on CakePHP with SOAP client apart from people using PHP5. Anyone have this file?
NUzJqh http://fnYwlOpd2n9t4Vx6A3lbk.com
Please call back later little nymphet cp 8DDD
How many weeks’ holiday a year are there? young nude actress %-]]
Could you tell me the number for ? forever model preteen :-]]
Go travelling free young teen lesbians oeqa
Where’s the postbox? sexy underage upskirt plkoi
I’m sorry, I didn’t catch your name pedo stars
48741
Have you read any good books lately? early girl toplist
%-))
A pension scheme Loli Dorki Pthc
5646
Wonderfull great site Kasandra Model
%-DD
How many would you like? http://efylehooryy.de.tl strawberry nude model The way her ass is coming down on his dick toward the end of the vid is very sexy ^_^