I’m extending a webapp written with CI to communicate with visual basic application.
First of all i’d like to know if the solution i’ve choosen is a good option… i previously worked whith xml-rpc and put hands in a REST service, but to me SOAP solutions look more complete. Am i wrong?
Anyway, the problem up to now is that i cant call function inside my controller… here’s my code:
class Webservice extends CI_Controller {
function __construct() {
parent::__construct();
}
public function index() {
$server = new SoapServer("http://www.site.com/test.wsdl");
$server->setObject($this);
//$server->addFunction('sayHello');
$server->handle();
}
function sayHello($name) {
$salute = "Hi " . $name . ", it's working!";
return $salute;
}
}
I’ve compiled the wsdl file, but after i call site.com/webservice i get the following error:
SoapServer::addFunction() [soapserver.addfunction]: Tried to add a non existant function ‘sayHello’
I’ve also tried passing $CI=& get_instance() to $server->setObject(), but i think its the same as passing $this.
UPDATE – 12/09/2011
I figured it out… there is no need to use addFunction() if is already set the entire object $this. SOAP will call only the functions declared in the wsdl file, anyway it seems that i could not set a function as privete/protected.
Having said that I’m not sure to go ahead with SOAP… the tutorial written by Phil Sturgeon show a good solution using REST approach that return different response types (json, xml, serialize, csv).
More complete? How so?
SOAP is a much more defined and typed transfer protocol, but it’s complicated as hell for just sending data around. WSDL is to me a layer of complexity that is unnecessary. It is used just to tell the client and server what type the data is, but PHP doesn’t give a damn about type so why use this?
REST and JSON = quick and easy
SOAP and XML = slower and fugly