2015-11-27 8 views
1

У меня проблема, что сервер NuSOAP возвращает пустой массив. Я читал и пробовал много тем/вещей уже, но результат всегда один и тот же. Я предполагаю, что это лишь незначительная вещь, которую вы, ребята, можете решить в течение минуты.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); 

    ?> 

Извините за длинный пост. Надеюсь, он содержит всю необходимую информацию. Большое спасибо!

Cheers, Daniel

ответ

0

Я нашел ошибку. ComplexType, который включает в себя-структуру должен выглядеть так:

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

Так «ТНС: ClientInfo» вместо «ТНС: Клиенты» в последней строке.

Вот полностью функционирующий пример:

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); 

    ?> 
Смежные вопросы