OpenEdge 10 has native ABL support for Web Services. In order to access a Web Service via ABL, you will need to follow these general steps:
- Use the WSDL Analyzer to provide HTML documentation on the interface that the WSDL describes. This documentation includes 4GL sample code to use.
- Based on the documentation of the WSDL Analyzer develop your 4GL application which accesses the Web Service.
Note: For in-depth information on how to access a Web Service through ABL, please refer to the "OpenEdge Development: Web Services" documentation.For a quick overview on how to connect to a Web Service, please take a look at the following sample ABL code which retrieves the latest stock quote of a stock ticker. This Web Service is available at http://www.webservicex.net/stockquote.asmx
and uses Document/Literal as the WSDL's Style/Use.Note: Please use these steps as guidelines to access a Web Service. Publicly available Web Services can be found at http://www.webservicex.net/
.
- Run the WSDL Analyzer within a Proenv window: bprowsdldoc http://www.webservicex.net/stockquote.asmx?WSDL DOC
- Open the index.html document inside the DOC directory which is created by the WSDL Analyzer.
- By clicking on a link in the Port types section you will get to the documentation which explains how to access this Web Service via 4GL. (For this example, there is only a StockQuoteSoap Port type)
- On the page for a specific Port type, the connection details will contain code samples on how to connect to this specific service. The Operation (internal procedure) detail section documents the ABL signatures for the operations provided by the WebService.
- By using this generated documentation you will be able to create an ABL application, e.g.:
Note: The Wrapped Document/Literal calling convention is supported since OpenEdge 10.1A. The sample code below is based on this convention.
DEFINE VARIABLE hWebService AS HANDLE NO-UNDO.
DEFINE VARIABLE hStockQuoteSoap AS HANDLE NO-UNDO.
DEFINE VARIABLE symbol AS CHARACTER NO-UNDO.
DEFINE VARIABLE GetQuoteResult AS CHARACTER NO-UNDO.
/* Set up a proxy for the service interface. This uses the Port Type name */
CREATE SERVER hWebService.
hWebService:CONNECT("-WSDL 'http://www.webservicex.net/stockquote.asmx?WSDL'").
IF NOT hWebService:CONNECTED() THEN DO:
MESSAGE "SERVER: " SKIP "http://www.webservicex.net/stockquote.asmx?WSDL" SKIP
"is not connected"
VIEW-AS ALERT-BOX INFO BUTTONS OK.
RETURN.
END.
/* use the Port type name here to create proxy and set a handle to it */
RUN StockQuoteSoap SET hStockQuoteSoap ON hWebService.
IF NOT VALID-HANDLE(hStockQuoteSoap) THEN DO:
MESSAGE "PortType: " VALID-HANDLE(hStockQuoteSoap) " is not valid"
VIEW-AS ALERT-BOX INFO BUTTONS OK.
RETURN.
END.
/* Use the operation name here, and invoke it in the proxy handle */
symbol = "PRGS".
RUN GetQuote IN hStockQuoteSoap(INPUT symbol, OUTPUT GetQuoteResult).
/* Handle errors that could occur, including reading any SOAP faults returned by the WebService */
IF ERROR-STATUS:ERROR THEN DO:
DEFINE VARIABLE iCnt AS INTEGER NO-UNDO.
DO iCnt = 1 TO ERROR-STATUS:NUM-MESSAGES:
MESSAGE ERROR-STATUS:GET-MESSAGE(iCnt)
VIEW-AS ALERT-BOX INFO BUTTONS OK.
END.
IF VALID-HANDLE(ERROR-STATUS:ERROR-OBJECT-DETAIL) THEN DO:
DEFINE VARIABLE hXML AS HANDLE NO-UNDO.
DEFINE VARIABLE mDoc AS MEMPTR NO-UNDO.
CREATE X-DOCUMENT hXML.
hXML:LOAD('LONGCHAR', ERROR-STATUS:ERROR-OBJECT-DETAIL:SOAP-FAULT-DETAIL:GET-SERIALIZED(), FALSE).
hXML:SAVE("memptr", mDoc).
MESSAGE "Fault Code : " ERROR-STATUS:ERROR-OBJECT-DETAIL:SOAP-FAULT-CODE SKIP
"Fault String: " ERROR-STATUS:ERROR-OBJECT-DETAIL:SOAP-FAULT-STRING SKIP
"Fault Actor : " ERROR-STATUS:ERROR-OBJECT-DETAIL:SOAP-FAULT-ACTOR SKIP
"Error Type : " ERROR-STATUS:ERROR-OBJECT-DETAIL:TYPE SKIP SKIP
"Fault Detail: " SKIP GET-STRING(mDoc,1)
VIEW-AS ALERT-BOX INFO BUTTONS OK.
END.
END.
/* Show the XML respose. In real-life application, one would parse it and process the data here */
MESSAGE GetQuoteResult
VIEW-AS ALERT-BOX INFO BUTTONS OK.
/* clean up: delete any proxies, then disconnect & delete the service object */
DELETE OBJECT hStockQuoteSoap.
hWebService:DISCONNECT().
DELETE OBJECT hWebService.