[
  {
    "Id": "609285",
    "ThreadId": "256828",
    "Html": "\r\n<p>I am trying to implement &quot;a WCF service that receives a zip file as an attachment, and dynamically unpacks the zip to a stream for analysis&quot; .&nbsp;</p>\r\n<p>Does anybody has sample to read the stream file on the fly?</p>\r\n<p>&nbsp;</p>\r\n<p>Scenario:</p>\r\n<p>1) Zip (Xml Files) Stream comes from client to wcf service</p>\r\n<p>2) Iterate through all the files</p>\r\n<p>3) Read one xml stream to string xml (??) without unzipping the files to the filesystem..</p>\r\n",
    "PostedDate": "2011-05-08T16:10:26.353-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "609321",
    "ThreadId": "256828",
    "Html": "<p>Hmm, interesting.&nbsp; Not sure exactly what you are planning.&nbsp; it sounds like WCF Service that receives a stream,<br />and then unzips the stream as it is being received.</p>\n<p>I think it should be straightforward.&nbsp; Enable streaming&nbsp;as per this page: <a href=\"http://msdn.microsoft.com/en-us/library/ms789010.aspx\">How to: Enable Streaming in WCF</a></p>\n<p>In the server-side code, you have a method that receives a readable stream as input.&nbsp; Create a <a href=\"http://cheeso.members.winisp.net/DotNetZipHelp/html/077c5c21-1d3d-9f46-3a3a-a32aa5583d08.htm\">ZipInputStream()</a> around that Stream, and simply read/extract entries from the zip file.</p>\n<div style=\"background-color: white; color: black;\">\n<pre>    <span style=\"color: blue;\">byte</span>[] buffer= <span style=\"color: blue;\">new</span> <span style=\"color: blue;\">byte</span>[2048];\r\n    <span style=\"color: blue;\">int</span> n;\r\n    <span style=\"color: blue;\">using</span> (<span style=\"color: blue;\">var</span> raw = File.Open(inputFileName, FileMode.Open, FileAccess.Read))\r\n    {\r\n        <span style=\"color: blue;\">using</span> (<span style=\"color: blue;\">var</span> input= <span style=\"color: blue;\">new</span> ZipInputStream(raw))\r\n        {\r\n            ZipEntry e;\r\n            <span style=\"color: blue;\">while</span> (( e = input.GetNextEntry()) != <span style=\"color: blue;\">null</span>)\r\n            {\r\n                <span style=\"color: blue;\">if</span> (e.IsDirectory) <span style=\"color: blue;\">continue</span>;\r\n                <span style=\"color: blue;\">string</span> outputPath = Path.Combine(extractDir, e.FileName);\r\n                <span style=\"color: blue;\">using</span> (<span style=\"color: blue;\">var</span> output = File.Open(outputPath, FileMode.Create, FileAccess.ReadWrite))\r\n                {\r\n                    <span style=\"color: blue;\">while</span> ((n= input.Read(buffer, 0, buffer.Length)) &gt; 0)\r\n                    {\r\n                        output.Write(buffer,0,n);\r\n                    }\r\n                }\r\n            }\r\n        }\r\n    }\r\n</pre>\n</div>\n<p>The code above shows how to create a file for each entry in the received zip stream.&nbsp; You said you didn't want to do that, so you'd need to modify that but.&nbsp; What you decide to do with the data, once you extract it, is up to you.</p>\n<p>&nbsp;<br />ps: There was a related question a while ago about a WCF service that <em>emits </em>a ZIP stream back to the client.&nbsp; This required a&nbsp;nifty trick.&nbsp;See this post for details:</p>\n<p><a href=\"http://dotnetzip.codeplex.com/discussions/210699#post437276\">http://dotnetzip.codeplex.com/discussions/210699#post437276</a></p>\n<p>You don't need to use anonymous pipes in your scenario though - for a client sending a zip to the server.</p>\n<p>&nbsp;</p>",
    "PostedDate": "2011-05-08T20:48:13.16-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "609465",
    "ThreadId": "256828",
    "Html": "<blockquote style=\"border: solid .1em #ccc; font-style: italic; margin: .25em 1em 0 1em; padding: 0 .25em 0 .25em;\"><strong>Cheeso wrote:</strong></blockquote>\n<p>Thanks your reply. Basically,</p>\n<p>Upload Call: I get xml file in the zip format and have to deserialize into the data object (created by xsd) and pass it on to the business layer API.</p>\n<p>Download Call: I get xml as a string from business layer and here, I have to convert the xml string into xml file, zip it and convert into a stream to return as a response back to the client.</p>\n<p>Note: In the above two calls, we do not want to write anything to filesystem nor memory on the service side (Hosted on IIS Website ).</p>\n<p>The link you have provided has useful information. I will try the code and will let you know.</p>",
    "PostedDate": "2011-05-09T04:34:25.413-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]