exception not being caught
I have the following PHP code on a web page:
$wsdl_url = "someURL?wsdl";
try {
$client = new SoapClient($wsdl_url, array('login' => 'mylogin','password' => 'mypassword'));
$client->myWebMethod(); // <-- problem call
} catch (Exception $e) {
echo "none";
}
It's a basic call to a web service. The problem is that when an error is thrown 开发者_StackOverflow社区on the line $client->myWebMethod()
, echo "none"
is not printed. In fact, nothing in the catch
block runs. Hence, I don't think the exception is being caught.
A fatal error is displayed on the web page.
Question: Any ideas on why this is happening? I expected all exceptions to be caught and handled with this code. But what I'm getting is that the fatal error is being displayed on the page. Maybe web services are handled differently?
EDIT: the error is that it's missing a bunch of required parameters. if I add the parameters the call works fine. I am purposely omitting the parameters to get the error, so i would know how to handle it.
The error is something like: Fatal error: SOAP-ERROR: Object hasn't 'myparameter1'
Thanks in advance.
I got the same exact problem this morning while running a custom module for Drupal which required an external SOAP Web Service. To be honest, I'm not quite sure how I solved the problem.
Turns out it was all about clearing my Web Server's cache that had to do with the respective WSDL. In your tmp/ folder you will find various files named wsdl-yourservice-etc. Delete them and it should be OK. If not, the problem lies in the code and more specifically in the sequence and syntax of the arguments passed to the WSDL.
I hope I helped.
Unfortunately, this is not a catchable error.
However, you can check if the soap extension is loaded before trying to instantiate it by calling get_loaded_extensions with something along the lines of:
if (in_array('soap', get_loaded_extensions())) {
// it's loaded!
}
精彩评论