Luciano
Luciano

Reputation: 1455

SOAP Server with CodeIgniter

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).

Upvotes: 1

Views: 10712

Answers (3)

Jesus Manriquez
Jesus Manriquez

Reputation: 1

try this

<?php 
defined('BASEPATH') OR exit('No direct script access allowed');

ini_set("soap.wsdl_cache_enabled", "0");
$srv = new SoapServer("http://www.example.com/test.wsdl");
$srv->setClass('Webservice');
$srv-> addFunction(SOAP_FUNCTIONS_ALL);
$srv->handle();


class Webservice extends CI_Controller {

function  __construct() {
    parent::__construct();
}

public function index() {
}

function sayHello($name) {
    $salute = "Hi " . $name . ", it's working!";
    return $salute;
}

}

Upvotes: 0

corysus
corysus

Reputation: 657

If you use NuSOAP class then WSDL is not problem. You just need to call your server like:

http://yoururl/api?wsdl

and NuSOAP will generate WSDL for you. I have some SOAP services developed by NuSOAP and all works like charm in any lang. that support SOAP.

Good Luck !

Upvotes: 1

Phil Sturgeon
Phil Sturgeon

Reputation: 30766

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

Upvotes: 6

Related Questions