user3889193
user3889193

Reputation: 63

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:[email protected]>

<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><dlwmin:getApplicationPDFResponse xmlns:dlwmin="http://example.com/POS/get" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><ns1:GetPDFResponse xmlns:ns1="http://example.com/POS/get"><ns1:appPdfDoc><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:urn:uuid:[email protected]"/></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:[email protected]>

%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.

Upvotes: 3

Views: 2428

Answers (0)

Related Questions