Easy way to use nusoap with CI

 

So, I had to make soap server in CI (CodeIgniter) and it wasn’t easy for me, but at last i did it :) .
I couldn’t find any easy ways to do this on CI forum so I decided to share my experience.

first of all you should download zip file and unpack it in your libraries folder. there is nusoap directory and nusoap_lib.php.

second step: create controller for example soap_member.php and paste this code in it:

    class Soap_Member extends Controller {

    var $nusoap_server;
    var $ns = "http://localhost/index.php/soap_member/"; //this is namespace

    function Soap_Member()
    {
    parent::Controller();

    $this->load->library("Nusoap_lib");
    $this->nusoap_server = new soap_server();
    $this->nusoap_server->configureWSDL("MemberWSDL", $this->ns);
    $this->nusoap_server->wsdl->ports = array('MemberWSDLPort'=> array(
    "binding" => "MemberWSDLBinding",
    "location" => $this->ns,
    "bindingType"=> "http://schemas.xmlsoap.org/wsdl/soap/"
    ));

    $this->nusoap_server->register(
    "getMember",
    array('member_id' => 'xsd:integer'),
    array("return"=>"xsd:string"),
    "urn:MemberWSDL",
    "urn:".$this->ns."/getMember",
    "rpc",
    "encoded",
    "Get Member"
    );

    function getMember($member_id) {
    $CI =& get_instance();
    //you can access any of your models like this $CI->member_model->function_name();
    return 'Member';
    }
    }

    function index()
    {
    $this->nusoap_server->service(file_get_contents("php://input"));
    }
    function webservice()
    {
    if($this->uri->rsegment(3) == "wsdl") {
    $_SERVER['QUERY_STRING'] = "wsdl";
    } else {
    $_SERVER['QUERY_STRING'] = "";
    }
    $this->nusoap_server->service(file_get_contents("php://input"));
    }
    }


now you can see your wsdl on the same link in your $ns and test your soap server from here or from any soap client.

 
 
Ministry of Foreign Affairs has been working with ITDC since 2005 and we feel that they're experts in their fields.

Ministry of Foreign Affairs