[Mono-list] HttpWebRequest differently compared to HttpWebRequest on .Net.

Gonzalo Paniagua Javier gonzalo.mono at gmail.com
Tue Mar 13 16:08:33 UTC 2012

On Fri, Mar 9, 2012 at 4:37 AM, marten.ekblad at relevo.se
<marten.ekblad at relevo.se> wrote:
> I have created a client app that communicates with a web service that uses
> the Comet way of sending events to a client. To do that I start a
> “long-living” HttpWebRequest to the server. The server communicates back to
> the client by sending chunked content (Transfer-Encoding: chunked).
> Individual events are then transferred in chunks. The problem for me here is
> that Mono seems to wait for the connection to terminate or the timeout to
> happen before sending the chunks back to the consumer of HttpWebRequest.
> This is not the case in .Net. In .Net each chunk is reported back
> individually when they arrive.
> This is the pseudo code I’m using:
> 1.      HttpWebRequest req = WebRequest.Create( URL…);
> 2.      req.BeginGetRequestStream(…);
> 3.      stream = eventContext.WebRequest.EndGetRequestStream(…);
> 4.      StreamWriter writer = new StreamWriter(stream);
> 5.      writer.Write(data);
> 6.      writer.Close();
> 7.      eventContext.RequestStream.Close();
> 8.      eventContext.WebRequest.BeginGetResponse(…);
> 9.      HttpWebResponse resp = (HttpWebResponse)
> req.EndGetResponse(asynchronousResult);
> 10.     responseStream = resp.GetResponseStream();
> 11.     responseStream.BeginRead(eventContext.Buffer, 0, 20000, new
> AsyncCallback(DataReceived), eventContext);
> 12.     In DataReceived I do responseStream.EndRead(asynchronousResult);
> 13.     After that I arm the read again with responseStream.BeginRead(…);
> In .Net DataReceived is called on each packet. In Mono it’s called after 30
> seconds (probably the timeout).
> Is this the intended behavior with HttpWebRequest and chunked content? Is
> there another recommended way of dealing Comet style web services?

For the record, this was a bug that is now fixed in the mono-2-10 and
master branches.


More information about the Mono-list mailing list