CodeIgniter Forums

Full Version: Problems with nuSoap library and wsdl XML link call
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Unknown[/eluser]
I am trying to implement a webservice using nusoap library.

Everything looks fine but I'm not able to see the XML file, if I click on the "View the WSDL for the service" link, it goes to codeigniter default controller.

For example: http://www.chiringocloud.com/webservice/webservice its my url for the codeigniter webservice

Being first webservice the codeigniter project in Apache and the second webservice the webservice controller I am trying to implement.

So If I click on the WSDL link it points to http://www.chiringocloud.com/webservice/index.php?wsdl

I have realised that If I put manually http://www.chiringocloud.com/webservice/...index/wsdl then it shows the xml of all the definitions of my webservice.

I've tried to use routes.php config file as many guides I've checked suggest, but without luck. The entry I use is:
$route['Webservice/obtieneMiembro/wsdl'] = 'Webservice/index/wsdl';

But I don't really know how does routes works or if that is not the problem.

The code of the webservice controller:
Code:
class Webservice extends CI_Controller {
    
    function Webservice() {
        parent::__construct();          
        $this->load->library("nusoap_lib");  
        $this->nusoap_server = new soap_server();
        
        $this->nusoap_server->configureWSDL("MiembroWSDL", "urn:MiembroWSDL");

        $this->nusoap_server->wsdl->addComplexType(
            "Miembro",
            "complexType",
            "array",
            "",
            "SOAP-ENC:Array",
            array(
                "id"=>array("name"=>"id", "type"=>"xsd:int"),
                "nombre"=>array("name"=>"nombre", "type"=>"xsd:string"),
                "apellido"=>array("name"=>"apellido", "type"=>"xsd:string")
            )
         );    

        $this->nusoap_server->register(
            "obtenerMiembro",
            array(
                "id" => "xsd:int",
            ),
            array("return"=>"tns:Miembro"),
            "urn:MiembroWSDL",
            "urn:MiembroWSDL#obtenerMiembro",
            "rpc",
            "encoded",
            "Obtiene la informaciĆ³n de un miembro especificado"
        );
    }
        
     function index() {
         if($this->uri->segment(3) == "wsdl") {
            $_SERVER['QUERY_STRING'] = "wsdl";
         } else {
            $_SERVER['QUERY_STRING'] = "";
        }

        $this->nusoap_server->service(file_get_contents("php://input"));
    }

    function obtener_miembro() {
        function obtenerMiembro($idMiembro) {
            $CI =& get_instance();
            
            $CI->load->model("Miembro");
            
            $row = $CI->Miembro->obtenerMiembro($idMiembro);
            
            return $row;
        }
        
        $this->nusoap_server->service(file_get_contents("php://input"));
    }
}

El Forum

[eluser]Unknown[/eluser]
Try doing it my way and see if it helps you.
http://ellislab.com/forums/viewthread/192796/

El Forum

[eluser]Unknown[/eluser]
I Finally fixed several issues I had:

My code:
Code:
<?php
class Webservice extends CI_Controller {
    
    function Webservice() {
        parent::__construct();          
        $this->load->library("nusoap_lib");  
        
        
        $this->nusoap_server = new soap_server();
        $this->nusoap_server->configureWSDL("WebServiceG2", "urn:WebServiceG2");
        
        $this->nusoap_server->register(
            "sendFile",
            array(
                "name" => "xsd:string",
                "content" => "xsd:string"
            ),
            array("return"=>"xsd:string"),
            "urn:WebServiceG2",
            "urn:WebServiceG2#getFile",
            "rpc",
            "encoded",
            "Sends a file using SOAP to G2"
        );  
        
        $this->nusoap_server->register(
            "welcomeMember",
            array(
                "name" => "xsd:string",
                "sex" => "xsd:string",
                "phone" => "xsd:string",
                "memberID" => "xsd:int",
                "language" => "xsd:string"
            ),
            array("return"=>"xsd:string"),
            "urn:WebServiceG2",
            "urn:WebServiceG2#welcomeMember",
            "rpc",
            "encoded",
            "Sends new member parameters, welcome"
        );                  
    }
        
      function index() {
        
        function sendFile($name,$content) {
            //return $name.",".$content;
            libxml_use_internal_errors( true );
            $doc = new DOMDocument('1.0', 'utf-8');
            $doc->loadXML(base64_decode($content));
            $errors = libxml_get_errors();
            if(empty($errors)){
                $fichNuevo = $name;
                $fichNuevo = fopen($fichNuevo,'w');
                fwrite($fichNuevo,$content);
                fclose($fichNuevo);
                return "TRANSFERENCIA CORRECTA";            
            }else{
                return "FALLO EN FORMATO XML";
            }
        }
    
        function welcomeMember($name=null,$sex=null,$phone=null,$memberID=null,$language=null) {
            if($name and $sex and $phone and $memberID and $language){
                return "USUARIO RECIBIDO";
            }else{
                return "USUARIO INCORRECTO";
            }
        }
        
        $this->nusoap_server->service(file_get_contents("php://input"));
    }
}
?>

With that I can call the "http//myURL.webservice/index?wsdl" and it will work without any route to be added and any code in the index file.

And the most important part for me was to add inside the index function all the soap services functions, without that It was not working if I was using the "default" wsdl instead of using the specific "http//myURL.webservice/sendFile/index/wsdl" or the other one. I don't know if you know what I mean...