Re: HttpWebRequest - receiving stream before it's completed. Should it work? ... yes
Yes, it does work! (...but I still don't know if it's a bug or "by design")
So, what was wrong with my initial sample code? The first difference between the full framework and SL when calling
BeginGetResponse is
AllowReadStreamBuffering. As mentioned by Ola,
HttpWebRequest.AllowReadStreamBuffering (new in Beta 2) needs to be set to false (default is true). That will work but there is a catch (the second difference between "full framework" and Silverlight for
BeginGetResponse). Why was it waiting until the end of the stream to step in
BeginGetResponse then? 4kb...(4096 I suppose).
HttpWebRequest.AllowReadStreamBuffering set
BrowserHttpWebRequest._allowBufering variable. This is used in
Completed,
Failed and
Progress methods....
Progress is the one.... if _allowBuffering==true, call the Callback param... and this event is raised by
InternalWebRequest object... nothing I can get more from there... I haven't been able to find where, but I suppose that before
Progress can be called, there is a conditional statement that verifies that the stream is greater then 4kb....
So in my sample code, I was writing 5 times
"status : XX" to the response stream (and was getting the result as one string instead of five small strings). The resulting string was far from 4kb (but this works in my app console).... If I send a 4kb chunk first, then the following
"status : XX" are received every 10 sec as expected.
Obviously, sending an initial 4kb chunk is applicable only when you control the server part... at least now you know that you will need to have received 4kb from the server before
AllowReadStreamBuffering take effect.
Cheers!