Once the web service is deployed to an ABL web application in a running instance
of PAS for OpenEdge, you can test it using an external application like SOAP UI or by
creating an ABL SOAP client. This topic describes how to test a SOAP web service by
creating an ABL SOAP client.
To create an ABL SOAP client, you use a utility called bprowsdldoc, which is also referred to as the WSDL
Analyzer. This utility reads a WSDL document and generates documentation that
includes sample ABL code snippets that you can copy and modify as you develop an ABL
SOAP client.
Steps to test a web service using an ABL SOAP
client
Perform the following steps to create an ABL SOAP client for
testing:
Run the WSDL Analyzer.
Examine the generated WSDL documentation.
Use the sample code snippets to develop an ABL SOAP client.
Step 1—Run the WSDL Analyzer
Perform the following steps to run the
WSDL Analyzer:
Launch Proenv.
Enter bprowsdldoc, followed by:
The location of the WSDL file (if the WSDL file is stored locally) or
the URL of the WSDL
An output directory where the WSDL documentation is generated
The WSDL documentation is generated as HTML files in the output
directory. Open the index.html file. This file is the
starting point of the WSDL documentation and contains links to documentation for port
types, data types, and other configurations.
A port type defines a
group of operations that you can execute on the web service. A data type defines the
XML schema for request, response, or fault messages.
Step 3—Use sample code snippets to develop an ABL
SOAP client
To build the ABL SOAP client using code snippets from the WSDL
documentation, perform the following steps:
Create an ABL procedure file called client.p.
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
client.p.
Locate the example code snippet that defines input and
output variables and copy those definitions into
client.p.
From the same code snippet, copy and paste the line that runs the operation into client.p.
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, the client.p file should
resemble this example:
// client.p
// Created by copying snippets from the port type documentation.
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.
/*Select a customer by number */
iCustNum = 1.
CREATE SERVER hWebService.
hWebService:CONNECT("-WSDL 'http://localhost:8810/MySampleApp/soap/wsdl?targetURI=urn:MySampleWebService'").
// Runs Port Types
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. To help you in this task, a
complete code sample is provided next.
Complete code sample
The following code
sample is an example of a functioning ABL SOAP client.
//client.p
//Includes good programming practices
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://localhost:8810/MySampleApp/soap/wsdl?targetURI=urn:MySampleWebService'").
// Handles connection error
IF NOT hWebService:CONNECTED() THEN DO:
MESSAGE "SERVER: " SKIP "http://localhost:8810/MySampleApp/soap/wsdl?targetURI=urn:MySampleWebService" SKIP
"is not connected"
VIEW-AS ALERT-BOX INFO BUTTONS OK.
RETURN.
END.
RUN MySampleWebServiceObj SET hMySampleWebServiceObj ON hWebService.
// Handles invalid PortType
IF NOT VALID-HANDLE(hMySampleWebServiceObj) THEN DO:
MESSAGE "PortType: " VALID-HANDLE(hMySampleWebServiceObj) " is not valid"
VIEW-AS ALERT-BOX INFO BUTTONS OK.
RETURN.
END.
RUN serviceInterface IN hMySampleWebServiceObj(INPUT iCustNum, OUTPUT result, OUTPUT cName).
// Handles errors
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.
// Provides details of errors
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.
// Disconnects and deletes objects
DELETE OBJECT hMySampleWebServiceObj.
hWebService:DISCONNECT().
DELETE OBJECT hWebService.