2015-11-27 1 views
1

J'ai le problème, que le serveur NuSOAP renvoie un tableau vide. J'ai lu et essayé beaucoup de sujets/choses mais le résultat est toujours le même. Je suppose que c'est seulement une chose mineure que vous pouvez résoudre en une minute.NuSOAP renvoie un tableau vide

Je veux mettre un tableau de chaînes contenant des informations client dans un autre tableau qui contient tous les serveurs:

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

Les tableaux vont se remplir à partir de données MySQL, mais à des fins de test, je crée un tableau statique avec des données . Voici ce que j'ai jusqu'à présent:

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

?> 

quand je l'appelle la fonction "GetClientInfo", je reçois toujours un tableau vide:

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

     [1] => Array 
      (
      ) 

     [2] => Array 
      (
      ) 

     [3] => Array 
      (
      ) 

     [4] => Array 
      (
      ) 

     [5] => Array 
      (
      ) 

     [6] => Array 
      (
      ) 

    ) 

)

Le client appelle la fonction:

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

    ?> 

Désolé pour le post long. J'espère qu'il contient toutes les informations nécessaires. Merci beaucoup d'avance!

Cheers, Daniel

Répondre

0

Je trouve mon erreur. Le complexType qui comprend le struct doit ressembler à ça:

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

So 'tns: CLIENTINFO' au lieu de 'tns: Les clients' dans la dernière ligne.

Voici un exemple pleinement fonctionnel:

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

    ?>