on 07-17-2012 5:55 AM
Hi,
can any one tell me how to use REST servieces in webdynpro abap if possible with example .
Thanks Regards,
Naga Punnarao.
Hi Naga,
REST web services are callable over HTTP so you would use a CL_HTTP_CLIENT object to handle the call to the web service. There is nothing specific to Web Dynpro in the code; you could write this code in any class method, function module, subroutine, etc. For example...
DATA client TYPE REF TO if_http_client.
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = 'https://host:port/WebService/operation'
IMPORTING
client = client
EXCEPTIONS
OTHERS = 4.
* Set request method to GET or POST
client->request->set_method( if_http_request=>co_request_method_post ).
* Set the request form data
client->request->set_form_field(
name = 'FORM_FIELD_ONE'
value = value_one
).
client->request->set_form_field(
name = 'FORM_FIELD_TWO'
value = value_two
).
* Send HTTP request
CALL METHOD client->send
EXCEPTIONS
OTHERS = 5.
CASE sy-subrc.
WHEN 0. " send OK
* Receive HTTP response
CALL METHOD client->receive
EXCEPTIONS
OTHERS = 4.
CASE sy-subrc.
WHEN 0. " receive OK
* Examine messages returned from the web service call
lv_cdata = client->response->get_cdata( ).
WHEN OTHERS. " receive error
CALL METHOD client->get_last_error
IMPORTING
code = ls_http_error-code
message = ls_http_error-message.
ENDCASE.
WHEN OTHERS. " send error
CALL METHOD client->get_last_error
IMPORTING
code = ls_http_error-code
message = ls_http_error-message.
ENDCASE.
You can use class CL_IXML to parse the CDATA returned by the web service. If you need to pass binary data to the web service, for example file contents, the approach is a little different.
Cheers,
Amy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
78 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.