简体   繁体   中英

Streaming a file from WCF service

I am trying to figure out how to stream a file (typically a PDF) from a web service that is front ended by a typical web site. The PDFs do not physically exist, but are created on the fly by a report generator (think Crystal, Telerik Reporting, etc.)

I can do this today directly from the web site by doing a Response.Clear() followed by setting the ContentType and adding the appropriate Content-Disposition header finally followed up by a Response.BinaryWrite(...) .

But, a WCF service (IIS hosted in this case), does not have a Response object. I have tried passing in the Response object from my web page as a parameter, but I can't even start the WCF Service because HttpResponse cannot be serialized.

Am I barking up the wrong tree? Is there a better way of looking at this? We wanted it in a common web service because more of our web sites are needing to do this and we don't want to maintain multiple copies of the code to do it.

You can send your file as byte[] array.

Or you can send this file as a Stream parameter (using Streamed mode)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM