I’m using PHP version 5.2.1 and CakePHP version 1.1.16-5421.
In this example we’ll create a basic web service client using native PHP SOAP function and CakePHP. The service we will consume is a “fortune”, you can find its info at xmethods.net.
Here is the complete code:
<?php
class WsController extends AppController {
var $uses = array();
var $layout = '';
function fortune() {
ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
$client = new SoapClient("http://www.doughughes.net/WebServices/fortune/fortune.cfc?wsdl",
array('proxy_host' => "10.1.89.231",'proxy_port' => 8080)
); // I'm using proxy to connect Internet from my LAN
try {
echo $client->getFortune();
} catch (SoapFault $exception) {
echo $exception;
}
}
?>
Don’t forget to create empty file for the view (I’m wondering how to create an action without a view in CakePHP). Then access it at http://<url to your cake>/ws/fortune.
The key in that code is the WSDL, and function “getFortune()” which is defined in the WSDL.
Really simple isn’t it?
Recent Comments