我遇到的问题是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);
?>
当我调用函数&#34; GetClientInfo&#34;时,我总是得到一个空数组:
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 :(得分:0)
我发现了自己的错误。包含结构的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);
?>