function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
DodiDodi 

How to parse binary attachment data from a SOAP web service response

Hi all, I have a requirement where we access pdf docs from a third party web service that stores them. I am trying to bring these back into Salesforce as attachments and I have a call out that passes in the request xml and receives a response ok. Question is how do we access the binary attachment section of the response? The attachment is outside the soap envelope and trying to figure out how to get to it so I can load it as an attachment. 

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <ns2:DocDNAExtractResponse xmlns:ns2="http://hq-srames-lt.lason.com/DocDNAWS/">
         <Result>
            <ResponseXML><![CDATA[<RESPONSE>
<DOCS_FOUND>3</DOCS_FOUND>
<DOCS_EXTRACTED>3</DOCS_EXTRACTED>
</RESPONSE>]]></ResponseXML>
            <StatusXML>&lt;STATUS>SUCCESS&lt;/STATUS></StatusXML>
            <Documents>
               <IndexDetails>PSC_GENID    PSC_GENNME    PSC_CUSTID    PSC_CUSNME    PSC_SDOCID    PSC_ORDNUM    PSC_GENSDT    PSC_TSDFSD    PSC_IDOCID    PSC_DOCTYP    PSC_DOCID    PSC_MANFLG    PSC_SCNDTE    Pages</IndexDetails>
               <FileAttachmentList>
                  <FileName>83115e33-015e-4d09-9bdf-bfda3a93424e-000001.pdf</FileName>
                  <Attachment>
                     <xop:Include href="cid:b5a0b95f-9f14-41b1-85af-dab89be0561b@example.jaxws.sun.com" xmlns:xop="http://www.w3.org/2004/08/xop/include"/>
                  </Attachment>
               </FileAttachmentList>
            </Documents>
         </Result>
      </ns2:DocDNAExtractResponse>
   </S:Body>
</S:Envelope>



HTTP/1.1 200 OK
Date: Wed, 10 Jun 2015 19:02:27 GMT
Transfer-Encoding: chunked
Content-Type: multipart/related;start="<rootpart*7ae4c202-67e8-4e07-8a57-0034174bd098@example.jaxws.sun.com>";type="application/xop+xml";boundary="uuid:7ae4c202-67e8-4e07-8a57-0034174bd098";start-info="text/xml"
Set-Cookie: JSESSIONID=jj7QV4JD4Z1MB2TDBrGnT49K56KK0RRvqBZYSjlXYjf3nkLWClnQ!2091688840; path=/; secure; HttpOnly
X-Powered-By: Servlet/2.5 JSP/2.1
Set-Cookie: BIGipServerDNA_Securevault_pool=3154379274.22811.0000; path=/

--uuid:7ae4c202-67e8-4e07-8a57-0034174bd098
Content-Id: <rootpart*7ae4c202-67e8-4e07-8a57-0034174bd098@example.jaxws.sun.com>
Content-Type: application/xop+xml;charset=utf-8;type="text/xml"
Content-Transfer-Encoding: binary

<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:DocDNAExtractResponse xmlns:ns2="http://hq-srames-lt.lason.com/DocDNAWS/"><Result><ResponseXML>&lt;RESPONSE>&#xd;
&lt;DOCS_FOUND>3&lt;/DOCS_FOUND>&#xd;
&lt;DOCS_EXTRACTED>3&lt;/DOCS_EXTRACTED>&#xd;
&lt;/RESPONSE>&#xd;
</ResponseXML><StatusXML>&lt;STATUS>SUCCESS&lt;/STATUS></StatusXML><Documents><IndexDetails>PSC_GENID    PSC_GENNME    PSC_CUSTID    PSC_CUSNME    PSC_SDOCID    PSC_ORDNUM    PSC_GENSDT    PSC_TSDFSD    PSC_IDOCID    PSC_DOCTYP    PSC_DOCID    PSC_MANFLG    PSC_SCNDTE    Pages&#xd;
</IndexDetails><FileAttachmentList><FileName>83115e33-015e-4d09-9bdf-bfda3a93424e-000001.pdf</FileName><Attachment><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:b5a0b95f-9f14-41b1-85af-dab89be0561b@example.jaxws.sun.com"/></Attachment></FileAttachmentList></Documents></Result></ns2:DocDNAExtractResponse></S:Body></S:Envelope>
--uuid:7ae4c202-67e8-4e07-8a57-0034174bd098
Content-Id: <b5a0b95f-9f14-41b1-85af-dab89be0561b@example.jaxws.sun.com>
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary

%PDF-1.4
%����
2 0 obj
<</Length 40>>stream
q 1287.75 0 0 1679.25 0 0 cm /Im1 Do Q

endstream
endobj
4 0 obj
<</DecodeParms<</K -1/Rows 2239/Columns 1717>>/Type/XObject/Subtype/Image/ColorSpace/DeviceGray/Width 1717/BitsPerComponent 1/Length 53021/Height 2239/Filter/CCITTFaxDecode>>stream
&�d� `�9 a��r1��9�ßpWr������T2����
���ʒV@� �sa�9 A�#r9�0�Ð����4�0��I�7rC�rsa�Q�9�0�s�w;�s�Pu�
/�5A��0�r1��0��sa�9';��)�9��$)!��T��3�ʃ����c��n�s�)�\��C 6�3�ra�Q�;�
s�� �rs��Ürr 㑎B�a�9�Øsg$��DDDDDDDDDDDDDDDDy@A��0�(�3�a�Q�9�;��a��;��Øs�'$9�㑎a�9�0�Ð0�2�0�sw;�s�܌r7Mb"""""""S�x����.�d|�"""""<�@���s@�r
#�H���9�0�Øsw?��6I2�9Y��� �YNq�9�0� �s�ey�0�nTyZ�����9��?9Vw;����:Φ��hȺ+�"t]��[����Dw�#�N�J��tG��Q$��]���"-�2Vf����F!&��H����q2e�< ˳_L�6͑��q�D�s8f��.F�r.k��SM4�l}s�s�*/�����e�A��O�M>�����������������b�����G��{��_�������2�&P/�=������_����J���Ȕ�8��������������/_���w�����(������������y�*���������w)?ˠؐ����_������$��TG����������i7�h~���������������������A����������-��)������������EK:唗��+��������w�F�_���_�������DE���to�z������o���WX�����������&�J��֛���_�_������!u������������%����������u�����������"@c�����������������������_������%���������� �#�}���_�������"?����������������������fW����_�������~�z���������𽮷���������q�����������H�G��u�������������������}�u���������u���������'z�����������S��_������_���������������]������r!��l/���W����׿�[I��������������u����������__�����~Y�������������|�f�>>�����{����e�F�0�_�����������nd�ß"��j�k吺�������_���a�;    ��w����
tgVH"��    ������������i�anHz�$xA��P��c���������u�!��શ���E �'��������������~5K�Ó�XN����UUS������������d-']���u&�N�P�P������u����^�O|?��-�#I=8P�8Zs�/����������D�+�&=~�����V������������oA���X_��a��_⡯�����������P����#��y��ܘ������������K��Zֹ�l���������~���;����U��Lj����������{�,�O_�/�q�����������x�9 �%����{%l�i�����������^S��pOK_����������AV�W���]o��������ֿ��qn���xRZut������������������K+�_DM����Y�_�_���������մ������6����}���������&�P�D=���Xk־�t�����������_��;[lV��?��]'[�n�_���_�W��Ѝ4�]SM~;k!�>K�_���������i�� �'��5�=J����_��������    ��hDDk�����������8�kk
?����_������`�DԄNŗ��������������������������������}{ ������������������������������������������d�����������������������������������{������������޿����%��4 &���w����v�B"""#�"""""""""""""?���:���<~%���3�
4~M�3������E�\!)gw��ǙqM�4�F�=|�F��³腢�)�_/���SGfyT��]�X��1�h���M��7Oߝ�2f�yYq->�H,����`�A���o_���=5��}RlV��ҽ_���������ʑ������3Y;8�E��/Dv`�3��<?��8uT�V������S�Q�Ǚ��m�3���2s63B��%�3~��E�E�px<�����s� B��반�{�XJ��/�3�l�r6��(�;#���8��͙�f� �$F�5�i}���?�F����?�==g��p�;S\���-�ܷr��F��]���g�����o_W��T��#�G�
k�Zuh��@��hϖ�4i0�(�ѡ��o�&��}�3���M����5�R���_�M�6G�n����&�������ѝ�gs;��o�gp�f�3�xu3��ѣO�ֿ�_��ӯ����C�}k�����W�������n�'�w�s�ه�     j�>4��_O���k"��kI���د�ۯ��𑻏��{���q2���������8���~������f��������?������}�����~�~����!���������_��0�Yu���������������l���0�����!����������⦟ׯ��ԏw��u��q��7����0���������
�����~����i���]�������zz�������?���_:��������۽z�J�_����������{�������щ&*�8��د��>�������G��)�u�������v�����������K��b�Э��K�M5L ���)�_�1������+1��u_�\ƞ��aX��6)���?�)�b��*��������~�*�����a4�S�B"#�?���ݮ����N>?c�����������ߦ�������ܣ�� ������b��!u�GM� �����������3������CS#��_�ȷ���gb>� �ת_8����ݡ&�`AՑ�]���9�dc8�f�+�a�6OC��Ghl0
fap����h����Y���6:
�`T�th_�DD��(@�`r?;t[
��a�gsq�r�V�׵ f
���
��}�;�ʂ��JfVs��B�([u"f�9N@��e�܁A���`���]E���    W����,sO$Gb�w�o��C6ȉ4,��E&o)*�2�H�kz �*
�k�FZ����Ԉ* ��3�eG�靅�轧4f��� /���#ˣC����.����Hϣ��=��F�_1�&b=-���>�D~���z>��
�o���sq�9�'��3��x ˙r6͑�_6���a3L �!� ���qa;͇    �L���)pKL��s��(vn>����IapM����e�xN�B-#ԩ��H���A�v���};��Պ����_���.4˒j�'���]��H��þwu�,s>�����g�9�ִ�љ�ϙ�)zI<ϙ�?��>a�3���h�0��ǣ>��X�0�_������F{H��Z��9����-+ ����ե����#��u8��x���|a����t�����~>����U~����}{֔P��������׾���z�����Dy��ő��Ov���{��`������������>������?��Pa��a�4��W0�_�M���{��?�V�U�4}?ۏ�������KF�������΁�ቑ��}��&�4���_�#�����_�:�s1�E� �6͙��p�8�"Y�M4Xy���g������%�{������ϫ^�?�x"?�F?��<��������/������������^��������c�����^߳����z������/�0�����o�ݏ�8����E���-�&��p��}�)������?����66=��D�ű��:ݍ���s��~��~�o��^���_������4������t�����x���w��^*#���v�iݧv��M a0�4"M�a��� !g�B""���0�������������b��*��}��OM4
2㈈��DqG�"8�!�DP�������$��o �qY-K�^������ƋS>���E�<WV�����D0�������-W�q�S��Z��%�Z���������L|َ��w�����j�ѝ��4��k���y�ɰ`���2���u_�׷���5�9���3�̆D1N��`�    ��뿶���T]��&�������B @�B ��O������"���b����M}4v������O�[YWc馚U��O����[����    ��ap���5^Eƈ��������E�D��Y+�fJ܎n��;�O�u �ui>��L����[����Uuw��GL࿨0��KK����G+ ��|�L�vvH2s'�ڥ$?�J�?��i��C���!�@�L ��Z���}�t/��1fNPd�NF�Cd�fD6fXA�׿A��A��%���%��w �    �v�������U�^���w֣o��5�M4�US����mI�D�.ܛ���׵J����iɏDݪ�n����rs(w.�P�Z����J���6�#1�\!�6�G�q�������;�����Ӫӭ7�z_I?]j8���u%��#
���4�U�׿O�iw�����̂�5��")��=�M���M�*ſ�#<���ת}�I���I��1�0�.����mUu�
30��ksJ�#    J�C�=2XEgf;���p�#�:+(F�\z��E������4�ꉏU_��W�w%h��"Q���ֻ����i7���-�^F�ү~������b���D����Dv=zX�*W�"8�_֖:GO�q��\���2?W_��u�_�7饼���>N����?� �O�ү��a�!'Y���%�� ^�����K��7�֩S~��k�fJ������=�}�M�"Ç��_������7�z��w�}��-��JK���]��� C�7�Eˏ��������N��C��V�P���+�����
��0���/G����wտ������e    /�ix�ؤ�_i���3�O�*4��o{կQ��K����ޛ�~Ӵ׾��a��w�����U߯��0?�����u�H
b����M}l,0����m��M���a���v��ujNe
I���%kد�+�)��    ��0��h0D#��x'���=_�H�M��G�VǴ;�^���U�a:��v>��[i��ޝ����^O�    �h0�A��������O�׆�m4Ӵ�4���F�DDG��xB�-DDA�!�|�w��"#�_��������a������������!2�.!�GE�&��G�����EX�لk�s��L
@���8����o��ԁ(� A9���e��?��j�HB�C�M���
�[R��!����C9Mfڳ�Pqs2���A�����Y� �]��2|��D��1Ta�B3Do��2��P��dI�-�_�0��ծ��i����:g2e��eT�E�ӊi���?��K~���n�7b��s63��vl�v]�3�|��3 �.͚�L����P���[��o��
3�h$�O    ��U;�q�ޚ�wv���
`�e��l���ˌ�ds    �?�����ܦ/9�#�Nytr6Y��˙�0z_���F{H��#=��]���ў��jx[;�gp����X�wwh_�@��H~� D{��D�6H3 �a3?    �
�2�0?0G���D}%�"<����_�b��ߺ��k�����i��|�g��;��<ϙ�8Uj��|�)�;�'w�l<o�ݣ�F}������w�<g�*�F~`���O�l��ҫ
���},{�?k���qB��w����W�=.�0D{��W�g���o_�+��G����X��~6�����[�_�/�D��>���5t�����U�Oڏ8���Ն��#�6Q��=����1�o���������z3��0��|o�x/����0_��`������ 7�u����4����������/�ȇ��<7Q��7�F�� ���џ���1�߂)߄P���]��:b��r���]={/S��}u���?��>�����~o������}���T0ECmc�^8��ba�Ʊ�����b�����"<����"<����_���]ֽ�{���0����">�6����B�!=;���Mm4�{$馃^�$�i����s��~��s��cccb���w�ڗ�\��G�[���t�x����☙�0�DDDDDDDDDDlDDDDDDE�P�B"�=�`��L&W��1^�q�ӵ��Q��zi�q�ӴQ�p�    �Y��E'��0�a;B"Ͱ��O�����F*��0�� !����������-!�E2���4l>��C�_�c    �31�?���ft#�f`�Gf��>��aa5�k!a�H�9 S�8.C�<!�8@�
4-=>�?^����p`�� �0�L�]띣%�2t“�n�8jd�ߘ�����E����3m;L�rL���$��Dh3�#�;�"�"$�����D�1LV��Zɖv����H���T��EQ#����CI�#w!��zl'D�[��� �Ϗ3�A�fu��"�O    ���C""Jqűk�Ċ'�A�'�<ԟF_w���"#���rc�Gֿ���'�
�᪫��?���% ���4�}~���    k�c��yc��>��{��c�����B}[��_W���u���Idu��&��饫���i���q�;������}.���tN�_�h�t����9p��V+��[��U�D1���q}�h�N������� ޿������~����4�e�i�������]�_���V���Z}��]�~�a�D!�D����������H���ʉ�K�c�_�TT��^�� {k���I�o�O��ݯ����K�C��+c�_��+��0���A����kߥ�������B1�C0�?����^J�5T�T�MS������p�v��T!DDDDDo��DDDDD�����������/�'F��׿�Ó��8a3;�9�UY�]�3���kH��9�>f��� ς��̌ȢM4�Z���zA�����%2��B|��] r�1�\�q�a0�z���U��ǧ��T�&�i�i�v���MiQ1ܞ�w�������uO����0:~�.��j���������$�;�J�̘4d��vN�i��p�;�p´���.)s3#�A��pS��)v`������4Q4h?�hC����_��n%�B,&O�N#A��3��~�_�Aiw[�_H�Lz��=����$�_������c��Ɏ�������[��G�c�
w��=o��c���    ����X�4M��˿�A�� �c�{����L.�a<���vM˰���X�?���a�c�}� � ��گ��]��1ߎ�z���׽��^����[�u��Lq��/Mq�ԖO    ��oi_���
Best Answer chosen by Dodi
DodiDodi
Appears from the knowledge article that this is not supported with the existing XML parser. 

https://help.salesforce.com/apex/HTViewSolution?urlname=System-CalloutException-Web-service-callout-failed-Failed-to-get-next-element&language=en_US

All Answers

Andy BoettcherAndy Boettcher
Does this give you any hints at all?  Looks like you have a binary message body that you need to decode....

https://developer.salesforce.com/blogs/developer-relations/2011/07/sending-binary-data-to-apex-updated.html

 
DodiDodi
Yes, we will need to decode, but the question is if we are using the out of box parsers for the XML, how do we get to the attachment data out of the response message? 
DodiDodi
Appears from the knowledge article that this is not supported with the existing XML parser. 

https://help.salesforce.com/apex/HTViewSolution?urlname=System-CalloutException-Web-service-callout-failed-Failed-to-get-next-element&language=en_US
This was selected as the best answer