Friday, January 11, 2008

Throwing a custom soap fault from a Web Service

Today I thought of describing how to return a soap fault from a WSF/PHP service.
SOAPFault is used to carry error or status information with in a soap message. For this purpose WSF/PHP extension provideds the pre defined class WSFault with the following constuctor.

WSFault(string code, string reason, string role, string detail).

Lets implement a service with will return the fault code "Sender" with reason value "Fault Test".

WSFault constructor only needs code and reason arguements to be mandatory. The other arguments are optional.

WSFault class extends the exception class. So once you create the WSFault object ,it can be thrown from the function.

Here is the complete source code for a service returning the SOAP Fault.

function sendFault($inMessage) {
throw new WSFault("Sender", "Testing WSFault");

$operations = array("getFault" => "sendFault");

$service = new WSService(array("operations" => $operations));



No comments:

Post a Comment