Although your comments didn't correlate with my initial test results, I
realised they may have been skewed by the rest of the application
infrastructure, so I decided to write a stand-alone module to test the
various options. I have posted the code below in the hope that it helps
somebody else who is trying to figure this out.
The short answer is that trigger_error('Some message', E_USER_ERROR) seems
to be the best approach, as it results in a SOAP Fault document being passed
back to the client without requiring any SOAP-specific code in the class
whose functionality is being exposed, which is pretty much what I wanted.
Unfortunately this solution doesn't provide the facility to return an error
code, but I'm not too fussed about that.
FWIW, here is my test code:
<?php
/* zstest.php - Simple module to test Zend_Soap_Server error handling
behaviour */
set_include_path( '../ws/library/' . get_include_path());
require_once "Zend/Loader.php";
Zend_Loader::registerAutoload();
if ( isset($_GET['wsdl'])) {
$auto = new Zend_Soap_AutoDiscover();
$auto->setClass('Foo');
$auto->handle();
} else if ( isset($_GET['ping'])) {
$client = new Zend_Soap_Client('http://localhost/zstest.php?wsdl');
try {
echo $client->ping('Hello World!'), '<br />';
} catch ( Exception $e ) {
echo 'Exception caught: ', $e->faultcode , ' - ', $e->faultstring,
'<br />';
}
echo htmlentities($client->getLastResponse());
} else {
$server = new Zend_Soap_Server('http://localhost/zstest.php?wsdl');
$server->setClass('Foo');
$server->handle();
}
class Foo
{
/**
* @param string $testData
* @return string
*/
public function ping( $testData )
{
// throw new SoapFault( '1', 'Die' ); /* Error code and message
passed back in SOAP Fault document. */
// die( 'Die' ); /* SOAP Fault document is NOT returned by server. */
// trigger_error('Die', E_USER_ERROR); /* Best compromise. */
return $testData;
}
}
?>
beberlei wrote:
>
>
> The Zend Soap Server internally catches all exceptions, warnings and
> notices and transforms them
> into XML SOAP Fault Response MEssages which are sent back to the client.
>
> You can even decide which Error Messages are taken from the Exception
> based
> on the Exception type with $server->registerException() // or something
> like that.
>
> greetings,
> Benjamin
>
>
--
View this message in context: http://www.nabble.com/Zend-SOAP-server%3A-what-is-the-best-approach-for-error-exception-handling--tp22467835p22486501.html
Sent from the Zend Web Services mailing list archive at Nabble.com.
没有评论:
发表评论