Extract PDF file from soap response string



Problem: Extract PDF file from soap response string.


Description: I have the following response returned by webservice and converted using



response = client.UploadData(ClientUrl, Data);
string s = Encoding.UTF8.GetString(response);


--MIMEBoundaryurn_uuid_E2119CF27EF7027A6F1406730560891
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml"
Content-Transfer-Encoding: binary
Content-ID: <0.urn:uuid:E2119CF27EF7027A6F1406730560892@apache.org>

<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://ift.tt/sVJIaE"><soapenv:Body><dlwmin:getApplicationPDFResponse xmlns:dlwmin="http://ift.tt/V8QnRr" xmlns:xsi="http://ift.tt/ra1lAU"><ns1:GetPDFResponse xmlns:ns1="http://ift.tt/V8QnRr"><ns1:appPdfDoc><xop:Include xmlns:xop="http://ift.tt/1euX8oV" href="cid:urn:uuid:E2119CF27EF7027A6F1406730560893@apache.org"/></ns1:appPdfDoc><ns1:messageList/></ns1:GetPDFResponse></dlwmin:getApplicationPDFResponse></soapenv:Body></soapenv:Envelope>
--MIMEBoundaryurn_uuid_E2119CF27EF7027A6F1406730560891
Content-Type: application/pdf
Content-Transfer-Encoding: binary
Content-ID: <urn:uuid:E2119CF27EF7027A6F1406730560893@apache.org>

%PDF-1.4
%????
26 0 obj<</Rect[91.4365 636.817 299.129 651.505]/T(Contract Address 2)/t 1/V(OA CITY / OK / 73132-1501)/Subtype/Widget/DA(/ArialMT 10 Tf )/MK<<>>/FT/Tx/AP<</N 27 0 R>>/Ff 8388609>>
endobj

H??Wk????_?|?A?0???"K? \???+????^?]?f???:U??p6D????T???5???????y???z?f??zS???????t?{u?????U?DZ?`??i?l6u???u?U??:?0??2????S{yqU????\?>
d?~d(??C??Y?F???'?~K?03&?2??U.F?:4?@???????>_,???"?M?+????.*?x2?4Y??b???o??(M??F[X???j?cQ????EQZ??_??)Jg?a??h8m-;???:??;-???


It does have PDF, which starts at %PDF-1.4.


I have never parsed xop content. I just tried to load it into XDocument like



XDocument xdoc = XDocument.Parse(s);
XElement root = xdoc.Root;
XNamespace ns1 = "example.com/POS/get";
var fileBinary = root.Descendants(ns1 + "appPdfDoc").FirstOrDefault();


and got an error that it is not a valid xml document.


Now I trying to use XmlDictionaryReader.CreateMtomReader to load string S and see if that will allow me to extract PDF.


Please let me know if any other detail is needed. Any help is much appreciated.


Best Regards.


No comments:

Post a Comment