[Fwd: Returning Soap_Fault]
| From: | Michal Ludvig | Date: | Sun, 18 Jun 2006 22:50:35 +0000 |
| Subject: | [Fwd: Returning Soap_Fault] | ||
| Groups: | php.soap | ||
| Request: | Send a blank email to php-soap+get-2310@lists.php.net to get a copy of this message | ||
(Resending. I'm not sure it went through as I wasn't subscribed to the
list before. Sorry for eventual duplicate.)
Hi all,
I've got a SOAP server using PEAR::SOAP (latest) and a client using PHP
5.1.4 bundled SOAP. I could eventually use PEAR::SOAP on the client as
well but I seem to have issues with the server so it's not an issue at
the moment.
I'm trying hard to return a proper SOAP_Fault from the server but even
after googling all around I haven't found how to do it.
Obviously I'm trying to return a SOAP_Fault from reverseMessage() method
in the code below. While playing with this code I got all different
kinds of results, from "Violation of encoding rules" to httpd crashes. I
even tried to throw a regular exception in reverseMessage() and have
try {
$server->service(...);
}
catch (Exception $ex) {
$server->_raiseSoapFault(...);
}
but that wouldn't work either.
Any hints are highly appreciated.
This is my simple server.php:
<?php
require_once('SOAP/Server.php');
require_once('SOAP/Disco.php');
class TestFault {
var $__dispatch_map = array();
function TestFault() {
$this->__dispatch_map['reverseMessage'] = array(
"in" => array("message" => "string"),
"out" => array("result" => "string"),
);
}
function reverseMessage($message)
{
# return new Soap_Fault("Exxeption:$message:", 123);
return strrev($message);
}
}
$server = new SOAP_Server();
$webservice = new TestFault();
$server->addObjectMap($webservice,
'http://schemas.xmlsoap.org/soap/envelope/');
if (isset($_SERVER['REQUEST_METHOD']) &&
$_SERVER['REQUEST_METHOD']=='POST')
$server->service($HTTP_RAW_POST_DATA);
?>
The client is even simpler:
<?php
$client = new SoapClient($wsdl_url, array('trace' => 1));
$result = $client->reverseMessage("Test Message");
if (is_soap_fault($result)) {
trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, ".
"faultstring: {$result->faultstring})",
E_ERROR);
}
print_r($result);
echo("\nDone.");
?>
Thanks
Michal Ludvig
--
* Personal homepage: http://www.logix.cz/michal