Está en la página 1de 13

Handle SOAP with Attachment Scenarioin SAP PI

I came across with lots of questions related with SOAP with attachments in PI and cant see many guides/blogs related to this. So I thought to clear the cloud on this with a Synchronous SOAP-PI-Proxy scenario. In this scenario we will handle attachment in Synchronous proxy call. SOAP request will pushed through third party tool SOAPUI, where we will attach the payload in request. Assumption 1. SLD configuration is with Technical System and Business System is done. Product and SWC is created in SLD. 2. SWC is imported in ESR. 3. Communication between ECC to PI and PI to Proxy is done. 4. ABAP code will only include logic of How to read incoming attachment. 5. SOAPUI is installed. Below is the development done in PI side ESR Development For testing purpose, I am taking few fields in source and target side. Main aim is to read attachment in inbound proxy. Source Data Type DT_Source

Target Data Type DT_TARGET - See more at: http://flipbeans.com/FlipBeans/handle-soap-attachmentscenario-sap-pi-7-31/#sthash.SqWfynpx.dpuf

Based on these data types, create Message type MT_SOURCE and MT_TARGET. Create Service Interface for Synchronous message flow. Outbound Service Interface

Inbound Service Interface-

Next step is to create Request and Response Message Mappings. Request Message Mapping

Response Message Mapping

Now create operations mapping based on above request and response mapping. Request Operation Mapping

Response Operation Mapping

Configuration Integration Builder For configuration of this scenario, we need to create 2 Communication channel (Sender and Receiver). Sender Communication Channel SOAP Sender for Proxy communication, which is able to hold attachment if we click on Keep Attachments under Conversion Parameters.

Receiver Communication Channel

Integrated Configuration Create Integrated Configuration between sender and receiver with above communication channel with operations mapping.

Now, development is completed from PI side. We need to go to ECC and generated server proxy to implement the method to read attachment and send output file back. In ECC, go to SPROXY transaction and generate proxy for Inbound Service Interface.

Double Click on provider class->Method Name to implement logic in inbound proxy class method. ABAP Code METHOD zii_si_target~si_target. *** **** INSERT IMPLEMENTATION HERE **** *** DATA: lt_attach TYPE prx_attach, l_name TYPE string, l_xstring TYPE xstring, l_string TYPE string, l_type TYPE string, l_attachment TYPE REF TO if_ai_attachment. DATA: lo_server_context TYPE REF TO if_ws_server_context, lo_payload_protocol TYPE REF TO if_wsprotocol. DATA : l_kind TYPE sychar01.

TRY. lo_server_context = cl_proxy_access=>get_server_context( ). lo_payload_protocol = lo_server_context->get_protocol( if_wsprotocol=>payload ). DATA : lo_attachment_protocol TYPE REF TO if_wsprotocol_attachments.

lo_attachment_protocol ?= lo_server_context->get_protocol( if_wsprotocol=>attachments ). CALL METHOD lo_attachment_protocol->get_attachments RECEIVING attachments = lt_attach. . CATCH cx_ai_system_fault. ENDTRY. LOOP AT lt_attach INTO l_attachment. CALL METHOD l_attachment->get_kind RECEIVING p_kind = l_kind. IF l_kind NE space. CALL METHOD l_attachment->get_binary_data RECEIVING p_data = l_xstring. ENDIF. ENDLOOP. CALL FUNCTION LXE_COMMON_XSTRING_TO_STRING EXPORTING in_xstring = l_xstring * IN_CODEPAGE = 4110 * EX_CODEPAGE = 0000 * UNMASK_CRLF = IMPORTING ex_string = l_string

EXCEPTIONS error =1 OTHERS = 2. IF sy-subrc <> 0. * Implement suitable error handling here ENDIF. DATA : lt_record TYPE zdt_target_record_tab, lwa_record TYPE zdt_target_record. CLEAR lwa_record. lwa_record-id = l_string. APPEND lwa_record TO lt_record. output-mt_target-record = lt_record. ENDMETHOD. Above code help to read incoming attachment in inbound proxy method in ABAP and then we can implement it as per our requirement. As of now, I have mapped incoming payload to one of the field (ID of data types mentioned earlier). We are ready to test this scenario. First step of testing is to download WSDL of this scenario. Open Integrated Configuration ->Display WSDL -> Save to save the WSDL. Open SOAPUI and give SOAP UI project name and browse WSDL path, downloaded in earlier step. Then double click on request 1 to send SOAP request to SAP. Add attachment to the message before sending any request. Also add authentication details in SOAPUI before posting request.

Below is the response received in SOAPUI.

Through this blog, I tried to give a simple solution about How to read an attachment in inbound proxy. There is possibility of different solution approach and above blog is in one of them. Hope this will help many people who stuck in SOAP with attachment scenario

- See more at: http://flipbeans.com/FlipBeans/handle-soap-attachmentscenario-sap-pi-7-31/#sthash.2jnAzM0I.dpuf

También podría gustarte