Update:
This is unrelated to WPF, as all clients are failing now. Using WireShark, I see that the server is sending packets but they are not being received by the client, and the server eventually sends an RST packet to kill the connection (which never makes it to the client).
WPF seems to be closing HTTP connections if a REST service takes a long time to respond.
I'm using a REST web service that takes 7 minutes to generate a JSON response. When called from Firefox, Android, or iOS, I see the response. When called from WPF's HttpWebRequest (or HttpClient or WebClient) with a 10 minute timeout, the web service reports "Connection reset by peer" when it tries returning the JSON after 7 minutes, and at the 10 minutes mark, the HttpWebRequest throws a timeout error.
Here is one version of the code:
try
{
// Create Request
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
// Set timeouts
request.Timeout = 10 * 60 * 1000;
request.ReadWriteTimeout = 10 * 60 * 1000;
request.ContinueTimeout = 10 * 60 * 1000;
// Getting desperate (I also tried not doing any of this)
request.KeepAlive = true;
request.ProtocolVersion = HttpVersion.Version10;
request.ServicePoint.ConnectionLeaseTimeout = 10 * 60 * 1000;
request.ServicePoint.MaxIdleTime = 10 * 60 * 1000;
// Attempt to get data
WebResponse response = request.GetResponse();
Stream stream = response.GetResponseStream();
StreamReader sr = new StreamReader(stream);
string content = sr.ReadToEnd();
label1.Content = content.Length.ToString();
}
catch (Exception ee)
{
// End up here
label1.Content = ee.Message;
}
I have also tried HttpClient, WebClient, and RestSharp with the same results.
If the service responds quickly, WPF gets the data correctly. In a fit of depiration, I also used regedit to set TcpTimedWaitDelay to 19 minutes, just in case.
Here is what I think is happening:
Does anyone out there know what's going on or how I can debug this?
Thanks!