Can I configure WCF not to buffer messages but still return Content-length? RRS feed

  • Question

  • Background:

    I have a WCF REST service which downloads and then serves very large files (1-20Gb) to a web browser. To simplify, think of my service as a proxy. This obliges me to set TransferMode = Streamed or TransferMode = StreamedResponse on the Binding, or the end client will have to wait for the source files to be downloaded to the webserver before the actual download begins. Also, buffered transfer mode kills the server for large files (RAM usage). Intermediate disk storage is not an option. From TransferMode man page:

    (...) Buffered transfers hold the entire message in a memory buffer until the transfer is complete.

    But when setting TransferMode to Streamed or StreamedResponse, WCF no longer returns the header Content-length to the client, and a new header Transfer-Encoding: chunked is added. This is consistent with wikipedias article on chunked transfer:

    (...) uses the Transfer-Encoding HTTP header in place of the Content-Length header (...)

    But I always know the size of the data to be transferred beforehand, and for the end user, it's very frustrating not to know the size of the download (no percentage or time-left indication).


    (How) can I configure the WCF binding to use a "streaming" Transfer mode (or more specifically, not buffering the entire message before sending) and still return the Content-Length header to the browser?

    (Disclaimer: This is a slightly modified cross-post from my own question on StackOverflow, as I have not recieved any satisfying responses there I thought I'd try my luck here.)

    Thursday, March 13, 2014 2:12 PM


  • The code you posted is probably not relevant to the problem at hand.

    However, the link you provided describes the exact same problem, and there *seems* to be a workaround somehere in there using IDataStreamProvider... also I found this link in there which points out that this is a missing feature in WCF.

    Friday, March 14, 2014 10:42 AM

All replies