Skip to Content

Have you ever tried to consume a external WS in SAP ( Calling the client proxy -> Method ) filling all the parameters and you receive a blank response?

Below I indicate the steps to consume the external WS:

    –  Create Client Proxy as usual in SE80

    –  Create Logical port as usual in Soamanager

  

    Imagine that this WS method ( called concatenate ) has two inbound parameters:

      

        – Param1

        – Param2

      

    And it concatenates Param1 and Param2

  

    – Go to SE80 select the client proxy and test it with the client proxy test tool, indicating the Logical port and checking the set extended xml handling checkbox. After this SAP shows the request in xml format.

    Export the request content in a local file.

  

Once the xml format request is downloaded, it’s possible to call the WS using the code below.

Report ZWS_CALL.

*Data declaration

data: lo_sys_exception   type ref to CX_AI_SYSTEM_FAULT ,

      err_string type string.

data: lv_Req type STRING,

      lv_resp type STRING.

data: lv_class_name   type SEOCLNAME,

      lv_method_name  type SEOCLNAME,

      lv_log_port     type PRX_LOGICAL_PORT_NAME,

      lv_request      type XSTRING,

      lv_handling     type ABAP_BOOL,

      lv_response     type XSTRING,

      lv_error        type xstring,

      lv_exce         type STRING.

data: lv_param1 type string value ‘This is a’.

      lv_param2 type string value ‘Webservice test’.

data: v_param1 type string,

      v_param2 type string.

concatenate ‘ <n0:param1>’ lv_param1 ‘</n0:param1>’ into v_param1. * parameter 1

concatenate ‘ <n0:param2>’ lv_param2 ‘</n0:param2>’ into v_param2. * parameter 2

lv_class_name  = ‘ZCO_CONCATENATE’. ” client proxy generated class

lv_method_name = ‘CONCATENATE’.        ” method name

lv_log_port    = ‘C_LOG_PORT’.      ” logical port

lv_handling    = ‘X’.               ” set extended xml handling

* build the request in xml format as it’s in the se80 test tool ( downloaded file )

concatenate ‘<n0:concat xmlns:n0=”http://XXXXXX.XXXXXXX.CCCCCCC” xmlns:prx=”urn:sap.com:proxy:xxx:/xxx/xxxxxxxxxxxxxxxxx:700:2008/01/11″>’

            v_param1

            v_param2

            ‘</n0:login>’ into lv_req separated by cl_abap_char_utilities=>cr_lf.

* transform the request into xstring format

lv_request = cl_proxy_service=>cstring2xstring( lv_req ).

data: system_fault type ref to cx_ai_system_fault,

      system_error type ref to cx_xms_system_error,

      sus type ref to CX_XMS_SYSERR_PROXY.

* call the method using the CL_PROXY_ADAPTER_TEST

TRY.

    CALL METHOD CL_PROXY_ADAPTER_TEST=>OUTBOUND_TEST

      EXPORTING

        CLASS_NAME            = lv_class_name

        METHOD_NAME           = lv_method_name

        LOGICAL_PORT_NAME     = lv_log_port

        REQUEST_DATA          = lv_request

        EXTENDED_XML_HANDLING = lv_handling

      IMPORTING

        RESPONSE_DATA         = lv_response

        ERROR_DATA            = lv_error

        EXCEPTION_CLASS_NAME  = lv_exce.

  CATCH CX_XMS_SYSERR_PROXY into sus.

    message sus type ‘I’.

    exit.

  catch cx_xms_system_error into system_error.

    message system_error type ‘I’.

    exit.

  CATCH CX_SXML_SERIALIZATION_ERROR .

  catch cx_ai_system_fault into system_fault.

    message system_fault type ‘I’.

    exit.

  CATCH CX_AI_APPLICATION_FAULT .

ENDTRY.

* TRANSFORM THE RESPONSE FROM XSTRING TO STRING AND PROCESS IT. HERE WE SHOULD FIND THE RESULT OF THE CONCATENATE OPERATION.

lv_resp = cl_proxy_service=>XSTRING2CSTRING( lv_response ).

Hope it helps.

Regards

Jon

To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

Leave a Reply