Try OpenEdge Now
skip to main content
Web Services
Creating ABL Clients to Consume OpenEdge SOAP Web Services : Handling SOAP Message Headers in ABL : Creating and managing SOAP message headers : Using a client-created SOAP request header : Procedure to create a SOAP request header
 
Procedure to create a SOAP request header
This is the procedure (BuildRequestHeader) that creates the global SOAP request header that the client sends in all requests to the Web service:
Procedure to create a SOAP request header
/*1*/
PROCEDURE BuildRequestHeader:
  /* Define procedure parameter */
  DEFINE OUTPUT PARAMETER hHeader AS HANDLE.
  /*2*/
  DEFINE VARIABLE hHeaderEntryref AS HANDLE.
  DEFINE VARIABLE ClientNS AS CHARACTER
    INIT "http://ServiceHost/SOAPHeader".
  /*3*/
  /* Create SOAP header and server objects */
  CREATE SOAP-HEADER hHeader.
  CREATE SOAP-HEADER-ENTRYREF hHeaderEntryref.
  /*4*/
  /* Create x-doc objects to build header */
  CREATE X-DOCUMENT hXdoc.
  CREATE X-NODEREF hXAttribute.
  CREATE X-NODEREF hXnoderef1.
  CREATE X-NODEREF hXnoderef2.
  CREATE X-NODEREF hXtext.
  /*5*/
  /* Create the header entry */
  hHeader:ADD-HEADER-ENTRY(hHeaderEntryref).
/*6*/
  /* Create the header namespace data */
  hXdoc:CREATE-NODE-NAMESPACE(hXnoderef1, ClientNS, "AuthHeader",
                              "ELEMENT").
  hXdoc:CREATE-NODE-NAMESPACE(hXAttribute, "http://www.w3.org/2000/xmlns/",
                              "xmlns", "ATTRIBUTE").
 hXAttribute:NODE-VALUE = ClientNS.
  hXnoderef1:SET-ATTRIBUTE-NODE(hXAttribute).
  hXdoc:INSERT-BEFORE(hXnoderef1, ?).
  /*7*/
  /* Create the Username/Password data */
 hXdoc:CREATE-NODE-NAMESPACE(hXnoderef2, ClientNS, "UserName", "ELEMENT").
  hXnoderef1:APPEND-CHILD(hXnoderef2).
  hXdoc:CREATE-NODE(hXtext,"","text").
  hXnoderef2:APPEND-CHILD(hXtext).
 hXtext:NODE-VALUE = cUsername.
  /*8*/
 hXdoc:CREATE-NODE-NAMESPACE(hXnoderef2, ClientNS, "Password", "ELEMENT").
  hXnoderef1:APPEND-CHILD(hXnoderef2).
  hXdoc:CREATE-NODE(hXtext, "", "text").
  hXnoderef2:APPEND-CHILD(hXtext).
 hXtext:NODE-VALUE = cPassword.
  /*9*/
  /* Fill the header entry using a deep copy */
 hHeaderEntryref:SET-NODE(hXnoderef1).
  /*9*/
  /* Fill the header entry using a deep copy */
 hHeaderEntryref:SET-NODE(hXnoderef1).
  /*10*/
  /* Procedure/header cleanup */
 DELETE OBJECT hXdoc.
 DELETE OBJECT hXAttribute.
 DELETE OBJECT hXnoderef1.
 DELETE OBJECT hXnoderef2.
 DELETE OBJECT hXtext.
 DELETE OBJECT hHeaderEntryref.
END PROCEDURE.
The code in the preceding example:
1. Defines a single output parameter to return the global SOAP header object that it creates to the client mainline context
2. Defines a handle variable (hHeaderEntryref) to reference the SOAP header entryref object, and a variable (ClientNS) that specifies the namespace for the SOAP header entry that it creates
3. Creates the global SOAP header object that references the XML for the header using the CREATE SOAP-HEADER statement, and creates the SOAP header entryref object that references the XML for the header entry using the CREATE SOAP-HEADER-ENTRYREF statement
4. Creates the x-document and x-noderef objects required to build the XML to be added as the header entry for the global SOAP header
5. Adds a header entry to the newly created SOAP header object, referenced by the hHeaderEntryref object, using the ADD-HEADER-ENTRY( ) method
6. Creates the root node (<AuthHeader> element) for the header entry in the working x-document object
Note: The namespace attribute specifying http://www.w3.org/2000/xmlns/ is a requirement of the DOM. For more information, see the information on XML support in OpenEdge Development: Programming Interfaces.
7. Creates the <UserName> element as a child node of the header entry
8. Creates the <Password> element as a second child node of the header entry
9. Assigns the header entry in the global SOAP header object to the XML for the <AuthHeader> element of the x-document object using the SET-NODE( ) method
Note: You must call the ADD-HEADER-ENTRY() method before calling the SET-NODE() method to populate an entry. If you do not, you are essentially overwriting the XML of the same entry over and over.
10. Cleans up by deleting all the helper objects created in the procedure before returning to the client mainline