Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

HTTP header - SOAP Webservice

Former Member
16,620

Hi to all,

I need to insert http parameter to consumer proxy (SOAP).

With SOAP UI is possibile insert value into header tab.

I know that to REST webservice is used cl_http_client class to insert http value.

Anyone know how i can insert http header value with SOAP web service?

Regards

Giuseppe

1 ACCEPTED SOLUTION
Read only

Sandra_Rossi
Active Contributor
0 Likes
12,418

After you instantiate the proxy class, you may add custom header fields via the methods GET_PROTOCOL and SET_SEND_HEADER_FIELDS as follows, before calling the Web Service:

DATA(transport) = CAST IF_WSPROTOCOL_TRANSPORT( proxy->GET_PROTOCOL( IF_WSPROTOCOL=>TRANSPORT ) ).
transport->set_send_header_fields( value #(
    ( name = 'Authorization' value = 'Bearer 81908CB' ) ) ).

Standard header fields are automatically added by the SAP standard (Content-Type, Accept, SOAPAction, etc.)

15 REPLIES 15
Read only

Sandra_Rossi
Active Contributor
0 Likes
12,419

After you instantiate the proxy class, you may add custom header fields via the methods GET_PROTOCOL and SET_SEND_HEADER_FIELDS as follows, before calling the Web Service:

DATA(transport) = CAST IF_WSPROTOCOL_TRANSPORT( proxy->GET_PROTOCOL( IF_WSPROTOCOL=>TRANSPORT ) ).
transport->set_send_header_fields( value #(
    ( name = 'Authorization' value = 'Bearer 81908CB' ) ) ).

Standard header fields are automatically added by the SAP standard (Content-Type, Accept, SOAPAction, etc.)

Read only

0 Likes
12,418
Manciagli Giuseppe My release is ABAP 7.52. I guess you use a lower version (which one?)If you don't have IF_WSPROTOCOL_TRANSPORT, it means that you simply can't use this feature.For information, in 7.52, the preparation of the HTTP request is implemented in class CL_SOAP_HTTP_TPBND_ROOT, method IF_SOAP_TRANSPORT_BINDING~SEND, which comprises the generation of HTTP headers (call of method SET_HTTP_HEADERS, which in turn calls the method SET_CUSTOM_HTTP_HEADERS).I guess that your version has only the method SET_HTTP_HEADERS, not SET_CUSTOM_HTTP_HEADERS.But you may implement your own logic via the Enhancement Framework.
Read only

0 Likes
12,418

Manciagli Giuseppe Can you tell the future visitors how you solved? (especially, if you added HTTP headers, how you did it) Thanks.

Read only

Former Member
0 Likes
12,418

Hi Sandra, thanks for the reply.

In the IF_WSPROTOCOL interface I see only these protocols:
'IF_WSPROTOCOL_ASYNC_MESSAGING'
'IF_WSPROTOCOL_ROUTING'
'IF_WSPROTOCOL_ATTACHMENTS'
'IF_WSPROTOCOL_XI_HEADER'
'IF_WSPROTOCOL_WS_HEADER'
'IF_WSPROTOCOL_PAYLOAD'
'IF_WSPROTOCOL_MESSAGE_ID'
'IF_WSPROTOCOL_SESSION'
'IF_WSPROTOCOL_SEQUENCE'
'IF_WSPROTOCOL_SAP_ADDRESSING'
'IF_WSPROTOCOL_LUW_CONTROL'
'IF_WSPROTOCOL_CONNECTIVITY'
'IF_WSPROTOCOL_IBC

The only one that contains a method similar to the one you posted is the 'IF_WSPROTOCOL_WS_HEADER' but it is used to change the soap heade

I'm interested in changing the http header like SOAP UI in this way. Is there anything I didn't get?

Regard

Giuseppe

Read only

0 Likes
12,418

Please refer to my comment attached to my previous answer.

Read only

0 Likes
7,301

Hi @Sandra_Rossi, I am referring the same code as yours but I am not able to see the custom http headers fields in integration suite. I am using SOAP based consumer web service. Is there any config. blocking the custom http header in SOAManager setting?

Read only

0 Likes
7,292

I don't know. You'd better start a new thread.

Read only

ArthurParisius
Contributor
0 Likes
12,418

As an alternative, you could look at this link Consume SOAP Webservice and add custom Header

Read only

0 Likes
12,418

I think it refers to the SOAP header, not to the HTTP header.

Read only

12,418

I thought it was about the HTTP header because in the comments it indicates that in SOAMANAGER the transport protocol is set to Transfer via HTTP Header.

Read only

caner_genis
Explorer
12,418

Hi all,

We have faced the same problem. Our release is 7.50 so IF_WSPROTOCOL_TRANSPORT doesn't exist. It has been solved with the following steps:

  1. Create Z-class to set and get SOAP HTTP header parameters.
  2. Create two private-static attributes (field and value).
  3. Create two public-static methods (SET_HTTP_HEADERS, GET_HTTP_HEADERS).
  4. Implement the methods.
  5. Call Zclass=>SET_HTTP_HEADERS in your code before calling the proxy method.
  6. Create an enhancement implementation in the method CL_SOAP_HTTP_TPBND_ROOT=>SET_HTTP_HEADERS.
  7. Call Zclass=>GET_HTTP_HEADERS in the enhancement and IF_HTTP_ENTITY=>set_header_field, like the code below:
ENHANCEMENT 1  Z_SOAP_SET_HTTP_HEADERS.    "active version
  
  zcl_enh=>get_http_headers( IMPORTING ev_name  = DATA(lv_name)
                                       ev_value = DATA(lv_value) ).

  IF lv_name IS NOT INITIAL.
    entity->set_header_field( name  = lv_name
                              value = lv_value ).

  ENDIF.
ENDENHANCEMENT.

Hope it helps future visitors.

Regard,

Caner.

Read only

0 Likes
12,418

Hi Caner,

We are facing the same problem too. Has your issue been solved with the steps you've explained? If so, what is the code you've used to implement Zclass=>SET_HTTP_HEADERS & Zclass=>GET_HTTP_HEADERS?

Read only

12,418

Hi Nikhila,

Yes these steps are working well in our end. You should create setter and getter method for two private-static attributes (field and value) created in the step 2.

class ZCL_ENH definition
  public
  final
  create public .

public section.
  class-methods SET_HTTP_HEADERS
    importing
      !IV_NAME type STRING
      !IV_VALUE type STRING .
  class-methods GET_HTTP_HEADERS
    exporting
      !EV_NAME type STRING
      !EV_VALUE type STRING .
protected section.
private section.

  class-data FIELDNAME type STRING .
  class-data FIELDVALUE type STRING .
ENDCLASS.

CLASS ZCL_ENH IMPLEMENTATION.

* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_ENH=>GET_HTTP_HEADERS
* +-------------------------------------------------------------------------------------------------+
* | [<---] EV_NAME                        TYPE        STRING
* | [<---] EV_VALUE                       TYPE        STRING
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD get_http_headers.
  ev_name  = fieldname.
  ev_value = fieldvalue.

ENDMETHOD.

* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_ENH=>SET_HTTP_HEADERS
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_NAME                        TYPE        STRING
* | [--->] IV_VALUE                       TYPE        STRING
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD set_http_headers.
  fieldname  = iv_name.
  fieldvalue = iv_value.

ENDMETHOD.
ENDCLASS.

Regard,

Caner.

Read only

johan_kneubuhler
Newcomer
0 Likes
12,418

Hi Giuseppe,

Did you can put the Authorization HTTP Header instead of SOAP Header?

Regards.

Read only

0 Likes
12,418

Please use the COMMENT button for comments, asking for complements, adding details, replying to a comment or a proposed solution or to the OP question, etc., ANSWER is only to propose a solution, dixit SAP text at the right of the answer area.