WSF/PHP has bound this custom faults in to a PHP language constructs, so PHP developers will not need to worry about web service messages and their formats. Here is a simple example of how you can throw and catch custom faults.
your server side will be
function greet($name)
{
if(is_my_enemy($name)) {
throw new WSFault("sender", "you are not my friend");
return "<xml>{$name}</xml>";
}
$service = new WSService(array("operations" => "greet"));
$service->reply();
You will handle the fault in the client side with this code,
$client = new WSClient(array("to" => "http://localhost/url/to/above/service.php"));
try{
$res = $client->request($req);
}
catch(Exception $e)
{
if($e instanceof WSFault) {
just_report_error($e->reason);
}
}
No comments:
Post a Comment