Q:

Can WCF MemoryStream return type be written to the Http Response object for downloading as an Excel file?

I built a parsing application that reads xml files and populates an Excel workbook using the NPOI library. Originally, I had that as part of my .net web app and would get the MemoryStream from NPOI and write that to the Response object so the browser would download it.  I've since moved the parsing to a WCF netTcp service hosted in a Windows Service.  The communication works great, but when I return the MemoryStream from the WCF service and write it to the response, I get the following error:

Microsoft JScript runtime error:
  Sys.WebForms.PageRequestManagerParserErrorException:
  The message received from the server
  could not be parsed.

My question is: What happens to the stream when it gets passed from the wcf service to my client?  The stream is (theoretically) the exact same stream from NPOI that I was writing to the response originally.  Is there any special processing that I need to do on the client to make this work?
Here is my client code: (the exception get thrown at Response.End()
string filename = "test.xls";

ms = client.GetExportedFile();
byte[] b = ms.ToArray();

ms.Flush();
ms.Close();

Response.Clear();
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader( "Content-Disposition", string.Format( "attachment;filename={0}", filename ) );
Response.AddHeader( "Content-Length", b.Length.ToString() );
Response.BinaryWrite( b );
Response.End();

A:

You seem to retrun stream to request for partial page update with Update panel (search for Sys.WebForms.PageRequestManagerParserErrorException to find more details about exception).
Make sure that you are retruning stream only to full page request (GET/POST issued by browser itself, not by some script on the page that expects some particular type of responce).

