Skip to Content
Technical Articles

Consuming Webservices with tag in WSDL using ABAP

Consuming Webservices with <ANY> tag in WSDL using ABAP

*  request_data = inpxml.
cl_proxy_st_part=>create_for_clas_method(
EXPORTING
class                    = class
method                   = method
for_serialize_request    = abap_false
for_deserialize_request  = abap_true
for_serialize_response   = abap_true
for_deserialize_response = abap_false
extended_xml_handling    = extended_xml_handling
IMPORTING
request_part             = lr_request_part
response_part            = lr_response_part
param_tab                = lt_parameter
).

TRY.
*     map xml to abap data
lr_reader = cl_sxml_string_reader=>create( inpxml ).
lr_request_part->deserialize( reader = lr_reader ).

*     create proxy
CREATE OBJECT lr_proxy
EXPORTING
class_name        = class
logical_port_name = logical_port.

lr_prot_payload ?= lr_proxy->get_protocol(
if_wsprotocol=>payload ).

lr_prot_payload->announce_payload_consumption( ).

*     call proxy
lr_proxy->if_proxy_client~execute(
EXPORTING
method_name = method
CHANGING
parmbind_tab = lt_parameter
).

*     get payload
IF NOT lr_response_part IS INITIAL.
*       try payload protocol
TRY.
IF NOT lr_prot_payload IS INITIAL.
lr_ws_payload =
lr_prot_payload->get_sent_response_payload( ).
IF NOT lr_ws_payload IS INITIAL.
org_response_data = lr_ws_payload->get_xml_binary( ).
ENDIF.
ENDIF.

CATCH cx_ai_system_fault.                     “#EC NO_HANDLER
ENDTRY.

ENDIF.
CATCH cx_ai_application_fault INTO lr_app_fault.

IF lr_prot_payload IS BOUND.
*       read response payload
TRY.
lr_ws_payload =
lr_prot_payload->get_sent_exception_payload( ).
IF NOT lr_ws_payload IS INITIAL.
org_response_data = lr_ws_payload->get_xml_binary( ).
ENDIF.
CATCH cx_ai_system_fault.                     “#EC NO_HANDLER
ENDTRY.

ENDIF.

*     get type description of application fault
lr_classdescr ?= cl_abap_typedescr=>describe_by_object_ref(
p_object_ref = lr_app_fault ).

*     get type name
exception_class_name = lr_classdescr->get_relative_name( ).

*     base class cannot be mapped to XML for no stylesheet can be
*     generated
IF exception_class_name = ‘CX_AI_APPLICATION_FAULT’.
RAISE EXCEPTION TYPE cx_ai_system_fault
EXPORTING
textid   = cx_root=>cx_root
previous = lr_app_fault.
ENDIF.

CLEANUP.
IF lr_prot_payload IS BOUND.

*       try to get original payload, even in case of errors
TRY.
lr_ws_payload = lr_prot_payload->get_sent_response_payload(
).
IF NOT lr_ws_payload IS INITIAL.
org_response_data = lr_ws_payload->get_xml_binary( ).
ENDIF.
CATCH cx_ai_system_fault.                    “#EC NO_HANDLER)
ENDTRY.

ENDIF.
ENDTRY.
resxml = org_response_data.

endmethod.

 

 

h2. Sample program that uses the ZWS_CALL

 

constants:
lp TYPE prx_logical_port_name value ‘Logical Port Name’,
cl TYPE seoclname value ‘Generated Consumer Proxy Class Name’,
md_cdata TYPE seoclname value Generated method in the consumer proxy class’.

* Step 1

CALL TRANSFORMATION source_transformation
SOURCE root = inpdate
RESULT XML inpxml.

Step 2<br />      TRY.<br />          CALL METHOD zcl_ws_call=>ws_call<br />            EXPORTING<br />              class        = cl<br />              method       = md_sdata<br />              logical_port = lp<br />              inpxml       = inpxml<br />            IMPORTING<br />              resxml       = resxml.<br />        CATCH cx_ai_system_fault .<br />      ENDTRY.</p><p> Step 3
CALL TRANSFORMATION Response_transformation
SOURCE XML resxml
RESULT root = sign_itab.

 

h2. Conclusion

 

Even in a less than perfect world, SAP can easily consume web services. ABAP Consumer proxy generated class can be used to accomplish parts of the job that it is intended to do. By combining simple XML processing ABAP commands with the generated consumer proxy, every web service can be consumed in ABAP.

h1. References:

a. Consuming Services with ABAP

b. http://help.sap.com/saphelp_nw70/helpdata/en/47/3a989cbcef2f35e10000000a1553f6/frameset.htm

    1. 2. XML to ABAP and ABAP to XML Transformation –

a. http://help.sap.com/saphelp_nw70/helpdata/en/e3/7d4719ca581441b6841f1054ff1326/frameset.htm </li></ul>

Be the first to leave a comment
You must be Logged on to comment or reply to a post.