Welcome Guest, Not a member yet? Register   Sign In
Nusoap in Code Igniter 1.5.4
#1

[eluser]Leonardo Radoiu[/eluser]
Hello!

After some hard time trying to figure out how I can implement nusoap library in 1.5.4 version I came up with a solution I want to share with all of you who came across the very same problem.

First, the nusoap library file that you must put in the system/libraries folder (we assume we have already there the nusoap base class named nusoap.php). I named this Nusoap_lib.php:

Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Nusoap_lib
{
   function Nusoap_lib()
   {
       require_once(BASEPATH.'libraries/nusoap'.EXT);
   }
}
?>

Let's say we have a nusoap webservice named MemberWSVC saved as a controller file named MemberWSVC.php:

Code:
<?php
class MemberWSVC extends Controller {
    function __construct() {
        parent::Controller();
        
        $this->load->library("Nusoap_lib");
        
        $this->nusoap_server = new soap_server();
        $this->nusoap_server->configureWSDL("MemberWSDL", "urn:MemberWSDL");
        
        $this->nusoap_server->wsdl->addComplexType(
            "MemberRecordset",
            "complexType",
            "array",
            "",
            "SOAP-ENC:Array",
            array(
                "id"=>array("name"=>"id", "type"=>"xsd:int"),
                "firstname"=>array("name"=>"firstname", "type"=>"xsd:string"),
                "lastname"=>array("name"=>"lastname", "type"=>"xsd:string")
            )
        );    
        
        $this->nusoap_server->register(
            "selectMemberInfo",
            array(
                "id" => "xsd:int",
            ),
            array("return"=>"tns:MemberRecordset"),
            "urn:MemberWSDL",
            "urn:MemberWSDL#selectMemberInfo",
            "rpc",
            "encoded",
            "Get member's info"
        );
    }
    
    function index() {
        // this just expose webservice's methods. if you put this in every method of the webservice to describe it you won't get it to work because of some post/get issues i guess


        // this is a workaround for not having get params enabled in ci
        // usually you get the nusoap webservice's wsdl by appending "?wsdl" at the end of its url

        if($this->uri->segment(3) == "wsdl") {
            $_SERVER['QUERY_STRING'] = "wsdl";
        } else {
            $_SERVER['QUERY_STRING'] = "";
        }
        
        $this->nusoap_server->service(file_get_contents("php://input"));
    }
    
    function select_member_info() {
        function selectMemberInfo($member_id) {
            $CI =& get_instance();
            $CI->load->model("Member");
            
            $CI->Member->_id = $member_id;
                        
            $row = $CI->Member->selectMemberInfo(); // the method we use to retrieve member's info as array
    
            return $row;
        }
        
        $this->nusoap_server->service(file_get_contents("php://input"));
    }
}
?>

Finally, we consume the webservice with a controller named Client.php:

Code:
<?php
class Client extends Controller {
    function __construct() {
        parent::Controller();

        $this->load->library("Nusoap_lib");
    }

    function index() {
        $id = $this->uri->segment(3);

        $this->nusoap_client = new soapclient($this->config->item('base_url')."/webservice.php/MemberWSVC/select_member_info/wsdl");
        
        if($this->nusoap_client->fault)
        {
            $text = 'Error: '.$this->nusoap_client->fault;
        }
        else
        {
            if ($this->nusoap_client->getError())
            {
                $text = 'Error: '.$this->nusoap_client->getError();
            }
            else
            {
                $row = $this->nusoap_client->call(
                    'selectMemberInfo',
                    array($id),
                    'urn:MemberWSDL',
                    'urn:MemberWSDL#selectMemberInfo'
                );
                
                if(count($row) > 0 && is_array($row)) {
                    $text = "The member's name is ".$row['firstname']." ".$row['lastname'];
                } else {
                    $text = "There is no such member with ID ".$id;
                }
            }
        }

        etc.
    }
?>

Let's say this client will be accesible at http://localhost/webservice.php/client/12345

That's it! I hope it works for you.


Messages In This Thread
Nusoap in Code Igniter 1.5.4 - by El Forum - 08-29-2007, 02:58 PM
Nusoap in Code Igniter 1.5.4 - by El Forum - 09-12-2007, 06:42 PM
Nusoap in Code Igniter 1.5.4 - by El Forum - 09-13-2007, 03:10 PM
Nusoap in Code Igniter 1.5.4 - by El Forum - 09-14-2007, 04:54 AM
Nusoap in Code Igniter 1.5.4 - by El Forum - 11-19-2007, 06:31 AM
Nusoap in Code Igniter 1.5.4 - by El Forum - 12-06-2007, 11:59 AM
Nusoap in Code Igniter 1.5.4 - by El Forum - 12-06-2007, 02:27 PM
Nusoap in Code Igniter 1.5.4 - by El Forum - 04-09-2008, 10:13 PM
Nusoap in Code Igniter 1.5.4 - by El Forum - 04-09-2008, 11:28 PM
Nusoap in Code Igniter 1.5.4 - by El Forum - 05-04-2008, 04:34 AM
Nusoap in Code Igniter 1.5.4 - by El Forum - 05-04-2008, 10:34 AM
Nusoap in Code Igniter 1.5.4 - by El Forum - 11-25-2008, 12:56 AM
Nusoap in Code Igniter 1.5.4 - by El Forum - 04-13-2010, 08:31 AM
Nusoap in Code Igniter 1.5.4 - by El Forum - 04-13-2010, 09:09 AM
Nusoap in Code Igniter 1.5.4 - by El Forum - 04-13-2010, 09:13 AM
Nusoap in Code Igniter 1.5.4 - by El Forum - 04-13-2010, 09:21 AM
Nusoap in Code Igniter 1.5.4 - by El Forum - 10-25-2010, 10:57 AM
Nusoap in Code Igniter 1.5.4 - by El Forum - 10-25-2010, 09:39 PM
Nusoap in Code Igniter 1.5.4 - by El Forum - 04-13-2011, 01:57 PM
Nusoap in Code Igniter 1.5.4 - by El Forum - 04-13-2011, 03:07 PM



Theme © iAndrew 2016 - Forum software by © MyBB