2

我在带有zend-soap框架的 php 中有一个简单的 Web 服务

我在hellos.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"
}

sayHelloResultindex 有一个唯一值“Array”,它应该返回一个array值类型。问题是......它可能返回一个数组或仅返回字符串类型。

我做错了什么?

4

0 回答 0