CodeIgniter Forums

Full Version: Easy way to use nusoap with CI
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Unknown[/eluser]
So, I had to make soap server in CI and it wasn't easy for me, but at last i did it Smile.
I couldn't find any easy ways to do this on this forum so I decided to share my experience.

first of all you should download the attached zip 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:

Code:
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.

El Forum

[eluser]ken.sniper[/eluser]
Could you show the clinet code of this soap_server.thank you very much.

El Forum

[eluser]ortenheim[/eluser]
thank god for a soap library that works!

can you make a simple soap client example of connecting to an external soap server with xml parsing?

best regards,

Mikael