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 : Reusing an unchanged SOAP response header
 
Reusing an unchanged SOAP response header
This example shows how you might handle a SOAP header that you first encounter in the response message returned from the Web service, then use unchanged as the SOAP header for the next request. This is an example of the header returned from the Web service:

SOAP response header to be reused

<soap:Envelope>
  . . .    <soap:Header>
      <AuthHeader xmlns="http://ServiceHost/SOAPHeader">
        <AccessID>XYZZY</AccessID>
      </AuthHeader>
    </soap:Header>
  . . .
</soap:Envelope >
It contains one header entry, AuthHeader, that contains a value used as an access key (AccessID). This type of header might be used when the Web service and client maintain a consistent context for each other between requests.
This is the mainline of a procedure that invokes the Web service to reuse the response header:

Invoking a request that reuses an unchanged SOAP response header

/* SOAPHeader1.p
 * Calls a fictitious Web service, first to request access, which gets back
 * a SOAP response header containing an AccessID, and sends the response
 * header back as part of a new request using the required access
 * credential that allows the Web service to respond appropriately to
 * the follow-up request.
 * 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 cResponse   AS CHARACTER FORMAT "x(72)".
DEFINE VARIABLE g_header    AS HANDLE.

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

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

/* Get the method, set the port type */
RUN HeadersSoap SET hPortType ON hWebSrvc.
/*2*/
/* Associate the req. & resp. callbacks with the port type */
hPortType:SET-CALLBACK-PROCEDURE("REQUEST-HEADER", "ReqHandler").
hPortType:SET-CALLBACK-PROCEDURE("RESPONSE-HEADER", "RespHandler").
/*3*/
/* Invoke the Web service with no header and display the results */
RUN OpenAccess IN hPortType (OUTPUT cResponse).
DISPLAY cResponse LABEL "WS response" WITH FRAME aaa.
/*4*/
/* Go again with the AccessID set from previous response header */
cResponse = "".
RUN HelloWorld IN hPortType (OUTPUT cResponse).
DISPLAY cResponse LABEL "WS response" WITH FRAME bbb.
/*5*/
DELETE OBJECT g_header.
DELETE OBJECT hPortType.
hWebSrvc:DISCONNECT().
DELETE OBJECT hWebSrvc.
/**************** Internal Procedures ****************/
The code in the preceding example:
1. Defines several mainline variables, including a global handle to reference the reused SOAP header (g_header).
2. Registers the request header (ReqHandler) and response header (RespHandler) handlers after connecting to the Web service and instantiating the HeaderSoap port type procedure object.
3. Runs the OpenAccess procedure to invoke the Web service operation that returns the AccessID value in the SOAP response header (see Response header handler for returning a header for reuse).
4. Runs the HelloWorld procedure to invoke the next Web service operation, passing back the SOAP response header to the Web service unchanged as the SOAP request header (see Request header handler for reusing a header).
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 original SOAP response header saved by the response header handler during execution of the OpenAccess procedure.
* Response header handler for returning a header for reuse
* Request header handler for reusing a header