Use the generated WSDL documentation to complete the standard steps
for consuming a SOAP web service which include the following:
Connects an ABL server object to the web service using the
CONNECT( ) method, specifying the location
of the WSDL file for run-time access and the name of a port type on the
server.
Creates a procedure object and associates it with the web service
using the RUN...SET syntax.
Invokes a web service operation using the RUN...IN syntax, passing in any necessary
parameters.
Handles any errors or return values.
Deletes the procedure object using DELETE PROCEDURE when it is no longer needed.
Unbinds the web service from the ABL server object using the
DISCONNECT( ) method when all processing is
complete.
Deletes the ABL server object using DELETE OBJECT when it is no longer needed.
This comments in this code identify an example of each step.
DEFINE VARIABLE hWebService AS HANDLE NO-UNDO.
DEFINE VARIABLE hMySampleWebServiceObj AS HANDLE NO-UNDO.
DEFINE VARIABLE iCustNum AS INTEGER NO-UNDO.
DEFINE VARIABLE result AS CHARACTER NO-UNDO.
DEFINE VARIABLE cName AS CHARACTER NO-UNDO.
iCustNum = 5000.
CREATE SERVER hWebService.
//Step 1
hWebService:CONNECT("-WSDL 'http://machinename:8810/MySampleApp/soap/wsdl?targetURI=urn:MySampleWebService'").
IF NOT hWebService:CONNECTED() THEN DO:
MESSAGE "SERVER: " SKIP "http://machinename:8810/MySampleApp/soap/wsdl?targetURI=urn:MySampleWebService" SKIP
"is not connected"
VIEW-AS ALERT-BOX INFO BUTTONS OK.
RETURN.
END.
// Step 2
RUN MySampleWebServiceObj SET hMySampleWebServiceObj ON hWebService.
IF NOT VALID-HANDLE(hMySampleWebServiceObj) THEN DO:
MESSAGE "PortType: " VALID-HANDLE(hMySampleWebServiceObj) " is not valid"
VIEW-AS ALERT-BOX INFO BUTTONS OK.
RETURN.
END.
// Step 3
RUN serviceInterface IN hMySampleWebServiceObj(INPUT iCustNum, OUTPUT result, OUTPUT cName).
// Step 4
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.
// Step 4 continued
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.
MESSAGE cName.
// Step 5
DELETE OBJECT hMySampleWebServiceObj.
// Step 6
hWebService:DISCONNECT().
// Step 7
DELETE OBJECT hWebService.
For more information on the methods and statements listed above see,
ABL Reference
Locate
details for code in the WSDL documentation
To build the ABL SOAP client
using code snippets generated by the WSDL Analyzer and available from the WSDL
documentation, perform the following steps:
Create an ABL procedure file.
Open the index.html file in
the WSDL documentation and click a link to a port type that you want to invoke.
This opens the port type documentation.
From the port type documentation, copy the example ABL code
snippet that defines connection parameters and paste it
into the ABL procedure file.
Locate the example code snippet that defines input and output variables and copy those definitions into your
procedure file.
From the same code snippet, copy and paste the line that runs the operation.
Assign values to input variables and add statements to process
the output. (See the statement that runs the operation—RUN serviceInterface in this example—to know which variables are
input and which ones are output).
Input variables must be
initialized before the operation is run. Statements to process the output
from the web service should be placed after the RUN statement.
At this point, your ABL procedure file should resemble this
example:
DEFINE VARIABLE hWebService AS HANDLE NO-UNDO.
DEFINE VARIABLE hMySampleWebServiceObj AS HANDLE NO-UNDO.
DEFINE VARIABLE iCustNum AS INTEGER NO-UNDO.
DEFINE VARIABLE result AS CHARACTER NO-UNDO.
DEFINE VARIABLE cName AS CHARACTER NO-UNDO.
iCustNum = 1.
CREATE SERVER hWebService.
hWebService:CONNECT("-WSDL 'http://machinename:8810/MySampleApp/soap/wsdl?targetURI=urn:MySampleWebService'").
RUN MySampleWebServiceObj SET hMySampleWebServiceObj ON hWebService.
RUN serviceInterface IN hMySampleWebServiceObj(INPUT iCustNum, OUTPUT result, OUTPUT cName).
MESSAGE cName.
You should now be able to test the web service by running the
procedure (CTRL+F11 in OpenEdge Developer Studio). Before you do so, you should
modify your code to adhere to good programming practices. Write code to handle
faults and other types of exceptions, delete the handles, and disconnect from
the web service as shown in the overview example.