dryk50495 2015-03-25 07:06
浏览 49
已采纳

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

I tried to declare function as normal function too,but didn't solved my problem. I was able to run the server code with single function as found in many tutorials but cannot add multiple function. plz suggest me how can i do that.

<?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
}

}

  • 写回答

1条回答 默认 最新

  • douan0729 2015-03-29 08:17
    关注

    I figured out that we should declare our all our soap functions inside index function. Instead of declaring class function. if any one know how to define register class function show how to do it plz. My soap server side code

    <?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
    }    
    }
    

    My client side code

    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);      
            }
        }
    }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据