Resultado devuelto por el servicio:
NULL
<?php
require_once 'nusoap/nusoap.php';
class Client04
{
const SERVICE_NAME = '/apps/soap/service04.php?wsdl';
const FUNCTION_NAME = 'findEmployeesByName';
private $client;
private $log;
private $result;
public function __construct()
{
$wsdl = "http://{$_SERVER['HTTP_HOST']}" . self::SERVICE_NAME;
$this->client = new nusoap_client($wsdl);
if (($error = $this->client->getError())) {
$this->log("error conectado con el servicio SOAP: $error");
$this->client = null;
}
}
public function getResult()
{
return $this->result;
}
public function getLog()
{
return $this->log;
}
public function run($name)
{
if ($this->client == null) {
return false;
}
$this->result = null;
$this->log = array();
$params=array(
'name' => $name,
);
$this->log('SERVICE ' . self::FUNCTION_NAME . ' REQUEST START');
$result = $this->client->call(self::FUNCTION_NAME, $params);
$this->log('SERVICE ' . self::FUNCTION_NAME . ' REQUEST FINISHED');
if (($error = $this->client->getError())) {
$this->log('Ha ocurrido algún error');
$this->log($error);
return false;
} else {
$this->log('Todo ok');
$this->result = $result;
return true;
}
}
private function log($message)
{
$this->log[] = $message;
}
}
<?php
require_once 'nusoap/nusoap.php';
$service = 'service04';
$server = new soap_server();
$server->configureWSDL($service);
$server->wsdl->addComplexType('employeeData','complexType','struct','all','',
array(
'id' => array('name'=>'id','type'=>'xsd:int'),
'name' => array('name'=>'name','type'=>'xsd:string'),
'department' => array('name'=>'department','type'=>'xsd:string'),
)
);
$server->wsdl->addComplexType('employeeDataArray','complexType','array','','SOAP-ENC:Array',
array(),
array(
array(
'ref' => 'SOAP-ENC:arrayType',
'wsdl:arrayType' => 'tns:employeeData[]',
)
)
);
$input_array = array('name' => 'xsd:string');
$return_array = array('status' => 'xsd:string', 'message' => 'xsd:string', 'result' => 'tns:employeeDataArray');
$server->register(
'findEmployeesByName',
$input_array,
$return_array,
"urn:$service",
"urn:$service#findEmployeesByName",
'rpc',
'encoded',
'Devuelve los empleado que cuyo nombre coincida'
);
$server->service(file_get_contents('php://input'));
function findEmployeesByName($name)
{
$employees = array(
array('id' => 1, 'name' => 'Jose Perez', 'department' => 'Ventas'),
array('id' => 2, 'name' => 'Juan Ramirez', 'department' => 'Ventas'),
array('id' => 3, 'name' => 'Jose Manuel Gonzalez', 'department' => 'Administracion'),
array('id' => 4, 'name' => 'Juan Jose Garcia', 'department' => 'Recursos Humanos'),
);
$result = array();
$name = strtoupper($name);
foreach ($employees as $employee) {
if (preg_match("/$name/", strtoupper($employee['name'])) !== 0) {
$result[] = $employee;
}
}
$status = 'ok';
$message = count($result) . ' empleados encontrados';
return array('status' => $status, 'message' => $message, 'result' => $result);
}