Try OpenEdge Now
skip to main content
Web Services
Creating ABL Clients to Consume OpenEdge SOAP Web Services : Invoking OpenEdge SOAP Web Service Operations from ABL : Managing complex data : Complex data example
 
Complex data example
The following examples show how you might manage a complex parameter, or any complex data, in this case, an OUTPUT parameter as serialized XML. This is a procedure that maps to a Web service operation, getAddress. Given a social security number (ssn), the operation returns an address (Address) as a complex type:

ABL prototype with a complex parameter accessed as serialized XML

PROCEDURE getAddress:
  DEFINE INPUT  PARAMETER ssn       AS CHARACTER.
  DEFINE OUTPUT PARAMETER cmAddress AS LONGCHAR.
END PROCEDURE.
This is the schema for a <complexType> element that returns the address information to the caller. It contains five string data type elements representing the components of the address:

Complex type in the WSDL

<complexType name="Address">
  <sequence>
    <element name="name" type="xsd:string">
    <element name="street" type="xsd:string">
    <element name="city" type="xsd:string">
    <element name="state" type="xsd:string">
    <element name="zip-code" type="xsd:string">
  </sequence>
</complexType>
This sample ABL procedure demonstrates how you can manage this complex type in ABL as a DOM tree. The variable to receive the parameter value, cmAddress, is defined as a LONGCHAR. After the Web service operation returns a value for cmAddress, the LOAD( ) method on the x-document handle, hXDoc, parses and loads the <complexType> element from cmAddress into the associated x-document object.
Because the schema of the complex type is known, the remaining x-document and x-noderef handle methods simply retrieve the root node from the "Address" DOM tree, and pick off the component value (text element) for each of the five component nodes that comprise the complex type, in order, assigning them to the corresponding fields of a database record.
This is the ABL example for handling the parameter as a DOM tree:

Complex type managed in ABL as a DOM tree

DEFINE VARIABLE hWS           AS HANDLE.
DEFINE VARIABLE hAddrPortType AS HANDLE.
DEFINE VARIABLE cmAddress     AS LONGCHAR.

CREATE SERVER hWS.

hWS:CONNECT ("-WSDL http://www.zzzcompany.org/ssn.wsdl
              -Service addressSVC
              -Port addressPort").

RUN addressPortType SET hAddrPortType ON SERVER hWS.

RUN getAddress IN hAddrPortType (INPUT "555-55-5555", OUTPUT cmAddress).

DEFINE VARIABLE hXDoc  as HANDLE.
DEFINE VARIABLE hXRoot as HANDLE.
DEFINE VARIABLE hXNode as HANDLE.
DEFINE VARIABLE hXText as HANDLE.

CREATE X-DOCUMENT hXDoc.
CREATE X-NODEREF  hXRoot.
CREATE X-NODEREF  hXNode.
CREATE X-NODEREF  hXText.

hXDoc:LOAD("LONGCHAR", cmAddress, FALSE).

hXDoc:GET-DOCUMENT-ELEMENT(hXRoot).

/* because we know the content, we are just moving straight ahead
   and getting each one of the nodes under the root, then getting its
   TEXT node to get the data we're interested in. */
hXRoot:GET-CHILD(hXNode, 1).
hXNode:GET-CHILD(hXText, 1).

/* let's assume we have a DB table with the appropriate fields */
myTable.name = hXText:NODE-VALUE.

/* ... */
hXRoot:GET-CHILD(hXNode, 5).
hXNode:GET-CHILD(hXText, 1).
myTable.zip-code = hXText:NODE-VALUE.

/* clean up */
/* ...      */

hWS:DISCONNECT( ).