nusoap可以返回字符串数组吗?

问题描述 投票:0回答:1

我想在我的网络服务中返回一个字符串数组

我已经尝试过:

<?php
require_once('nusoap/nusoap.php');

$server = new soap_server();
$server->configureWSDL('NewsService', 'urn:NewsService');
$server->register('GetAllNews', 
 array(),
 array('return' => 'xsd:string[]'),
 'urn:NewsService',
 'urn:NewsService#GetAllNews',
 'rpc',
 'literal',
 ''
);

// Define the method as a PHP function
function GetAllNews()
{
 $stack = array("orange", "banana");
 array_push($stack, "apple", "raspberry");
 return $stack;
}

但它不起作用。 正确的语法是什么?

预先感谢您的帮助

php web-services nusoap
1个回答
0
投票

你不能返回这样的数组。要返回数组,您必须定义一个复杂类型。 我将为您提供一个例子...

服务器程序

service.php
:

    <?php
// Pull in the NuSOAP code
require_once('lib/nusoap.php');
// Create the server instance
$server = new soap_server();
// Initialize WSDL support
$server->configureWSDL('RM', 'urn:RM');

//Define complex type
$server->wsdl->addComplexType(
 'User',
 'complexType',
 'struct',
 'all',
 '',
 array(
  'Id' => array('name' => 'Id', 'type' => 'xsd:int'),
  'Name' => array('name' => 'Name', 'type' => 'xsd:string'),
  'Email' => array('name' => 'Email', 'type' => 'xsd:string'),
     'Description' => array('name' => 'Description', 'type' => 'xsd:string')
  )
);


// Register the method
$server->register('GetUser',     // method name
 array('UserName'=> 'xsd:string'),         // input parameters
 array('User' => 'tns:User'),     // output parameters
 'urn:RM',         // namespace
 'urn:RM#GetUser',     // soapaction
 'rpc',          // style
 'encoded',         // use
 'Get User Details'      // documentation
);

function GetUser($UserName) {

    return array('Id' => 1, 
       'Name' => $UserName,
       'Email' =>'[email protected]',
       'Description' =>'My desc'
       );

}

// Use the request to (try to) invoke the service
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>

还有客户端程序

client.php
:

<?php
// Pull in the NuSOAP code
require_once('lib/nusoap.php');
// Create the client instance
$client = new soapclient('http://localhost/Service/service.php');
// Call the SOAP method
$result = $client->call('GetUser', array('UserName' => 'Jim'));
// Display the result
print_r($result);
?>
© www.soinside.com 2019 - 2024. All rights reserved.