Welcome Guest, Not a member yet? Register   Sign In
nusoap 0.9.5 and codeigniter 2.1.0
#1

[eluser]Unknown[/eluser]
Hello,

I just try to run my first webservice in php with codeigniter. I found http://ellislab.com/forums/viewthread/60879/ and based on that one i made my very simple example.

Problem occurs when I want to create client for my webservice
location: http://localhost/ciwebservice/index.php/member_client
error:
Quote:Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://localhost/ciwebservice/index.php/MemberWSVC/WS_select_members/wsdl' : Premature end of data in tag html line 2 in C:\wamp\www\ciwebservice\application\controllers\member_client.php on line 12

Also have problem when want to generate wsdl file I have error in my browser:
location: http://localhost/ciwebservice/index.php/.../wsdl?wsdl
error:
Quote:This page contains the following errors:

error on line 1 at column 6: XML declaration allowed only at the start of the document
Below is a rendering of the page up to the first error.



In that location: http://localhost/ciwebservice/index.php/...mbers/wsdl everything looks fine (see attachement)

I tried to make everything as simple as possible. My model works fine.

What I could do wrong?
1. I downloaded nusoap from sourceforge not from codeigniter wiki site (in older version i have error that ereg() function is deprecated in nusoap.php file)
2. I changed nusoap.php to nusoap_base.php (to make file name the same as class name in file)

Here is the code:

model - member.php
Code:
<?php
class Member extends CI_Model {

function __construct(){
  parent::__construct();
}
    
function MODEL_select_members() {
  $members = array();

  if($this->_connect() === true){

   $sql = "SELECT * FROM `members`";
   $query = $this->db->query($sql);

   if($query->num_rows() > 0) {
    foreach($query->result_array() as $row){
     array_push($members, $row);
    }
   }

   $query->free_result();

   $this->_close();
  }

  return $members;
}
    
function _connect() {
  $this->load->database('default', FALSE);

  if(isset($this->db->conn_id)) {
   return true;
  } else {
   return false;
  }
}

function _close() {
  $this->db->close($this->db->conn_id);
}
}
?>

Controller webservice server MemberWSVC.php
Code:
<?php
class MemberWSVC extends CI_Controller {
function __construct() {
  parent::__construct();

  $this->load->library("nusoap_base");
  $this->load->model("Member");

  $this->nusoap_server = new soap_server();
  $this->nusoap_server->configureWSDL("MemberWSDL", "urn:MemberWSDL");

  $this->nusoap_server->wsdl->addComplexType(
   "MembersRecordset",
   "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"),
    "birthday"=>array("name"=>"birthday", "type"=>"xsd:date")
   )
  );

  $this->nusoap_server->register(
   "selectMembers",
   array(
    "start" => "xsd:int",
    "limit" => "xsd:int",
    "sortField" => "xsd:string",
    "sortOrder" => "xsd:string"
   ),
   array("return"=>"tns:MembersRecordset"),
   "urn:MemberWSDL",
   "urn:MemberWSDL#selectMembers",
   "rpc",
   "encoded",
   "Retrieves members' list"
  );

}

function index() {
  if($this->uri->rsegment(3) == "wsdl") {
   $_SERVER['QUERY_STRING'] = "wsdl";
  } else {
   $_SERVER['QUERY_STRING'] = "";
  }

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

function WS_select_members() {
  function selectMembers($start, $limit, $sortField, $sortOrder) {
   $CI =& get_instance();

   $rows = $CI->Member->MODEL_select_members();

   return $rows;
  }

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

Controller webservice client
Code:
<?php
class Member_Client extends CI_Controller {

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

  /* I hanged file name from nusoap to nusoap_base because main class name is nusoap_base */
  $this->load->library('nusoap_base');
}
function index() {
  /* here I try to get data from webservice */
  $this->soapclient = new soapclient('http://localhost/ciwebservice/index.php/MemberWSVC/WS_select_members/wsdl');
  
  if(!$this->soapclient->fault) {
   if(!$this->soapclient->getError()) {
    $members_list = $this->soapclient->call(
     'selectMembers',
     array($params['start'], $params['limit'], $params['sortField'], $params['sortOrder']),
     'urn:MemberWSDL',
     'urn:MemberWSDL#selectMembers'
    );
   }
  }
  
  var_dump($members_list);
  
}

function model() {
  /* just chceck if model work correctly */
  $this->load->model('member');
  $rows = $this->member->MODEL_select_members();
  
  var_dump($rows);
}
}
?>

EDIT:
I think it's because php print some errors in wsdl file error_reporting(0) does not help Sad




Theme © iAndrew 2016 - Forum software by © MyBB