【问题标题】:NuSOAP returns empty arrayNuSOAP 返回空数组
【发布时间】:2016-03-01 17:41:34
【问题描述】:

我有一个问题,NuSOAP 服务器返回一个空数组。我已经阅读并尝试了很多主题/事物,但结果总是一样的。我想这只是你们可以在一分钟内解决的小问题。

我想将包含客户端信息的字符串数组放入另一个包含所有服务器的数组中:

    Array
    (
       [Client1] => Array ([HostName] => 'TestHostName', [IP] => '1.1.1.1'),
       [Client2] => Array ([HostName] => 'TestHostName', [IP] => '2.2.2.2'),
       [Client3] => Array ([HostName] => 'TestHostName', [IP] => '3.3.3.3')
    )

数组将从 mysql 数据中填充,但出于测试目的,我创建了一个包含数据的静态数组。这是我到目前为止所得到的:

<?php
require_once ('lib/nusoap.php');
require('mysql.php');

$ServerName = 'server';
$ServiceName = 'CentralConfigService';
$ServiceURL = 'http://' . $ServerName . '/' . $ServiceName;

$Server = new soap_server();
$Server -> configureWSDL($ServiceName, $ServerName . '/' . $ServiceName);

function GetClientInfo($ClientName)
{
        $Clients = array();
        $ClientInfo = array(
                        'HostName' => 'testiname',
                        'IP' => 'testip',
                        'Type' => 'testtype',
                        'Config' => 'testconfig',
                        'Routines' => 'testroutines',
                        'Files' => 'testfiles',
                        'Access' => 'testaccess');
        $Clients[$ClientName] = $ClientInfo;
        return $Clients;
}


$Server -> wsdl -> addComplexType(
        'ClientInfo',
        'complexType',
        'struct',
        'sequence',
        '',
        array(
                'HostName' => array('name' => 'HostName', 'type' => 'xsd:string'),
                'IP' => array('name' => 'IP', 'type' => 'xsd:string'),
                'Type' => array('name' => 'Type', 'type' => 'xsd:string'),
                'Config' => array('name' => 'Config', 'type' => 'xsd:string'),
                'Routines' => array('name' => 'Routines', 'type' => 'xsd:string'),
                'Files' => array('name' => 'Files', 'type' => 'xsd:string'),
                'Access' => array('name' => 'Access', 'type' => 'xsd:string')
        )
);


$Server -> wsdl -> addComplexType(
        'Clients',
        'complexType',
        'array',
        '',
        'SOAP-ENC:Array',
        array(),
        array(
                array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:ClientInfo')
        ),
        'tns:Clients'
);


$Server -> register(
        'GetClientInfo',
        array('HostName' => 'xsd:string'),
        array('return' => 'tns:Clients'),
        $ServiceURL,
        $ServiceURL . '#GetClientInfo',
        'rpc',
        'encoded',
        'Get config by type');



if ( !isset( $HTTP_RAW_POST_DATA ) ) $HTTP_RAW_POST_DATA = file_get_contents( 'php://input' );

@$Server -> service($HTTP_RAW_POST_DATA);

?>

当我调用函数“GetClientInfo”时,我总是得到一个空数组:

    Array
    (
    [0] => Array
    (
        [0] => Array
            (
            )

        [1] => Array
            (
            )

        [2] => Array
            (
            )

        [3] => Array
            (
            )

        [4] => Array
            (
            )

        [5] => Array
            (
            )

        [6] => Array
            (
            )

    )

)

客户端调用函数:

    <?php

    require_once('lib/nusoap.php');

    $wsdl = "http://server/server.php?wsdl";
    $client = new nusoap_client($wsdl, 'wsdl');

    $result = $client -> call('GetClientInfo', array('ClientName'=>'Client1'));
    print_r($result);

    ?>

抱歉,帖子太长了。我希望它包含所有必要的信息。 提前非常感谢!

干杯, 丹尼尔

【问题讨论】:

    标签: php arrays apache wsdl nusoap


    【解决方案1】:

    我发现了我的错误。包含结构的 complexType 必须如下所示:

        $Server -> wsdl -> addComplexType(
        'Clients',
        'complexType',
        'array',
        '',
        'SOAP-ENC:Array',
        array(),
        array(
                array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:ClientInfo')
        ),
        'tns:ClientInfo'
    

    所以最后一行是 'tns:ClientInfo' 而不是 'tns:Clients'。

    这是一个功能齐全的示例:

    server.php

        <?php
        // Includes
        require_once ('lib/nusoap.php');
        require('mysql.php');
        require('cc_functions.php');
    
        // General SOAP configuration
        $ServerName = 'server';
        $ServiceName = 'CentralConfigService';
        $ServiceURL = 'http://' . $ServerName . '/' . $ServiceName;
        $Server = new soap_server();
        $Server -> configureWSDL($ServiceName, $ServerName . '/' . $ServiceName);
    
        function GetClientInfo($ClientName)
        {
        $Clients = array();
        $Clients1 = array(
                        'HostName' => 'testiname',
                        'IP' => 'testip',
                        'Type' => 'testtype',
                        'Config' => 'testconfig',
                        'Routines' => 'testroutines',
                        'Files' => 'testfiles',
                        'Access' => 'testaccess');
    
        $Clients2 = array(
                        'HostName' => 'testiname2',
                        'IP' => 'testip2',
                        'Type' => 'testtype2',
                        'Config' => 'testconfig2',
                        'Routines' => 'testroutines2',
                        'Files' => 'testfiles2',
                        'Access' => 'testaccess2');
        array_push($Clients, $Clients1);
        array_push($Clients, $Clients2);
        return $Clients;
        }
    
    
        $Server -> wsdl -> addComplexType(
        'ClientInfo',
        'complexType',
        'struct',
        'all',
        '',
        array(
                'ID' => array('name' => 'ID', 'type' => 'xsd:integer'),
                'HostName' => array('name' => 'HostName', 'type' => 'xsd:string'),
                'IP' => array('name' => 'IP', 'type' => 'xsd:string'),
                'Type' => array('name' => 'Type', 'type' => 'xsd:string'),
                'Config' => array('name' => 'Config', 'type' => 'xsd:string'),
                'Routines' => array('name' => 'Routines', 'type' => 'xsd:string'),
                'Files' => array('name' => 'Files', 'type' => 'xsd:string'),
                'Access' => array('name' => 'Access', 'type' => 'xsd:string')
        )
        );
    
    
        $Server -> wsdl -> addComplexType(
        'Clients',
        'complexType',
        'array',
        '',
        'SOAP-ENC:Array',
        array(),
        array(
                array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:ClientInfo[]')
        ),
        'tns:ClientInfo'
        );
    
    
        $Server -> register(
        'GetClientInfo',
        array('ClientName' => 'xsd:string'),
        array('return' => 'tns:Clients'),
        $ServiceURL,
        $ServiceURL . '#GetClientInfo',
        '',
        'rpc',
        'Get config by type');
    
    
        if (!isset($HTTP_RAW_POST_DATA)) $HTTP_RAW_POST_DATA = file_get_contents('php://input');
        @$Server -> service($HTTP_RAW_POST_DATA);
    
        ?>
    

    client.php

        <?php
    
        require_once('lib/nusoap.php');
    
        $wsdl = "http://server/server.php?wsdl";
        $client = new nusoap_client($wsdl, 'wsdl');
    
        $result = $client -> call('GetClientInfo', array('ClientName'=>''));
        print_r($result);
    
        ?>
    

    【讨论】:

      猜你喜欢
      • 2011-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-07
      • 2017-04-26
      • 1970-01-01
      • 2012-12-08
      相关资源
      最近更新 更多