Nusoap从数据库返回一个数组

时间:2017-05-14 14:13:41

标签: php codeigniter soap nusoap

我有这个结构的数据库表

ID | COUNTRY_CODE |国家

我想在回旋镖中返回它的所有数据。我在CodeIgniter上使用Nusoap。到目前为止,我已经成功建立了联系。然而,返回的并不是完整的数据列表。相反,我得到了这个

<?xml version="1.0" encoding="ISO-8859-1"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
        <SOAP-ENV:Fault>
            <faultcode xsi:type="xsd:string">SOAP-ENV:Server</faultcode>
            <faultactor xsi:type="xsd:string"></faultactor>
            <faultstring xsi:type="xsd:string">unable to serialize result</faultstring>
            <detail xsi:type="xsd:string"></detail>
        </SOAP-ENV:Fault>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

我希望有人可以帮我看看,看看我错过了什么。我对如何使用Nusoap没有太多指导。或者还有Nusoap的替代品吗?谢谢!

这是我的控制器网络服务器

<?php
class GetCountries extends CI_Controller{
    public function __construct() {
        parent::__construct();
        $this->load->model('CountriesModel');
        require_once APPPATH.'libraries/nusoap/nusoap.php';
        $this->nusoap_server = new soap_server();
        $this->nusoap_server->configureWSDL('Get Countries','urn:DMS_Countries');
        $this->nusoap_server->wsdl->addComplexType(
            'Countries',
            'complexType',
            'struct',
            'all',
            '',
            array(
                'id'=>array('name'=>'id','type'=>'xsd:int'),
                'country_code'=>array('name'=>'country_code','type'=>'xsd:string'),
                'country'=>array('name'=>'country','type'=>'xsd:string')
            )
        );
        $this->nusoap_server->wsdl->addComplexType(
                'CountryArray',
                'complexType',
                'array',
                '',
                'SOAP-ENC:Array',
                array(),
                array(
                    array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:getCountries[]')
                ),
                'tns:getCountries'
        );
        $this->nusoap_server->register(
                'getCountries',
                array(),
                array('Countries'=>'tns:CountryArray'),
                'urn:DMS_Countries',
                'urn:DMS_Countries#getCountries',
                'rpc',
                'encoded',
                'Get All Countries'
        );

        function getCountries(){
            $ci =& get_instance();
            $result = $ci->CountriesModel->get_test();
            if($result->num_rows()>0){
                $result_val = array();
                $i = 0;
                foreach($result->result_array() as $row){
                    $result_val[$i]=$row;
                    $i++;
                }
                return $result_val;
            }else{
                return false;
            }
        }
    }

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

0 个答案:

没有答案