0
I’m having a very unusual problem with a SOAP application. I have a simple client to take a consumer test.
When I test directly in the service view action returns the result correctly, but when I try to consume the same functionality by a client it returns me null
.
I looked at the PHP error log no wamp, and gives the following error:
Undefined variable: json in C: wamp64 www service-stsc module Webservice src Webservice Api Webserviceapi.php on line 591
OBS: I have other functions in this same service and are functioning normally.
Client:
parse.php
$client = new SoapClient('http://localhost/service-stsc/webservice/soap?wsdl');
var_dump($result = $client->__soapCall('ConsultaAnalitica', array(
'2017-06-05',
'2017-06-05')
));
Server:
Tsccontroller.php
public function analiseAction()
{
try
{
$webServiceApi = new WebServiceApi(array(TSCController::$TSCModel => $this->getModel(TSCController::$TSCModel)));
echo $webServiceApi->ConsultaAnalitica($dataInicial,$dataFinal);
exit;
}
catch(\Exception $ex)
{
return $ex->getMessage();
}
}
Webserviceapi.php
public function ConsultaAnalitica($dataInicial, $dataFinal)
{
try{
if (($tscs = $this->TSC->ConsultaAnaliticaSQL($dataInicial, $dataFinal)) != null){
foreach ($tscs as $tsc)
{
$array[$tsc->DataHora] = $tsc->Quantidade;
$json = json_encode($array);
}
return $json; <-- LINHA 591
}
}
catch(\Exception $ex)
{
$this->Log->Ocorrencia = 2;
$this->Log->Motivo = 'Problemas na consulta de tsc por data hora através do serviço de integração. Detalhes: ' . $ex->getMessage();
$this->Log->insertToLog($this->Log->toArray());
return false;
}
}
Tscmodel.php
public function ConsultaAnaliticaSQL($dataInicial, $dataFinal){
try{
$sqlTSC = "SELECT DataHoraOcorrencia as DataHora, COUNT(TSC.ID) as Quantidade FROM TSC WHERE DataHoraOcorrencia BETWEEN '$dataInicial' AND '$dataFinal' GROUP BY DATE(TSC.DataHoraOcorrencia)";
$TSC = $this->tableGateway->getAdapter()->query($sqlTSC,array());
return $TSC;
} catch (\Exception $ex) {
return $ex->getMessage();
}
}
$tscs
is empty does not enter noforeach
and does not create the variable$json
. I wouldn’t compare to null using aempty()
. Or set a default value for$json
– rray
But when I access my analysisAction (which is in Tsccontroller) that is within the service, it returns the value in json. Only returns null when accessed by a client.
– Jonathan de Toni