2015-11-27 132 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); 

    ?> 

對不起,很長的職位。我希望它包含所有必要的信息。 非常感謝!

乾杯, 丹尼爾

回答

0

我發現我錯了。包含結構的複雜類型有像她那樣:

$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:客戶在最後一行。

這裏是一個全功能的例子:

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

    ?>