Resultado devuelto por el servicio:
NULL
<?php
require_once 'nusoap/nusoap.php';
class Client03
{
const SERVICE_NAME = '/apps/soap/service03.php?wsdl';
const FUNCTION_NAME = 'getEmployeeById';
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($employeeId)
{
if ($this->client == null) {
return false;
}
$this->result = null;
$this->log = array();
$params=array(
'id' => $employeeId,
);
$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 = 'service03';
$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'),
)
);
$input_array = array('id' => 'xsd:int');
$return_array = array('status' => 'xsd:string', 'message' => 'xsd:string', 'result' => 'tns:employeeData');
$server->register(
'getEmployeeById',
$input_array,
$return_array,
"urn:$service",
"urn:$service#getEmployeeById",
'rpc',
'encoded',
'Devuelve los empleado que cuyo nombre coincida'
);
$server->service(file_get_contents('php://input'));
function getEmployeeById($id)
{
$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 = null;
foreach ($employees as $employee) {
if ($employee['id'] == $id) {
$result = $employee;
}
}
if ($result !== null) {
$status = 'ok';
$message = "empleado id $id encontrado";
} else {
$status = 'error';
$message = "empleado id $id no encontrado";
}
return array('status' => $status, 'message' => $message, 'result' => $result);
}