SoapClient Returns "NULL", but __getLastResponse() returns XML
Asked Answered
S

3

7

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);
Shapiro answered 3/7, 2013 at 6:43 Comment(1)
According to the wsdl, the soap response is incorrect (by the server), so the client cannot parse it. I have tested your code and the response XML contains HighLowValues tag, but it is related to the getHighLowTidePredictionsResponse function.Permian
G
5

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

Girt answered 26/9, 2014 at 9:26 Comment(0)
E
2

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

Endlong answered 3/7, 2013 at 6:50 Comment(0)
W
0

I had this same issue. If I used curl against the WSDL address I got a response. Yet when the WSDL was accessed through the PHP code, an error triggered. The issue was ultimately in the CA certificate. There was an "openssl.cafile" setting, with the php.init file, that pointed to a particular certificate that the WSDL endpoint rejected.

When I commented this out - by sticking a ';' in from of the openssl.cafile setting in the /etc/php.ini file, and bounced Apache, the WSDL connection through the PHP code worked.

Since curl worked and no option to override the certificates (i.e., no -k option was used) and it worked, then you know that the server-level setting was valid for that WSDL endpoint.

Hoping this makes sense and that is of some help for someone out there.

Watercool answered 15/5, 2024 at 18:49 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.