E_ERROR in SoapClient

View: New views
10 Messages — Rating Filter:   Alert me  

E_ERROR in SoapClient

by Paulo Azevedo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Is there a way to prevent the E_ERROR when SoapClient is not able to load a
WSDL file?

I just want to handle the error gracefully.

Thanks.

--
-Paulo
http://twitter.com/halufa

Re: E_ERROR in SoapClient

by David Zülke-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 30.07.2009, at 12:26, Paulo Azevedo wrote:

> Is there a way to prevent the E_ERROR when SoapClient is not able to  
> load a
> WSDL file?
>
> I just want to handle the error gracefully.

Yes. See http://php.net/manual/en/soapclient.soapclient.php

- David




smime.p7s (3K) Download Attachment

Re: E_ERROR in SoapClient

by Paulo Azevedo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

My problem is that SoapClient triggers a E_ERROR ( Fatal Error ) instead of
throwing an Exception.
Since E_ERROR cannot be catchable I don't find a way to gracefully handly
this problem.

PHP Fatal error:  SOAP-ERROR: Encoding: object hasn't 'profileData' property


Is there any way to gracefully catch this error?

--
-Paulo
http://twitter.com/halufa

Re: Re: E_ERROR in SoapClient

by Richard Quadling :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/7/31 Paulo Azevedo <halufa@...>:

> My problem is that SoapClient triggers a E_ERROR ( Fatal Error ) instead of
> throwing an Exception.
> Since E_ERROR cannot be catchable I don't find a way to gracefully handly
> this problem.
>
> PHP Fatal error:  SOAP-ERROR: Encoding: object hasn't 'profileData' property
>
>
> Is there any way to gracefully catch this error?
>
> --
> -Paulo
> http://twitter.com/halufa
>

You can tell the SoapClient to generate exceptions rather than errors.

[1] "The exceptions option is a boolean value defining whether soap
errors throw exceptions of type SoapFault."

Regards,

Richard.

[1] http://docs.php.net/manual/en/soapclient.soapclient.php
--
-----
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"
ZOPA : http://uk.zopa.com/member/RQuadling

--
PHP Soap Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: Re: E_ERROR in SoapClient

by Richard Quadling :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/7/31 Richard Quadling <rquadling@...>:

> 2009/7/31 Paulo Azevedo <halufa@...>:
>> My problem is that SoapClient triggers a E_ERROR ( Fatal Error ) instead of
>> throwing an Exception.
>> Since E_ERROR cannot be catchable I don't find a way to gracefully handly
>> this problem.
>>
>> PHP Fatal error:  SOAP-ERROR: Encoding: object hasn't 'profileData' property
>>
>>
>> Is there any way to gracefully catch this error?
>>
>> --
>> -Paulo
>> http://twitter.com/halufa
>>
>
> You can tell the SoapClient to generate exceptions rather than errors.
>
> [1] "The exceptions option is a boolean value defining whether soap
> errors throw exceptions of type SoapFault."
>
> Regards,
>
> Richard.
>
> [1] http://docs.php.net/manual/en/soapclient.soapclient.php
> --
> -----
> Richard Quadling
> Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
> "Standing on the shoulders of some very clever giants!"
> ZOPA : http://uk.zopa.com/member/RQuadling
>

<?php
try
        {
        $client=new SoapClient('http://api.rkd.reuters.com/schemas/wsdl/Charts_1_HttpAndRKDToken.wsdl',
array('exceptions' => True));
        }
catch(Exception $exception)
        {
        echo $exception;
        }
echo 'Finished';


outputs ...

SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Unknown required
WSDL extension 'http://schemas.xmlsoap.org/wsdl/soap/' in
Z:\soapbad.php:4
Stack trace:
#0 Z:\soapbad.php(4): SoapClient->SoapClient('http://api.rkd....', Array)
#1 {main}Finished



--
-----
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"
ZOPA : http://uk.zopa.com/member/RQuadling

--
PHP Soap Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: Re: E_ERROR in SoapClient

by David Zülke-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

However, that doesn't happen if the WSDL cannot be loaded at all IIRC  
(e.g. on a 404).

- David



On 31.07.2009, at 17:52, Richard Quadling wrote:

> 2009/7/31 Richard Quadling <rquadling@...>:
>> 2009/7/31 Paulo Azevedo <halufa@...>:
>>> My problem is that SoapClient triggers a E_ERROR ( Fatal Error )  
>>> instead of
>>> throwing an Exception.
>>> Since E_ERROR cannot be catchable I don't find a way to gracefully  
>>> handly
>>> this problem.
>>>
>>> PHP Fatal error:  SOAP-ERROR: Encoding: object hasn't  
>>> 'profileData' property
>>>
>>>
>>> Is there any way to gracefully catch this error?
>>>
>>> --
>>> -Paulo
>>> http://twitter.com/halufa
>>>
>>
>> You can tell the SoapClient to generate exceptions rather than  
>> errors.
>>
>> [1] "The exceptions option is a boolean value defining whether soap
>> errors throw exceptions of type SoapFault."
>>
>> Regards,
>>
>> Richard.
>>
>> [1] http://docs.php.net/manual/en/soapclient.soapclient.php
>> --
>> -----
>> Richard Quadling
>> Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
>> "Standing on the shoulders of some very clever giants!"
>> ZOPA : http://uk.zopa.com/member/RQuadling
>>
>
> <?php
> try
> {
> $client=new SoapClient('http://api.rkd.reuters.com/schemas/wsdl/Charts_1_HttpAndRKDToken.wsdl' 
> ,
> array('exceptions' => True));
> }
> catch(Exception $exception)
> {
> echo $exception;
> }
> echo 'Finished';
>
>
> outputs ...
>
> SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Unknown required
> WSDL extension 'http://schemas.xmlsoap.org/wsdl/soap/' in
> Z:\soapbad.php:4
> Stack trace:
> #0 Z:\soapbad.php(4): SoapClient->SoapClient('http://api.rkd....',  
> Array)
> #1 {main}Finished
>
>
>
> --
> -----
> Richard Quadling
> Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
> "Standing on the shoulders of some very clever giants!"
> ZOPA : http://uk.zopa.com/member/RQuadling
>
> --
> PHP Soap Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


smime.p7s (3K) Download Attachment

Re: Re: E_ERROR in SoapClient

by Paulo Azevedo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks for your answer.
Your code is complaining about loading the extension, not the WSDL file.

I've tried this code:
$client = new SoapClient( "http://127.0.0.1/nonexiting.wsdl",
    array(
        'exceptions' => true,
        'trace'    => true,
        'cache_wsdl' => WSDL_CACHE_NONE
    )
);

and it gives the error:
PHP Fatal error:  SOAP-ERROR: Parsing WSDL: Couldn't load from '
http://127.0.0.1/nonexiting.wsdl' : failed to load external entity "
http://127.0.0.1/nonexiting.wsdl"

As far as i know the 'exceptions' => true is set by default but it only
works for SoapFault exceptions.

2009/7/31 Richard Quadling <rquadling@...>

> 2009/7/31 Richard Quadling <rquadling@...>:
> > 2009/7/31 Paulo Azevedo <halufa@...>:
> >> My problem is that SoapClient triggers a E_ERROR ( Fatal Error ) instead
> of
> >> throwing an Exception.
> >> Since E_ERROR cannot be catchable I don't find a way to gracefully
> handly
> >> this problem.
> >>
> >> PHP Fatal error:  SOAP-ERROR: Encoding: object hasn't 'profileData'
> property
> >>
> >>
> >> Is there any way to gracefully catch this error?
> >>
> >> --
> >> -Paulo
> >> http://twitter.com/halufa
> >>
> >
> > You can tell the SoapClient to generate exceptions rather than errors.
> >
> > [1] "The exceptions option is a boolean value defining whether soap
> > errors throw exceptions of type SoapFault."
> >
> > Regards,
> >
> > Richard.
> >
> > [1] http://docs.php.net/manual/en/soapclient.soapclient.php
> > --
> > -----
> > Richard Quadling
> > Zend Certified Engineer :
> http://zend.com/zce.php?c=ZEND002498&r=213474731
> > "Standing on the shoulders of some very clever giants!"
> > ZOPA : http://uk.zopa.com/member/RQuadling
> >
>
> <?php
> try
>        {
>        $client=new SoapClient('
> http://api.rkd.reuters.com/schemas/wsdl/Charts_1_HttpAndRKDToken.wsdl',
> array('exceptions' => True));
>        }
> catch(Exception $exception)
>        {
>        echo $exception;
>        }
> echo 'Finished';
>
>
> outputs ...
>
> SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Unknown required
> WSDL extension 'http://schemas.xmlsoap.org/wsdl/soap/' in
> Z:\soapbad.php:4
> Stack trace:
> #0 Z:\soapbad.php(4): SoapClient->SoapClient('http://api.rkd....', Array)
> #1 {main}Finished
>
>
>
> --
> -----
> Richard Quadling
> Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
> "Standing on the shoulders of some very clever giants!"
> ZOPA : http://uk.zopa.com/member/RQuadling
>



--
-Paulo
http://twitter.com/halufa

Re: Re: E_ERROR in SoapClient

by Richard Quadling :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/7/31 Paulo Azevedo <halufa@...>:

> Thanks for your answer.
> Your code is complaining about loading the extension, not the WSDL file.
>
> I've tried this code:
> $client = new SoapClient( "http://127.0.0.1/nonexiting.wsdl",
>    array(
>        'exceptions' => true,
>        'trace'    => true,
>        'cache_wsdl' => WSDL_CACHE_NONE
>    )
> );
>
> and it gives the error:
> PHP Fatal error:  SOAP-ERROR: Parsing WSDL: Couldn't load from '
> http://127.0.0.1/nonexiting.wsdl' : failed to load external entity "
> http://127.0.0.1/nonexiting.wsdl"
>
> As far as i know the 'exceptions' => true is set by default but it only
> works for SoapFault exceptions.
>
> 2009/7/31 Richard Quadling <rquadling@...>
>
>> 2009/7/31 Richard Quadling <rquadling@...>:
>> > 2009/7/31 Paulo Azevedo <halufa@...>:
>> >> My problem is that SoapClient triggers a E_ERROR ( Fatal Error ) instead
>> of
>> >> throwing an Exception.
>> >> Since E_ERROR cannot be catchable I don't find a way to gracefully
>> handly
>> >> this problem.
>> >>
>> >> PHP Fatal error:  SOAP-ERROR: Encoding: object hasn't 'profileData'
>> property
>> >>
>> >>
>> >> Is there any way to gracefully catch this error?
>> >>
>> >> --
>> >> -Paulo
>> >> http://twitter.com/halufa
>> >>
>> >
>> > You can tell the SoapClient to generate exceptions rather than errors.
>> >
>> > [1] "The exceptions option is a boolean value defining whether soap
>> > errors throw exceptions of type SoapFault."
>> >
>> > Regards,
>> >
>> > Richard.
>> >
>> > [1] http://docs.php.net/manual/en/soapclient.soapclient.php
>> > --
>> > -----
>> > Richard Quadling
>> > Zend Certified Engineer :
>> http://zend.com/zce.php?c=ZEND002498&r=213474731
>> > "Standing on the shoulders of some very clever giants!"
>> > ZOPA : http://uk.zopa.com/member/RQuadling
>> >
>>
>> <?php
>> try
>>        {
>>        $client=new SoapClient('
>> http://api.rkd.reuters.com/schemas/wsdl/Charts_1_HttpAndRKDToken.wsdl',
>> array('exceptions' => True));
>>        }
>> catch(Exception $exception)
>>        {
>>        echo $exception;
>>        }
>> echo 'Finished';
>>
>>
>> outputs ...
>>
>> SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Unknown required
>> WSDL extension 'http://schemas.xmlsoap.org/wsdl/soap/' in
>> Z:\soapbad.php:4
>> Stack trace:
>> #0 Z:\soapbad.php(4): SoapClient->SoapClient('http://api.rkd....', Array)
>> #1 {main}Finished
>>
>>
>>
>> --
>> -----
>> Richard Quadling
>> Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
>> "Standing on the shoulders of some very clever giants!"
>> ZOPA : http://uk.zopa.com/member/RQuadling
>>
>
>
>
> --
> -Paulo
> http://twitter.com/halufa
>

Really?

Look at my code ...

<?php
try
        {
// $client=new
SoapClient('http://api.rkd.reuters.com/schemas/wsdl/Charts_1_HttpAndRKDToken.wsdl',
array('exceptions' => True));
        $client = new SoapClient( "http://127.0.0.1/nonexiting.wsdl",
array('exceptions' => True));
        }
catch(Exception $exception)
        {
        echo $exception;
        }
echo PHP_EOL, PHP_EOL, "Look I finished the program and didn't crash!";
?>

See the message at the end?

I run this and get output of ...

===============
SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load
from 'http://127.0.0.1/nonexiting.wsdl' : failed to load external
entity "http://127.0.0.1/nonexiting.wsdl"
 in Z:\soapbad.php:5
Stack trace:
#0 Z:\soapbad.php(5): SoapClient->SoapClient('http://127.0.0....', Array)
#1 {main}

Look I finished the program and didn't crash!
=================


If you are getting the SOAPclient to throw an exception, you would
normally be expected to catch it.

Other wise you end up with an uncaught exception. I use a global
handler for these so I can be lazy.

My catch() clause could just as easily have been ...

echo "We didn't get what we wanted.", PHP_EOL;



--
-----
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"
ZOPA : http://uk.zopa.com/member/RQuadling

--
PHP Soap Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: Re: E_ERROR in SoapClient

by Paulo Azevedo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm sorry, but your code doesn't work for me, heres a dump of what I did:

*[pazevedo@scmat116 html]$ cat t.php*
<?php
try {
    $client = new SoapClient( "http://127.0.0.1/nonexiting.wsdl",
        array('exceptions' => True)
    );
} catch( Exception $exception ) {
    echo $exception;
}
echo PHP_EOL, PHP_EOL, "Look I finished the program and didn't crash!";
?>
*[pazevedo@scmat116 html]$ php t.php*
PHP Fatal error:  SOAP-ERROR: Parsing WSDL: Couldn't load from '
http://127.0.0.1/nonexiting.wsdl' : failed to load external entity "
http://127.0.0.1/nonexiting.wsdl"
 in /var/www/html/t.php on line 11

Do you use any special/specific configuration on your php.ini ?

I tried this on PHP 5.2.10 on Windows and Linux.


2009/7/31 Richard Quadling <rquadling@...>

> 2009/7/31 Paulo Azevedo <halufa@...>:
> > Thanks for your answer.
> > Your code is complaining about loading the extension, not the WSDL file.
> >
> > I've tried this code:
> > $client = new SoapClient( "http://127.0.0.1/nonexiting.wsdl",
> >    array(
> >        'exceptions' => true,
> >        'trace'    => true,
> >        'cache_wsdl' => WSDL_CACHE_NONE
> >    )
> > );
> >
> > and it gives the error:
> > PHP Fatal error:  SOAP-ERROR: Parsing WSDL: Couldn't load from '
> > http://127.0.0.1/nonexiting.wsdl' : failed to load external entity "
> > http://127.0.0.1/nonexiting.wsdl"
> >
> > As far as i know the 'exceptions' => true is set by default but it only
> > works for SoapFault exceptions.
> >
> > 2009/7/31 Richard Quadling <rquadling@...>
> >
> >> 2009/7/31 Richard Quadling <rquadling@...>:
> >> > 2009/7/31 Paulo Azevedo <halufa@...>:
> >> >> My problem is that SoapClient triggers a E_ERROR ( Fatal Error )
> instead
> >> of
> >> >> throwing an Exception.
> >> >> Since E_ERROR cannot be catchable I don't find a way to gracefully
> >> handly
> >> >> this problem.
> >> >>
> >> >> PHP Fatal error:  SOAP-ERROR: Encoding: object hasn't 'profileData'
> >> property
> >> >>
> >> >>
> >> >> Is there any way to gracefully catch this error?
> >> >>
> >> >> --
> >> >> -Paulo
> >> >> http://twitter.com/halufa
> >> >>
> >> >
> >> > You can tell the SoapClient to generate exceptions rather than errors.
> >> >
> >> > [1] "The exceptions option is a boolean value defining whether soap
> >> > errors throw exceptions of type SoapFault."
> >> >
> >> > Regards,
> >> >
> >> > Richard.
> >> >
> >> > [1] http://docs.php.net/manual/en/soapclient.soapclient.php
> >> > --
> >> > -----
> >> > Richard Quadling
> >> > Zend Certified Engineer :
> >> http://zend.com/zce.php?c=ZEND002498&r=213474731
> >> > "Standing on the shoulders of some very clever giants!"
> >> > ZOPA : http://uk.zopa.com/member/RQuadling
> >> >
> >>
> >> <?php
> >> try
> >>        {
> >>        $client=new SoapClient('
> >> http://api.rkd.reuters.com/schemas/wsdl/Charts_1_HttpAndRKDToken.wsdl',
> >> array('exceptions' => True));
> >>        }
> >> catch(Exception $exception)
> >>        {
> >>        echo $exception;
> >>        }
> >> echo 'Finished';
> >>
> >>
> >> outputs ...
> >>
> >> SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Unknown required
> >> WSDL extension 'http://schemas.xmlsoap.org/wsdl/soap/' in
> >> Z:\soapbad.php:4
> >> Stack trace:
> >> #0 Z:\soapbad.php(4): SoapClient->SoapClient('http://api.rkd....',
> Array)
> >> #1 {main}Finished
> >>
> >>
> >>
> >> --
> >> -----
> >> Richard Quadling
> >> Zend Certified Engineer :
> http://zend.com/zce.php?c=ZEND002498&r=213474731
> >> "Standing on the shoulders of some very clever giants!"
> >> ZOPA : http://uk.zopa.com/member/RQuadling
> >>
> >
> >
> >
> > --
> > -Paulo
> > http://twitter.com/halufa
> >
>
> Really?
>
> Look at my code ...
>
> <?php
> try
>        {
> //      $client=new
> SoapClient('
> http://api.rkd.reuters.com/schemas/wsdl/Charts_1_HttpAndRKDToken.wsdl',
> array('exceptions' => True));
>         $client = new SoapClient( "http://127.0.0.1/nonexiting.wsdl",
> array('exceptions' => True));
>        }
> catch(Exception $exception)
>        {
>        echo $exception;
>        }
> echo PHP_EOL, PHP_EOL, "Look I finished the program and didn't crash!";
> ?>
>
> See the message at the end?
>
> I run this and get output of ...
>
> ===============
> SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load
> from 'http://127.0.0.1/nonexiting.wsdl' : failed to load external
> entity "http://127.0.0.1/nonexiting.wsdl"
>  in Z:\soapbad.php:5
> Stack trace:
> #0 Z:\soapbad.php(5): SoapClient->SoapClient('http://127.0.0....', Array)
> #1 {main}
>
> Look I finished the program and didn't crash!
> =================
>
>
> If you are getting the SOAPclient to throw an exception, you would
> normally be expected to catch it.
>
> Other wise you end up with an uncaught exception. I use a global
> handler for these so I can be lazy.
>
> My catch() clause could just as easily have been ...
>
> echo "We didn't get what we wanted.", PHP_EOL;
>
>
>
> --
> -----
> Richard Quadling
> Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
> "Standing on the shoulders of some very clever giants!"
> ZOPA : http://uk.zopa.com/member/RQuadling
>



--
-Paulo
http://twitter.com/halufa

Re: Re: E_ERROR in SoapClient

by David Zülke-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 31.07.2009, at 18:37, Richard Quadling wrote:

> Really?
>
> Look at my code ...
>
> <?php
> try
> {
> // $client=new
> SoapClient('http://api.rkd.reuters.com/schemas/wsdl/Charts_1_HttpAndRKDToken.wsdl' 
> ,
> array('exceptions' => True));
> $client = new SoapClient( "http://127.0.0.1/nonexiting.wsdl",
> array('exceptions' => True));
> }
> catch(Exception $exception)
> {
> echo $exception;
> }
> echo PHP_EOL, PHP_EOL, "Look I finished the program and didn't  
> crash!";
> ?>
>
> See the message at the end?
>
> I run this and get output of ...
>
> ===============
> SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load
> from 'http://127.0.0.1/nonexiting.wsdl' : failed to load external
> entity "http://127.0.0.1/nonexiting.wsdl"
> in Z:\soapbad.php:5
> Stack trace:
> #0 Z:\soapbad.php(5): SoapClient->SoapClient('http://127.0.0....',  
> Array)
> #1 {main}
>
> Look I finished the program and didn't crash!
> =================
What PHP version is that?

- David




smime.p7s (3K) Download Attachment