Skip to main content

Error Handling Logic

You can use the ApplicationError method to generate a SOAP fault at every point where your Web Service might generate an error. For example, currently the SOAPTutorial.SOAPService GetContact method ends normally, by returning “”, if there is no Contact with an ID value matching the client's input. In this situation, the method should properly generate an error.

Modify the SOAPTutorial.SOAPService GetContact so that it generates a SOAP fault. Here is the new method. Notice that it passes appropriate values for faultcode and detail to ApplicationError.

Method GetContact(id As %String) As SOAPTutorial.Contact [ WebMethod ]
 if ##class(SOAPTutorial.Contact).%ExistsId(id) {
  quit ##class(SOAPTutorial.Contact).%OpenId(id)
 else {
  do ..ApplicationError("ContactNotFound", 
                                 "Contact with id "_id_" could not be found!")
FeedbackOpens in a new tab