Try OpenEdge Now
skip to main content
Web Services
Creating ABL Clients to Consume OpenEdge SOAP Web Services : Handling Errors in ABL Requests to OpenEdge SOAP Web Services : Examples of ABL accessing a SOAP fault : Asynchronous call error handling example
 
Asynchronous call error handling example
As mentioned in Results handling, class-based error objects returned from an asynchronous call are handled slightly differently:
1. Note that, in contrast to comment 2 in the Traditional error handling example, the code retrieves the error object from the ERROR-OBJECT attribute of the asynchronous call handle (hRequest).
2. The ERROR-OBJECT attribute returns a reference to an object that implements the Progress.Lang.Error interface. To access information beyond the attributes inherited from Progress.Lang.Error, the object referenced by myerr is cast to the more specific type of object returned, Progress.Lang.SoapFaultError.
3. Checks the numMessages property of soaperr (part of Progress.Lang.Error's implementation) and displays messages as necessary.
4. Uses the ABL VALID-HANDLE function to determine the SoapFault property of soaperr points to a valid Soap-Fault object handle. If so, the information in the handle's attributes is displayed.
5. Uses the ABL VALID-HANDLE function again to determine if the SOAP fault has SOAP fault detail by testing the validity of the handle returned by hSoapFault:SOAP-FAULT-DETAIL. If so, it assigns a reference to the handle to the variable SOAPFaultDetail.

Sample asychronous error procedure

DEFINE VARIABLE hWS AS HANDLE.
DEFINE VARIABLE hWebSrvc AS HANDLE NO-UNDO.
DEFINE VARIABLE hPortType AS HANDLE NO-UNDO.
DEFINE VARIABLE hSOAPFault AS HANDLE NO-UNDO.
DEFINE VARIABLE hSOAPFaultDetail AS HANDLE NO-UNDO.
DEFINE VARIABLE i AS INTEGER NO-UNDO.
DEFINE VARIABLE cResponse AS CHARACTER NO-UNDO.
DEFINE VARIABLE hRequest AS HANDLE NO-UNDO.

CREATE SERVER hWebSrvc.
hWebSrvc:CONNECT("-pf soap.pf").

RUN ErrorServiceSoap SET hPortType ON hWebSrvc.

/* Get a SOAP fault */
/* HelloWorld2 always throws an exception with detailed contents. */

RUN HelloWorld2 IN hPortType ASYNCHRONOUS SET hRequest
EVENT-PROCEDURE "procDone" IN THIS-PROCEDURE (OUTPUT cResponse).

WAIT-FOR PROCEDURE-COMPLETE OF hRequest.

DELETE OBJECT hRequest.
DELETE OBJECT hPortType.
hWebSrvc:DISCONNECT().
DELETE OBJECT hWebSrvc.

PROCEDURE procDone:
DEFINE INPUT PARAMETER cResponse AS CHARACTER.
DEFINE VARIABLE myerr AS Progress.Lang.Error.
DEFINE VARIABLE soaperr AS Progress.Lang.SoapFaultError.

IF hRequest:ERROR THEN DO:
MESSAGE "An error occurred when running HelloWorld2".

/*1*/
myerr = SELF:ERROR-OBJECT.
/*2*/
soaperr = CAST (myerr, Progress.Lang.SoapFaultError).

/*3*/
IF soaperr:NumMessages > 0 THEN DO:
DO i = 1 TO soaperr:NumMessages:
MESSAGE "SoapFault Error: " soaperr:GetMessage(i).
END.
/*4*/
IF VALID-HANDLE(soaperr:SoapFault) THEN DO:
MESSAGE "soaperr:SOAPFAULT is a valid handle".
hSOAPFault = soaperr:SoapFault.
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 SKIP.

/*5*/
IF VALID-HANDLE(hSOAPFault:SOAP-FAULT-DETAIL) THEN DO:
SOAPFaultDetail = hSOAPFault:SOAP-FAULT-DETAIL.
END.
END.
END.
END.
END PROCEDURE.