Skip to main content

Generating a SOAP Fault

Every place in Web Service producer code that could generate an error should be able to generate SOAP faults. To avoid repeating the SOAP fault generating code multiple times, you can create a single method that generates the fault. This method can be invoked from every location in your producer code that can generate an error.

The following method takes the error code and detail as parameters and generates an appropriate SOAP fault. It invokes the %SOAP.WebServiceOpens in a new tab ReturnFault method which stops execution of the Web Service immediately and returns a valid SOAP message to the client. This SOAP envelope contains the SOAP fault instead of the regular data body.

Add this method to your SOAPTutorial.SOAPService class and recompile.

Method ApplicationError(code, detail)
 set fault=##class(%SOAP.Fault).%New()
 set fault.faultcode=code
 set fault.detail=detail
 set fault.faultstring="application error"
 // ReturnFault must be called to send the fault to the client.
 // ReturnFault will not return here.
 do ..ReturnFault(fault)
FeedbackOpens in a new tab