Application Development 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: 

Consume a web service with setting HTTP header

Former Member
0 Kudos

Hi

We are trying to consume an external web service from ABAP.

The web service requires authentication information set in HTTP header (not SOAP header) but we have no idea how to set HTTP header in ABAP.

Does anyone know how to do it?

Regards,

Kenji

4 REPLIES 4

Former Member
0 Kudos

Any idea?

0 Kudos

I have solved the issue myself.

The solution is the combination of client proxy and cl_http_client.

Using cl_http_client, you can easily set HTTP header to your SOAP request, while the generation of the SOAP message is much more complicated compared to client proxy.

On the other hand, the client proxy framework does not provide with a way to set HTTP header.

When I carefully looked into the automatically generated resources of the client proxy framework, I noticed client proxy contains XSLT that is responsible for the conversion between SOAP message and ABAP object.

You can find it by focusing the IMPORTING or EXPORTING message in the "External View" or "Internal View" tab and checking the "Show Stylesheets" checkbox on the right.

By utilizing these XSLT resources, you can easily convert ABAP objects whose type is automatically generated by the client ploxy framework to SOAP messages.

You can then set any HTTP header to the SOAP request and send it by cl_http_client.

Hope this helps someone.

Regards,

Kenji

0 Kudos

Hi Kenji,

i think i have the same issue, but i don't understand how you solved it.

i set up a web service from a remote-enabled function module. The webservice is fine: works correctly (tested by SoapUI free program)

I followed this guide to consume a web service via ABAP:

  data: lo_wsproxy  type ref to zwssumco_z_ws_sum,

        ls_response type zwssumz_ws_sumresponse,

        ls_request  type zwssumz_ws_sum.

  try.

      create object lo_wsproxy.

    catch cx_ai_system_fault.

      raise proxy_failed.

  endtry.

  ls_request-i_add1 = i_add1.

  ls_request-i_add2 = i_add2.

  try.

      call method lo_wsproxy->z_ws_sum

        exporting

          input  = ls_request

        importing

          output = ls_response.

    catch: cx_ai_system_fault cx_ai_application_fault .

      raise wscall_failed.

  endtry.

  commit work and wait.

  o_tot = ls_response-o_tot.

I try to call such a WS with the code above.

In dialog mode, no problem: a popup appears where yuo can insert userid and passwrd required by the WS.

But i need to call the WS during a background job execution.

How can i set user and password in the proxy client request, to skip the dialog popup ?

Thanks in advance

Best regards

Fabrizio Gemma

0 Kudos

Hi Kenji,

I have the same problem and I'm using a very similar code like fabrizzio's example.

Can you share the code that you used to add the custom http header?

Thanks in advance.