我在php中使用zend-soap
框架
hellows.php 中的我的网络服务类:
class Hello
{
/**
* Say hello.
*
* @param string $firstName
* @param string $lastName
* @param int $age
* @return array $aboutMe
*/
public function sayHello($firstName, $lastName, $age)
{
return $aboutMe = [
"name" => $firstName,
"lastName" => $lastName,
"age" => $age
];
}
}
自动发现配置:
$serverUrl = "http://localhost/zend/hellows.php";
$options = [
'uri' => $serverUrl,
];
$server = new Zend\Soap\Server(null, $options);
if (isset($_GET['wsdl'])) {
$soapAutoDiscover = new \Zend\Soap\AutoDiscover(/*new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeSequence()*/);
$soapAutoDiscover->setBindingStyle(array('style' => 'document'));
$soapAutoDiscover->setOperationBodyStyle(array('use' => 'literal'));
$soapAutoDiscover->setClass('Hello');
$soapAutoDiscover->setUri($serverUrl);
header("Content-Type: text/xml");
echo $soapAutoDiscover->generate()->toXml();
} else {
$soap = new \Zend\Soap\Server($serverUrl . '?wsdl');
$soap->setObject(new \Zend\Soap\Server\DocumentLiteralWrapper(new Hello()));
$soap->handle();
}
我的网络服务客户端:
$client = new Zend\Soap\Client('http://localhost/zend/hellows.php?wsdl');
$result = $client->sayHello(['firstName' => 'Jose', 'lastName' => 'Ramirez', 'age'=>20]);
之前显示的所有代码都运行正常,问题是当我转储result
变量(来自客户端文件)时,它会告诉我:
echo "<pre>";
var_dump($result);
...
object(stdClass)#4 (1) {
["sayHelloResult"]=>
string(5) "Array"
}
sayHelloResult
索引具有唯一值“Array”,它应返回array
值类型。问题是......它可以返回一个数组或只有字符串类型。
我做错了什么?