Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SoapClient Returns "NULL", but __getLastResponse() returns XML

The variable $response in the below code is NULL even though it should be the value of the SOAP request. (a list of tides). When I call $client->__getLastResponse() I get the correct output from the SOAP service.

Anybody know what is wrong here? Thanks! :)

Here is my code :

$options = array(
  "trace" => true,
  "encoding" => "utf-8"
);
$client = new SoapClient("http://opendap.co-ops.nos.noaa.gov/axis/webservices/highlowtidepred/wsdl/HighLowTidePred.wsdl", $options);

$params = array(
    "stationId" => 8454000,
    "beginDate" => "20060921 00:00",
    "endDate" => "20060922 23:59",
    "datum" => "MLLW",
    "unit" => 0,
    "timeZone" => 0
);

try {
 $result = $client->getHLPredAndMetadata($params);
 echo $client->__getLastResponse();
}
catch (Exception $e) {
  $error_xml =  $client->__getLastRequest();
  echo $error_xml;
  echo "\n\n".$e->getMessage();
}
var_dump($result);
like image 248
Padraig Avatar asked Jul 03 '13 06:07

Padraig


2 Answers

The reason that the $result (or the response to the SoapCall) is null is indeed because the WSDL is invalid.

I just ran into the same problem - the WSDL said the response should be PackageChangeBatchResponse yet the actual XML returns has PackageChangeResponse

Changing the WSDL to match the response / changing the response to match the WSDL resolves the issue

like image 135
Manse Avatar answered Sep 18 '22 22:09

Manse


you should give an option parameter as below :

<?php 
// below $option=array('trace',1); 
// correct one is below 
$option=array('trace'=>1); 

$client=new SoapClient('some.wsdl',$option); 

try{ 
  $client->aMethodAtRemote(); 
}catch(SoapFault $fault){ 
  // <xmp> tag displays xml output in html 
  echo 'Request : <br/><xmp>', 
  $client->__getLastRequest(), 
  '</xmp><br/><br/> Error Message : <br/>', 
  $fault->getMessage(); 
} 
?> 

"trace" parameter enables the output of request. Now, you should see the SOAP request. (source: PHP.net

like image 23
Matheno Avatar answered Sep 19 '22 22:09

Matheno