Skip to Content

I came across with lots of questions related with SOAP with attachments in PI and can’t 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

/wp-content/uploads/2012/12/pic1_169253.jpg

Target Data Type – DT_TARGET

/wp-content/uploads/2012/12/pic2_169254.jpg

Based on these data types, create Message type – MT_SOURCE and MT_TARGET.

Create Service Interface for Synchronous message flow.

Outbound Service Interface –

/wp-content/uploads/2012/12/pic3_169255.jpg

Inbound Service Interface-

/wp-content/uploads/2012/12/pic4_169256.jpg

Next step is to create Request and Response Message Mappings.

Request Message Mapping –

/wp-content/uploads/2012/12/pic5_169257.jpg

Response Message Mapping –

/wp-content/uploads/2012/12/pic6_169258.jpg

Now create operations mapping based on above request and response mapping.

Request Operation Mapping –

/wp-content/uploads/2012/12/pic7_169259.jpg

Response Operation Mapping –

/wp-content/uploads/2012/12/pic8_169260.jpg

Configuration – Integration Builder

For configuration of this scenario, we need to create 2 Communication channel (Sender and Receiver) and an ICO.

Sender Communication Channel – SOAP Sender for Proxy communication, which is able to hold attachment if we click on Keep Attachments under Conversion Parameters.

/wp-content/uploads/2012/12/pic9_169261.jpg

Receiver Communication Channel

/wp-content/uploads/2012/12/pic10_169262.jpg

Integrated Configuration

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

/wp-content/uploads/2012/12/pic11_169264.jpg

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.

/wp-content/uploads/2012/12/pic12_169265.jpg

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.

/wp-content/uploads/2012/12/pic13_169266.jpg

Below is the response received in SOAPUI.

/wp-content/uploads/2012/12/pic14_169267.jpg

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.

To report this post you need to login first.

6 Comments

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

  1. Karan Gambhir

    Hi Aashish,

    What configurations we need to do in ID if attachment is coming only as a response for webservice request?

    Scenario is Webservicerequest(without attachment)> PI> Proxy>PI>Webservice Response(with attachment)?

    (0) 
  2. Anurag Srivastava

    Hello Aashish,

    Thanks for the document. It would be good if you could mention the T codes also, so that beginners like me can find it easy to follow.

    (0) 
  3. Youri Catinat

    Hi Aashish,

    In my case i need to work with Excel Attachment or PDF.

    No problem with PDF Attachment.

    I receive the Attachment in Binary (Soap With Attachment).

    No problem with Soap With Attachment, i did some tests with SoapUI.


    I use : OPEN DATASET lv_file FOR OUTPUT IN BINARY MODE.

    I can create the .xls file correctly.

    How to work with Excel Attachment ?

    (0) 
    1. Indu Khurana

      Hello Youri,

      I am also having a synchronous soap-pi-proxy call where I am getting response from ECC in the form of binary data, this binary data is extracted in PI through UDF and an attachment is created out of it. This attachment is excel file .

      I am using content type: application/msexcel  but it’s still creating attachment.bin in soapUI.

      Also, I’m getting pop ups whne I try to open the file by changing extension of the attachment.

      Did you find solution to your problem??

      Please advise.

      http://scn.sap.com/thread/3955194

      thanks,

      Indu Khurana.

      (0) 
  4. Hubery Yao

    Hello All,

    I have a question about the size of attachment. I test the scenario in PI 7.11. The size of attachment is less than 5M, otherwise, it will be overtime. For PI 7.31, I am not sure whether the size of attachment is bigger.  Anyone knows the biggest size of attachment ?

    Thank you for your support.

    Many thanks & best regards,

    Hubery

    (0) 

Leave a Reply