Release 10.1A: OpenEdge Development:
Web Services

> ## Common procedure for SOAP fault handling

> The examples `StockQuotes.p` and `DataFormats.p` share a common procedure (using their own physical code copies) for handling SOAP faults. This works because the possible information that can be received for a SOAP fault is essentially the same for all Web services. You can, of course, design such a procedure differently to manage the error information and present it to the user. However, just about any design that you choose can work with any Web service.

> This is the procedure that both procedures call to handle all errors, including SOAP faults (modified to include numeric step comments that are referenced by the following description):

>     PROCEDURE ErrorInfo: /*1*/
>       DEFINE OUTPUT PARAMETER errorfound AS LOGICAL INITIAL FALSE.
>       DEFINE VARIABLE i AS INTEGER.
>       DEFINE VARIABLE hSOAPFault AS HANDLE.
>       DEFINE VARIABLE hSOAPFaultDetail AS HANDLE.
>       DEFINE VARIABLE HeaderXML AS LONGCHAR VIEW-AS EDITOR SIZE 70 BY 15 LARGE.
>       IF ERROR-STATUS:NUM-MESSAGES > 0 THEN
>       DO:
>          errorfound = TRUE.
>          DO i = 1 TO ERROR-STATUS:NUM-MESSAGES:
>             MESSAGE ERROR-STATUS:GET-MESSAGE(i) VIEW-AS ALERT-BOX.
>          END.
>     /*2*/
>          IF VALID-HANDLE(ERROR-STATUS:ERROR-OBJECT-DETAIL) THEN
>          DO:
>            hSOAPFault = ERROR-STATUS:ERROR-OBJECT-DETAIL.
>            MESSAGE
>            "Fault Code: "   hSOAPFault:SOAP-FAULT-CODE        SKIP
>            "Fault String: " hSOAPFault:SOAP-FAULT-STRING      SKIP
>            "Fault Actor: "  hSOAPFault:SOAP-FAULT-ACTOR       SKIP
>            "Error Type: "   hSOAPFault:TYPE  VIEW-AS ALERT-BOX.
>     /*3*/
>            IF VALID-HANDLE(hSOAPFault:SOAP-FAULT-DETAIL) THEN
>             DO:
>                 hSOAPFaultDetail = hSOAPFault:SOAP-FAULT-DETAIL.
>                 MESSAGE  "Error Type: " hSOAPFaultDetail:TYPE
>                          VIEW-AS ALERT-BOX.
>                 HeaderXML = hSOAPFaultDetail:GET-SERIALIZED().
>                 DISPLAY HeaderXML LABEL "Serialized SOAP fault detail"
>                         WITH FRAME a.
>             END.
>          END.
>       END.
>     END.

> This code:

> 1. Determines whether an error has occurred from the value of the `OUTPUT` parameter, which is set to `TRUE` if error messages exist. Each example procedure calls `ErrorInfo` after invoking a Web service operation. For example:

>       RUN GetStockQuotes IN hPortType (INPUT lcSymbol, OUTPUT lcQuote)
>           NO-ERROR.
>       RUN ErrorInfo (OUTPUT err).
>       IF NOT err THEN
>         /* Process operation results. */
>         . . .

> If an error occurs, `ErrorInfo` has already processed the error information in expectation that no normal results are available from the operation to process.

> 2. After displaying all the available error messages, `ErrorInfo` verifies that a SOAP fault caused the error by checking if a SOAP fault object is part of the error status (`ERROR-STATUS:ERROR-OBJECT-DETAIL` references it).

> 3. After displaying the basic SOAP fault information, `ErrorInfo` further verifies that there is SOAP fault detail information by checking if a SOAP fault-detail object is part of the SOAP fault object data (`hSOAPFault:SOAP-FAULT-DETAIL` references it) and displays any SOAP fault detail information that it references.

> Note also that the error processing in `ErrorInfo` is essentially identical to the error processing in the `TemperatureSample.p` procedure, which could be easily rewritten to call it.

Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095