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

Calling Web Service from Function Module

Former Member
0 Likes
1,628

dear all

i am new to SAP.

i have a web Service developed with .net and C#.

i want to call this web Service from inside a function module.

how can i do this ?

thanks,

1 REPLY 1
Read only

Former Member
0 Likes
613

Hi Ramzy,

Please browse through chrome or sdn , there is a lot of documents and discussions, any how find the below URL, which might be helpful.

Create a Function Module and full the below Code :

Sample code :

DATA: http_client TYPE REF TO if_http_client,

      host_str TYPE string VALUE 'www.myservice.in',

      service_str TYPE string,

      path TYPE string VALUE  'my path',

      errortext TYPE string. "used for error handling

DATA  : wf_string1 TYPE string,

         lw_inputs TYPE string,

         error_text type string,

         subrc TYPE SY-SUBRC,

         lw_outputs TYPE  string.

CALL METHOD cl_http_client=>create_by_url

  EXPORTING

    url                = 'myurl'

  IMPORTING

    client             = http_client

  EXCEPTIONS

    argument_not_found = 1

    plugin_not_active  = 2

    internal_error     = 3

    OTHERS             = 4.

  IF sy-subrc <> 0.

*  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

*             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

CALL METHOD http_client->request->set_header_field

  EXPORTING

    name  = '~request_method'

    value = 'POST'.

CALL METHOD http_client->request->set_header_field

  EXPORTING

    name  = '~server_protocol'

    value = 'HTTP/1.1'.

CALL METHOD http_client->request->set_header_field

  EXPORTING

    name  = '~request_uri'

    value = 'mypath'.

CALL METHOD http_client->request->set_header_field

  EXPORTING

    name  = 'Content-Type'

    value = 'application/soap+xml; charset=utf-8'."'text/xml; charset=utf-8'.

CALL METHOD http_client->request->set_header_field

  EXPORTING

    name  = 'Content-Length'

    value = '19000'."txlen.

CALL METHOD http_client->request->set_header_field

  EXPORTING

    name  = 'SOAPAction'

    value = 'myURL'.

concatenate 'data u need sned' into wf_string

CALL METHOD http_client->request->set_cdata

  EXPORTING

    data   = wf_string1

    offset = 0

    length = '19000'.

Regards,

Lokeswar.