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
 
Using a client-created SOAP request header
This example shows how you might create a SOAP header internally to use as an initial SOAP request header, as opposed to recycling a header previously received in a SOAP response message (described in previous examples). This is an example of the header created by the client for the Web service:

SOAP request header created entirely by the client

<SOAP-ENV:Envelope
  . . .
    <SOAP-ENV:Header>
      <ns0:AuthHeader xmlns:ns0="http://ServiceHost/SOAPHeader">
        <ns0:UserName>Scott</ns0:UserName>
        <ns0:Password>Administrator</ns0:Password>
      </ns0:AuthHeader>
    </SOAP-ENV:Header>
  . . .
</SOAP-ENV:Envelope>
The client creates a header very similar to the headers described in the previous examples. The <UserName> and <Password> elements, in this case, provide user authentication for each Web service request. The Web service requires this authentication for every Web service request.
The following code is the mainline of a procedure that invokes the Web service to create the initial SOAP request header containing a username and password node. This code:
1. Defines several mainline variables, including handles to access the global SOAP header (g_header) created for requests and its XML, and variables to hold the username (cUsername) and password (cPassword) values.
2. Builds the global request header used for all requests (see Procedure to create a SOAP request header).
3. Registers the request header (ReqHandler) handler after connecting to the Web service and instantiating the HeaderSoap port type procedure object.
4. Runs the HelloMyWorld procedure to invoke a Web service operation, passing back the global SOAP request header created by the client (see Request header handler for passing a globally-created header object).
5. Cleans up the global objects maintained in its context and disconnects from the Web service. Note that one of the objects it deletes is the global SOAP request header create by the client.

Invoking a request that creates a SOAP request header on the client

/* SOAPHeader3.p
  Calls a ficticious web service, passes it a username and password through
  a SOAP message request header, and gets back a string. The Web service has
  only one service and port available. */

/*1*/
/* Define local variables */
DEFINE VARIABLE hWebSrvc      AS HANDLE.
DEFINE VARIABLE hPortType     AS HANDLE.
DEFINE VARIABLE cUsername     AS CHARACTER INIT "Scott".
DEFINE VARIABLE cPassword     AS CHARACTER INIT "Administrator" .
DEFINE VARIABLE cResponse     AS CHARACTER FORMAT "x(72)".
DEFINE VARIABLE hXdoc         AS HANDLE.
DEFINE VARIABLE hXnoderef1    AS HANDLE.
DEFINE VARIABLE hXnoderef2    AS HANDLE.
DEFINE VARIABLE hXAttribute   AS HANDLE.
DEFINE VARIABLE hXtext        AS HANDLE.
DEFINE VARIABLE g_header      AS HANDLE.
/*2*/
/* Build global SOAP request header */
RUN BuildRequestHeader (OUTPUT g_header).

/* Create the Web service server object */
CREATE SERVER hWebSrvc.

/* Connect to the WS */
hWebSrvc:CONNECT("-WSDL
                   http://ServiceHost/SOAPHeader/HeaderExample.asmx?wsdl").

/* Get the method, set the port type */
RUN HeaderSoap SET hPortType ON hWebSrvc.
/*3*/
/* Associate the request callback with the port type */
hPortType:SET-CALLBACK-PROCEDURE("REQUEST-HEADER", "ReqHandler").
/*4*/
/* Invoke the web service and display the results */
RUN HellowMyWorld IN hPortType (OUTPUT cResponse).
DISPLAY cResponse LABEL "WS Response" WITH FRAME aaa.
/*5*/
DELETE OBJECT g_header.
DELETE OBJECT hPortType.
hWebSrvc:DISCONNECT().
DELETE OBJECT hWebSrvc.

/**************** Internal Procedures ****************/
* Procedure to create a SOAP request header
* Request header handler for passing a globally-created header object