I have a simple web service in php with zend-soap
framework
My web service class in 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
];
}
}
AutoDiscover configuration:
$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();
}
My Web Service Client:
$client = new Zend\Soap\Client('http://localhost/zend/hellows.php?wsdl');
$result = $client->sayHello(['firstName' => 'Jose', 'lastName' => 'Ramirez', 'age'=>20]);
All code earlier shown work fine, the issue is when I dump result
variable (from client file), it show me:
echo "<pre>";
var_dump($result);
...
object(stdClass)#4 (1) {
["sayHelloResult"]=>
string(5) "Array"
}
sayHelloResult
index has an unique value "Array", when it should return an array
value type. The questions is... it's posible return an array or only string type.
What I am doing wrong?