1

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 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.

4
  • 5
    Looks more like an exception is not being thrown. Let's see the code for myWebMethod(). Commented Sep 1, 2010 at 23:19
  • 3
    What is the fatal error? Commented Sep 1, 2010 at 23:21
  • Why do you think this code is in error? Commented Sep 1, 2010 at 23:22
  • 2
    If a fatal error is Class 'SoapClient' not found then your php was installed without soap support. Commented Sep 1, 2010 at 23:31

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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!
}

2 Comments

To clarify @webbiedave's answer, PHP has both errors and exceptions. You can handle errors with an error handler.
Thanks for the comments, I made an edition and noted the error I was getting. the soap extension is working fine.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.