如何在我的 codeigniter soap 服务器代码中声明多个函数?

How can i declare multiple function in my codeigniter soap server code?

我也试过将函数声明为普通函数,但没有解决我的问题。我能够 运行 具有许多教程中的单一功能的服务器代码,但无法添加多个功能。请建议我该怎么做。

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Support extends CI_Controller {
public $ns="";

function __construct()
{

    parent::__construct();

    $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';

    $this->load->library("nusoap_library");
    $this->load->model('support_model');

    $this->nusoap_server = new soap_server();

    $this->ns = 'http://'.$_SERVER['HTTP_HOST'].'/index.php/soapserver/';
    //$ns ="urn:server";

    $this->nusoap_server->configureWSDL("SupportWsdl", $this->ns); // wsdl cinfiguration
    $this->nusoap_server->wsdl->schemaTargetNamespace = $this->ns; // server namespace


    //first simple function
    $this->nusoap_server->register('hello',
        array('username' => 'xsd:string'),  //parameter
        array('return' => 'xsd:string'),  //output
        'urn:server',   //namespace
        'urn:'.$this->ns.'helloServer',  //soapaction
        'rpc', // style
        'encoded', // use
        'Just say hello');  //description

    //this is the second webservice entry point/function 
    $this->nusoap_server->register('login',
        array('username' => 'xsd:string', 'password'=>'xsd:string'),  //parameters
        array('return' => 'tns:Person'),  //output
        'urn:server',   //namespace
        'urn:'.$this->ns.'loginServer',  //soapaction
        'rpc', // style
        'encoded', // use
        'Check user login');  //description

       //first function implementation
    function hello() {
        function hello($username){
            $this->nusoap_server->service($HTTP_RAW_POST_DATA);
            return 'Howdy, '.$username.'!';  
        }    
    }

    //second function implementation 
    function login($username, $password) {
            //should do some database query here
            //just some dummy result
            return array(
            'id_user'=>1,
            'fullname'=>'John Reese',
            'email'=>'john@reese.com',
            'level'=>99
        );
        // $this->nusoap_server->service($HTTP_RAW_POST_DATA);
    }     
}



function index()
{
    $this->nusoap_server->service(file_get_contents("php://input"));// read raw data from request body
}

}

我发现我们应该在 index 函数中声明我们所有的 soap 函数。而不是声明 class 函数。如果有人知道如何定义 register class 函数,请告诉我如何去做。 我的 soap 服务器端代码

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Support extends CI_Controller {
public $ns="";

function __construct()
{

    parent::__construct();

    $this->load->library("nusoap_library");
    $this->nusoap_server = new soap_server();

    $this->ns = 'http://'.$_SERVER['HTTP_HOST'].'/index.php/soapserver/';

    $this->nusoap_server->configureWSDL("SupportWsdl", $this->ns); // wsdl cinfiguration
    $this->nusoap_server->wsdl->schemaTargetNamespace = $this->ns; // server namespace

     //first simple function
    $this->nusoap_server->register('hello',
        array('username' => 'xsd:string'),  //parameter
        array('return' => 'xsd:string'),  //output
        'urn:server',   //namespace
        'urn:'.$this->ns.'hello',  //soapaction
        'rpc', // style
        'encoded', // use
        'Just say hello');  //description

    $this->nusoap_server->register('bye',
        array('username' => 'xsd:string'),  //parameter
        array('return' => 'xsd:string'),  //output
        'urn:server',   //namespace
        'urn:'.$this->ns.'bye',  //soapaction
        'rpc', // style
        'encoded', // use
        'Just say bye');  //    

}

function index()
{
       function hello($username){
        //$this->nusoap_server->service($HTTP_RAW_POST_DATA);
        return 'Howdy, '.$username.'!';  
    } 


 function bye($username){
        //$this->nusoap_server->service($HTTP_RAW_POST_DATA);
        return 'bye, '.$username.'!';  
    } 
    $this->nusoap_server->service(file_get_contents("php://input"));// read raw data from request body
}    
}

我的客户端代码

class Attendance extends MX_Controller {
public $data = array();
private $permission = array();
private $branch = array();

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

    //This is your webservice server WSDL URL address
    $wsdl = "http://localhost/SOAP_Final/index.php/support?wsdl";

    $this->load->library("nusoap_library");
    $this->nusoap_server = new soap_server(); 

}


public function index()
{  

}



function call_hello()
{
    $this->nusoap_client = new nusoap_client("http://localhost/SoapFinalVersion/index.php/support?wsdl");

    if($this->nusoap_client->fault)
    {
         $text = 'Error: '.$this->nusoap_client->fault;
         echo "Hello ";
    }
    else
    {
        if ($this->nusoap_client->getError())
        {
             $text = 'Error: '.$this->nusoap_client->getError();
             echo "Hello ";
        }
        else
        {   
             $row = $this->nusoap_client->call(
                      'hello',
                      array('username'=>'john')
                    );       
              var_dump($row);      
        }
    }
}
}