HttpWebRequest timeout in Windows service
Posted
by googler1
on Stack Overflow
See other posts from Stack Overflow
or by googler1
Published on 2010-03-24T14:36:05Z
Indexed on
2010/03/24
16:13 UTC
Read the original article
Hit count: 302
c#
I am getting a timeout error while starting my Windows service. I am tring to download an XML file from a remote system which causes a timeout during the service OnStart.
This is the method I am calling from OnStart:
public static StreamReader GetResponseStream()
{
try
{
EventLog.WriteEntry("Epo-Service_Retriver", "Trying ...",
EventLogEntryType.Information);
CookieContainer CC = new CookieContainer();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(
Utils.GetWeeklyPublishedURL());
request.Proxy = null;
request.UseDefaultCredentials = true;
request.KeepAlive = true; //THIS DOES THE TRICK
request.ProtocolVersion = HttpVersion.Version10; // THIS DOES THE TRICK
request.CookieContainer = CC;
WebResponse response = request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
EventLog.WriteEntry("Epo-Service_Retriver", "Connected to Internet...",
EventLogEntryType.SuccessAudit);
return reader;
}
}
Is there any possibility to avoid this timeout?
© Stack Overflow or respective owner