Server side

A Genero Web Services server can throw a SOAP fault if any processing error is encountered.

To generate a SOAP fault you need to:

For example in $FGLDIR/demo/WebServices/calculator/server/calculatorServer.4gl, the calculator server has a divide_by_zero SOAP fault. The SOAP fault is raised when you try to divide a number by zero. To generate a SOAP fault proceed as follow:

Create a SOAP fault

You define the variable to send as a SOAP fault. It can be a simple string like in this example or a complex type. Remember to assign a XMLName to the variable.
DEFINE divide_by_zero STRING ATTRIBUTES (XMLName="DividedByZero")
Then you inform the service that it can use this fault variable using function com.WebService.createFault().
LET serv = com.WebService.CreateWebService("Calculator",serviceNS)
CALL serv.createFault(divide_by_zero,FALSE)

Add the SOAP fault to an operation

A SOAP fault can be used by an operation to inform the client that an error has occurred. An operation can use different SOAP faults but only one at a time.
LET op = com.WebOperation.CreateRPCStyle("divide","Divide",divide_in,divide_out)
CALL op.addFault(divide_by_zero,NULL)

Here, the SOAP fault is added to the "divide" operation.

Send the SOAP fault

Set the values to the fault variable. The fault message is be sent to the client at the end of the operation processing.
LET divide_by_zero = "Cannot divide "||divide_in.a||" by zero"
CALL com.WebServiceEngine.SetFaultDetail(divide_by_zero)