This is either a Silverlight bug or a specific Firefox constraint.
->The following works fine in IE.
On the server side I have a HTTP handler that just writes a string to the Response stream (within a loop). On the client side, I set AllowReadStreamBuffering to false. If I set a custom header, it seems to "disable" the AllowReadStreamBuffering since the BeginGetResponse's Callback parameter is just called after my httphandler is done (same as if I set to true).
HTTP Handler code:
public void ProcessRequest(HttpContext context)
{
context.Response.Write("Start write test"+'\n');
//4kb chunk for IE for test purpose... related to another possible bug in IE
//string bigfile = File.ReadAllText("c:\\bigfile.txt");
//context.Response.Write(bigfile);
//context.Response.Flush();
int nbLoop = 20;
while (nbLoop > 0)
{
Thread.Sleep(2000);
context.Response.Write("Write test : " + nbLoop + '\n');
context.Response.Flush();
nbLoop--;
}
context.ApplicationInstance.CompleteRequest();
}
Silverlight code: (called on a button's Click event)
private void btnGo_Click(object sender, RoutedEventArgs e)
{
string serverUri = HtmlPage.Document.DocumentUri.AbsoluteUri;
serverUri = serverUri.Substring(0, serverUri.LastIndexOf("/"));
Uri uri = new Uri(String.Format("{0}/test.test", serverUri));
HttpWebRequest req = WebRequest.Create(uri) as HttpWebRequest;
req.AllowReadStreamBuffering = false;
//uncomment the following to reproduce the bug
//req.Headers["custom-header"] = "custom";
req.BeginGetResponse(arResponse =>
{
//with AllowReadStreamBuffering=false, it should step here immediately
using (HttpWebResponse svrResp = req.EndGetResponse(arResponse) as HttpWebResponse)
{
using (StreamReader sr = new StreamReader(svrResp.GetResponseStream()))
{
int bsize = 256;
Char[] buffer = new Char[bsize];
int nbByte = sr.Read(buffer, 0, bsize);
while (nbByte > 0)
{
string resultingData = new String(buffer, 0, nbByte);
Debug.WriteLine(resultingData);
nbByte = sr.Read(buffer, 0, bsize);
}
}
}
},null);
}
I don't know if someone could confirm this? (I can email the complete VS solution if someone is interested)
Thanks