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: 

Call to WS from one backend to other backend

Former Member
0 Kudos

Hi All,

I created web service in one back-end e.g. DEV1 and i want to call him from other back-end DEV2.

How can i do that ?

Best Regards

Nina

Edited by: Nina C on May 4, 2009 12:53 PM

1 ACCEPTED SOLUTION

former_member189059
Active Contributor
0 Kudos

Hello,

You can modify this program to call your webservice

you will need to change the url to the url of your webservice

the url can be reached by deploying the webservice from transaction wsadmin

also make sure that host file entries are present if needed

*&---------------------------------------------------------------------*
*& Report  ZKRIS_SENDSMS
*&
*&---------------------------------------------------------------------*
*& Author : /people/durairaj.athavanraja/blog/2005/07/12/send-sms-to-india-from-abap
*& Date   : 16-06-2008
*& Purpose: Send SMS to BPL mobile in bombay
*&---------------------------------------------------------------------*
*& Date Changed by Tag Description
*&
*&---------------------------------------------------------------------*

REPORT  ZKRIS_SENDSMS.

DATA: http_client TYPE REF TO if_http_client .
DATA: wf_string TYPE string ,
result TYPE string ,
r_str TYPE string .
DATA: result_tab TYPE TABLE OF string.

SELECTION-SCREEN: BEGIN OF BLOCK a WITH FRAME .
PARAMETERS: mail(100) LOWER CASE,
 m_no(20) LOWER CASE ,
m_mss(120) LOWER CASE.
SELECTION-SCREEN: END OF BLOCK a .

START-OF-SELECTION .
  CLEAR wf_string .
  CONCATENATE
  'http://www.webservicex.net/SendSMS.asmx/SendSMSToIndia?MobileNumber='
  m_no
  '&FromEmailAddress='
  mail
 '&Message='
  m_mss
 INTO
  wf_string .

  CALL METHOD cl_http_client=>create_by_url
    EXPORTING
      url                = wf_string
    IMPORTING
      client             = http_client
    EXCEPTIONS
      argument_not_found = 1
      plugin_not_active  = 2
      internal_error     = 3
      OTHERS             = 4.

  CALL METHOD http_client->send
    EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state         = 2.

  CALL METHOD http_client->receive
    EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state         = 2
      http_processing_failed     = 3.
  CLEAR result .
  result = http_client->response->get_cdata( ).

  REFRESH result_tab .
  SPLIT result AT cl_abap_char_utilities=>cr_lf INTO TABLE result_tab .
  LOOP AT result_tab INTO r_str.
    WRITE:/ r_str .
  ENDLOOP .

12 REPLIES 12

Former Member
0 Kudos

HI All ,

Any Idea, i am stuck?

Regards

Nina

Edited by: Nina C on May 4, 2009 2:00 PM

former_member189059
Active Contributor
0 Kudos

Hello,

You can modify this program to call your webservice

you will need to change the url to the url of your webservice

the url can be reached by deploying the webservice from transaction wsadmin

also make sure that host file entries are present if needed

*&---------------------------------------------------------------------*
*& Report  ZKRIS_SENDSMS
*&
*&---------------------------------------------------------------------*
*& Author : /people/durairaj.athavanraja/blog/2005/07/12/send-sms-to-india-from-abap
*& Date   : 16-06-2008
*& Purpose: Send SMS to BPL mobile in bombay
*&---------------------------------------------------------------------*
*& Date Changed by Tag Description
*&
*&---------------------------------------------------------------------*

REPORT  ZKRIS_SENDSMS.

DATA: http_client TYPE REF TO if_http_client .
DATA: wf_string TYPE string ,
result TYPE string ,
r_str TYPE string .
DATA: result_tab TYPE TABLE OF string.

SELECTION-SCREEN: BEGIN OF BLOCK a WITH FRAME .
PARAMETERS: mail(100) LOWER CASE,
 m_no(20) LOWER CASE ,
m_mss(120) LOWER CASE.
SELECTION-SCREEN: END OF BLOCK a .

START-OF-SELECTION .
  CLEAR wf_string .
  CONCATENATE
  'http://www.webservicex.net/SendSMS.asmx/SendSMSToIndia?MobileNumber='
  m_no
  '&FromEmailAddress='
  mail
 '&Message='
  m_mss
 INTO
  wf_string .

  CALL METHOD cl_http_client=>create_by_url
    EXPORTING
      url                = wf_string
    IMPORTING
      client             = http_client
    EXCEPTIONS
      argument_not_found = 1
      plugin_not_active  = 2
      internal_error     = 3
      OTHERS             = 4.

  CALL METHOD http_client->send
    EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state         = 2.

  CALL METHOD http_client->receive
    EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state         = 2
      http_processing_failed     = 3.
  CLEAR result .
  result = http_client->response->get_cdata( ).

  REFRESH result_tab .
  SPLIT result AT cl_abap_char_utilities=>cr_lf INTO TABLE result_tab .
  LOOP AT result_tab INTO r_str.
    WRITE:/ r_str .
  ENDLOOP .

0 Kudos

Hi Kris,

Thank You,

I call to the endpoint and what i get is one long XML string (one line) .

How i can get the data, i.e. i build FM (wrap in WS) with import and export parameters and i want maintain them, do u have idea how i can do that?

BR

Nina

Edited by: Nina C on May 4, 2009 4:57 PM

0 Kudos

Hi Nina,

read [SAP Help|http://help.sap.com/saphelp_nw70ehp1/helpdata/en/bf/d005244e9d1d4d92b2fe7935556b4c/frameset.htm] about consuming a web service.

There you'll find the needed information and code examples.

Best Regards,

CW

0 Kudos

HI Cornelia,

Thanks,

Do i have to create proxy and logical port if i want to call to WS from backend1 to backend2 ?

IF yes ,where I have to create it in the tatget system or the host system ?

Best Regards

Nina

0 Kudos

Hi Nina,

you have to create the proxy and the logical port on client side.

Client side is the backend, that calls the web service.

Server side is providing the web service, that's the backend where you implemented your FM wrapped by the web service.

Best regards,

CW

0 Kudos

Hi ,

Thank you very much for all your answers!!!

I find this sample code that I think I should use in the program after i create the proxy like You tell in your previous post.

My question is where I have to put the WSDL or the Endpoint so the program will know to whom to call ?

DATA: proxy TYPE REF TO z00co_za_id_wsd2,
in TYPE z00my_operation_name,
out TYPE z00my_operation_name_response.
in-depa-city = u2019franku2019.
in-depa-country = u2019deu2019.
TRY.
CREATE OBJECT proxy
EXPORTING
logical_port_name = u2019L00u2019.
CATCH cx_ai_system_fault.
ENDTRY.
TRY.
CALL METHOD proxy->my_operation_name
EXPORTING
input = in
IMPORTING
output = out.
CATCH cx_ai_system_fault.
CATCH cx_ai_application_fault.
ENDTRY.

WRITE: / out-departure-airportid,
/ out-departure-city,
/ out-departure-country.

Best Regards

Nina

Edited by: Nina C on May 4, 2009 9:25 PM

Edited by: Nina C on May 4, 2009 10:38 PM

Edited by: Nina C on May 5, 2009 8:01 AM

0 Kudos

hai nina ,

to call a webservice from one back end to other,

first create a client proxy using the wsdl file of the function module,

u can test the client proxy from SE80 , before that u have to create the logical port

it can be created using transaction LPCONFIG or SOAMANAGER if release is latest

if once logical port is created u can test it by executing the client proxy

and u can also use the code which u have posted from any program

instantiate it and call the method by properly passing the parameters

but logical port is necessary , logical port must be created in the system from which ur calling i.e client proxy system

if solved close the thread

Edited by: mohammad afzal on May 5, 2009 8:31 AM

0 Kudos

HI ,

Thank You!

So if i get you right, this is the following procedure.

1. Create WS on the Target system (in the Server).

2. Generate proxy on the client (in the client).

3. create logical port Via lpconfig (in client).

Am i correct ?

But How can I fill the WS parameters (fill the import to get the export data) ?

Best Regards

Nina

0 Kudos

hello nina,

ur right with the steps in creation of webservices

and during testing when u execute the webservice u get a pop up window where u have a check box generate template data , if it is checked the parameters are autmotically proposed and u get the result

if u want to pass explicitly the paramters then u have to write a program and pass the values in input parameters , the paramters for the method have deep structure and u have to pass properly

i have doen a sample webservice where i pass a project definition and get its details

the sample code for the proxy is

the results is fetched in out parameter form where i can fetthed detials

REPORT ZDEMOPROXY.

Data : l_proxy type ref to ZPRJCO_ZPROJECTPORT_TYPE,

lo_sys_exception TYPE REF TO cx_ai_system_fault,

out type ZPRJZPROJECTOUTPUT,

in type ZPRJZPROJECTINPUT,

it_controller type PRXCTRLTAB,

wa_controller type prxctrl.

create object l_proxy.

in-PROJECT = 'T-10068'.

TRY.

CALL METHOD l_proxy->zproject

EXPORTING

input = in

IMPORTING

output = out

.

. CATCH cx_ai_system_fault into lo_sys_exception .

  • CATCH cx_ai_application_fault .

ENDTRY.

write out-details-description.

regards

afzal

0 Kudos

HI mohammad,

Thanks for your time.

I try the solution you propose and i think i get it.

i still not get the out parameters (coming empty)

i think that the problem is in LPCONFIG , but this is other issue so i open new post for that .

Thanks again

Nina

0 Kudos

hi nina,

as u said r u able to call the service from other system

and as u said u are getting empty paramters , check wether u haev used the export paramter of ur RFC

as that will be available in out paramter of proxy which is response from ur webserivce

may be LPCONFIG might not be working u can try to create in logical port in SOAMANAGER( this is applicable to latest versions of SAP) ,

i too faced lot of problem in creating a web service in r/3 and consume it in other r/3

atlast it was successful , in creatign logical port dotn forget to make the port as default port

regards

afzal