File Is Corrupted When Downloading PDF Using SOAP Protocol

How to download a PDF file from a SOAP endpoint?

The download of a PDF file from a SOAP endpoint, cannot be done using the current SOAP activity from Studio because the "Save" option is not available on such activity.

Using HTTP activity, the call is performed properly, file is downloaded but when opening it appears as corrupted. This is happening because HTTP is just a transport protocol which is sending the information as it is, without enveloping it as a SOAP call. When the server receives it, prepares the response and in the PDF header adds some additional information, for example:

<con1:Name>000030096349</con1:Name>
<con1:MimeType>application/pdf</con1:MimeType>
<con1:Length>54005</con1:Length>
<con1:Content>

When opening the file, the PDF editor will not recognize it properly because of the added header. If the PDF file is opened with a tool such NotePad++, the header added by the server needs to be removed therefore the file should be saved again and the PDF file will properly be recognized.

Making the same call from a third-party tool like SoapUI will download the file properly. This is happening because when using SoapUI, this one is not only transporting the information but is also enveloping and preparing the request to look specifically as a SOAP request. SOAP is an additional layer on top of HTTP. When SoapUI is properly preparing and enveloping the call > the server will understand it on a different way, and the response will also look different.

With this in mind, it can be said that both situations are behaving as expected, but the HTTP Activity from Studio will just transport the information, whilst SoapUI will prepare the request for SOAP and then send it. This is also happening because of the specifications of the server that is expecting to see the request enveloped for SOAP and not just HTTP sending the request.

To solve this from UiPath Studio, different approaches can be taken:
  • Use the new feature called Loading Web Services in Libraries, specifically designed for SOAP and Rest calls
  • Manually build the SOAP call, as specified on UiPath Forum post - Save Pdf Using HTTP Request
  • On Studio create a MultipartMemoryStreamProvider object, then extract the content and compare the content type (application/pdf). The final stage consists of writing the data to the byte array and saving it as a PDF file.