Quantcast
Channel: SCN: Message List - Service-Oriented Architecture (SOA) and SAP
Viewing all articles
Browse latest Browse all 1056

Re: Call Webservice from inside an ABAP program

$
0
0

Hi Ayan, I've just found my sample program which I created some years ago (converting measures with www.webservicex.net):

REPORT z_re_call_webservice.

 

 

PARAMETERS: p_source(50)TYPE c DEFAULT'Meters' LOWER CASE,

            p_dest(50)TYPE c DEFAULT'Yards' LOWER CASE,

            p_value(50)TYPE c DEFAULT'50',

            p_uname(50)  TYPE c          " Username Proxy

            p_pw(50)TYPE c LOWER CASE.  " Password Proxy

 

DATA: gv_uname_proxy TYPE string,

      gv_pw_proxy TYPE string,

      gv_subrc TYPE sy-subrc,

      gv_errortext TYPE string.

 

DATA: http_client TYPEREFTO if_http_client .

 

DATA: w_string TYPE string ,  " Input

      w_result TYPE string ,  " Output

      r_str    TYPE string .

 

DATA: result_tab TYPETABLEOF string.

 

 

DATA : html_content TYPE w3htmltabtype,

      generated_url TYPE char1024,

      html_line TYPE w3html.

 

START-OF-SELECTION.

 

* Passing parameters with HTTP GET (Is SOAP also possible???)

  CONCATENATE

    'http://www.webservicex.net/length.asmx'

    '/ChangeLengthUnit?LengthValue=' p_value

    '&fromLengthUnit=' p_source

    '&toLengthUnit=' p_dest

  INTO w_string.

 

* Create HTTP-Client-Objekt

  CALLMETHOD cl_http_client=>create_by_url

    EXPORTING

      proxy_host        = '00.000.0.000'

      proxy_service    = '8080'

      url              = w_string

    IMPORTING

      client            = http_client

    EXCEPTIONS

      argument_not_found = 1

      plugin_not_active = 2

      internal_error    = 3

      OTHERS            = 4.

 

  IF sy-subrc <>0.

    MESSAGE'Error creating client'TYPE'E'.

  ENDIF.

 

 

* Proxy login

  gv_uname_proxy = p_uname.

  gv_pw_proxy = p_pw.

 

  CALLMETHOD http_client->authenticate

    EXPORTING

      proxy_authentication = 'X'

      username            = gv_uname_proxy

      password            = gv_pw_proxy.

 

* Send

  CALLMETHOD http_client->send

    EXCEPTIONS

      http_communication_failure = 1

      http_invalid_state        = 2.

 

  IF sy-subrc <>0.

 

    CALLMETHOD http_client->get_last_error(

      IMPORTING

        code  = gv_subrc

        MESSAGE = gv_errortext ).

 

    WRITE: / 'communication_error( send )',

 

          / 'code: ', gv_subrc,'message: ', gv_errortext.

 

    EXIT.

 

  ENDIF.

 

* Receive Result

  CALLMETHOD http_client->receive

    EXCEPTIONS

      http_communication_failure = 1

      http_invalid_state        = 2

      http_processing_failed    = 3.

 

  IF sy-subrc <>0.

 

    CALLMETHOD http_client->get_last_error(

      IMPORTING

        code  = gv_subrc

        MESSAGE = gv_errortext ).

 

    WRITE: / 'communication_error( receive )',

 

          / 'code: ', gv_subrc,'message: ', gv_errortext.

 

    EXIT.

 

  ENDIF.

 

  CLEAR w_result .

 

* Result to string

  w_result = http_client->response->get_cdata().

 

* Disconnect

  CALLMETHOD http_client->close

    EXCEPTIONS

      http_invalid_state = 1

      OTHERS            = 2.


Viewing all articles
Browse latest Browse all 1056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>