I have a quiet (webHttpBinding) self-service WCF service. Most methods return an xml or json version of objects to the client.
I have several GET methods that run long methods, and I would like to pass the log response to the browser (or application) so that the user knows what is happening. This would be easy to accomplish using HttpContext.Current.Response.OutputStream.Write . Unfortunately, HttpContext.Current always null in the WCF self-service, even if I aspNetCompatibilityEnabled configuration (unfortunately, IIS is not an option).
I tried AnonymousPipeServerStream : WCF and streaming requests and responses
along with the first setup:
OutgoingWebResponseContext context = WebOperationContext.Current.OutgoingResponse; context.ContentType = "text/plain";
so that the answer gets into the browser, it does not load the stream into a file for saving.
In Chrome, it doesn't work at all - it buffers to the end. In IE or wget, it seems that the buffer is about 4k (or something else) at a time. This is not suitable for logging, because if I did not spit out unnecessary log messages to force output, the user really does not know what is happening. I can only assume that this is because the answer is actually a block answer, and 4k chunks (and not just a write to the output stream).
The fix in order to get chrome for output, apparently, should write some garbage to the content before sending the delayed response: Chunked transfer encoding is the behavior of the browser , however I donโt think it is possible with WCF.
So, the possible solutions I'm looking for are:
- A way to write to the output stream in WCF in a standalone service (without IIS). or
- A way to control the block sizes in a streaming response (& a way to write some content first so that Chrome displays the pieces).
Another option, I suppose, is to abandon WCF in favor of something more REST-friendly (I'm starting to think that WCF was not the right choice). However, having written so much in WCF, this seems like a tedious task. If I cannot switch to this, it will be a simple migration (for example, if I can reuse the same classes of service, perhaps with only different attributes). Nancy maybe?