docs.intersystems.com
Home  /  Application Development: Additional Options  /  Web Services Quick Start Tutorial  /  Web Service Error Handling in InterSystems IRIS  /  Generating a SOAP Fault


Web Services Quick Start Tutorial
Generating a SOAP Fault
[Back]  [Next] 
InterSystems: The power behind what matters   
Search:  


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.WebService 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)
}