Skip to Content

Edit Service Consumer Header.

Hi, friends!
I have 2 service consumer: ZCO_LOGON and ZCO_RUN_JOB.
ZCO_LOGON generates and returns SessionID.
I need to put this SessionID in a header of ZCO_RUN_JOB.
But there's a problem: ZCO_RUN_JOB header generated automatically and I don't know how to put my SessionID there.
I've tried to do something like this, but it didn't solve my problem.
Maybe somebody can advise me something or show me my mistake.

DATA(lr_proxy_conn) = NEW zco_logon( ).

IF lr_proxy_conn IS BOUND.
  TRY .
      lr_proxy_conn->logon( EXPORTING input  = conn_input
                            IMPORTING output = conn_output ).
    CATCH cx_ai_system_fault.

  DATA: client_proxy TYPE REF TO zco_run_job,
        ws_header    TYPE REF TO if_wsprotocol_ws_header,
        system_fault TYPE REF TO cx_ai_system_fault,
        name         TYPE string,
        namespace    TYPE string.

  DATA: obj_ixml         TYPE REF TO if_ixml,
        obj_ixml_factory TYPE REF TO if_ixml_stream_factory,
        obj_ixml_ostream TYPE REF TO if_ixml_ostream,
        obj_ixml_istream TYPE REF TO if_ixml_istream,
        obj_parser       TYPE REF TO if_ixml_parser,
        w_error          TYPE i.

  DATA: xml_document TYPE REF TO if_ixml_document,
        xml_root     TYPE REF TO if_ixml_element,
        xml_element  TYPE REF TO if_ixml_element,
        xml_node     TYPE REF TO if_ixml_node.

  DATA: lw_cstring TYPE string,
        l_xstring  TYPE xstring,
        l_string   TYPE string.

  CREATE OBJECT client_proxy
      logical_port_name = 'ZLP_RUN_JOB'.

  ws_header ?= client_proxy->get_protocol( if_wsprotocol=>ws_header ).

  l_string = '<soapenv:Header>' &&
                '<ser:session>' &&
                  '<SessionID>' && |{ conn_output-session_id }| && '</SessionID>' &&
                '</ser:session>' &&

  IF NOT l_string IS INITIAL.

    obj_ixml         = cl_ixml=>create( ).
    obj_ixml_factory = obj_ixml->create_stream_factory( ).
    obj_ixml_istream = obj_ixml_factory->create_istream_string( l_string ).
    xml_document     = obj_ixml->create_document( ).
    obj_parser       = obj_ixml->create_parser(
                                    stream_factory = obj_ixml_factory
                                    istream        = obj_ixml_istream
                                    document       = xml_document ).

    w_error = obj_parser->parse( ).

    IF sy-subrc = 0 AND NOT xml_document IS INITIAL.

      xml_root = xml_document->get_root_element( ).
      xml_element ?= xml_root->get_first_child( ).

      WHILE NOT xml_element IS INITIAL.
        name = xml_element->get_name( ).
        namespace = xml_element->get_namespace_uri( ).
        ws_header->set_request_header( name = name namespace = namespace dom = xml_element ).
        xml_element ?= xml_element->get_next( ).

CHECK: client_proxy IS BOUND.

  TRY .
      client_proxy->run_job( EXPORTING input  = input
                             IMPORTING output = output ).
    CATCH cx_ai_system_fault.
Add a comment
10|10000 characters needed characters exceeded

Related questions

0 Answers

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.