Is there a timeout issue with HttpWebRequest

  • Thread starter Thread starter Jens Jensen
  • Start date Start date
J

Jens Jensen

I try to set the timeout property on my
HttpWebRequest object before lunching the request.

It seems like any value above 100 seconds is discarded.

Has anyone observered malfunctional with this class?



Thanks
jj
 
Hello, Jens!

JJ> It seems like any value above 100 seconds is discarded.

100 seconds is rather big timeout. After 100 seconds TCP connection can timeout, and you will receive
WebException exception.

As a workaround you can try using HttpWebRequest.ServicePoint.MaxIdleTime or if that didn't help
change TCP/IP timeout settings in the OS ( http://support.microsoft.com/kb/314053/ )

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
I'm sending large database files for processing on the database. The
processing can take up to 2 minutes.
 
Thus wrote jens,
I try to set the timeout property on my
HttpWebRequest object before lunching the request.
It seems like any value above 100 seconds is discarded.

Has anyone observered malfunctional with this class?

Are you manipulating Timeout or ReadWriteTimeout?

People quite often use the fomer while actually wanting to use the latter ;-)

Cheers,
 
Hello, Jens!

JJ> I'm sending large database files for processing on the database. The
JJ> processing can take up to 2 minutes.

Can you provide code sample, where you "send large database files"?
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
Can you provide code sample, where you "send large database files"?


on the client: ( the xml is stored in "message")

{HttpWebRequest req =
(HttpWebRequest)HttpWebRequest.Create(ConfigurationManager.AppSettings["uri"]);

req.ContentType = "text/xml; charset=utf-8";

req.Method = "POST";

UTF8Encoding encoding = new UTF8Encoding();

byte[] postBytes = encoding.GetBytes(message);

req.ContentLength = postBytes.Length;

System.IO.Stream reqStream = req.GetRequestStream();

reqStream.Write(postBytes, 0, postBytes.Length);

reqStream.Close();

req.Timeout = 1000*int.Parse(
ConfigurationManager.AppSettings["SessionTimeOut"].ToString());
//SessionTimeOut

Log.Write("Sending file:" +
ConfigurationManager.AppSettings[file].ToString());

System.Net.WebResponse resp = (HttpWebResponse)req.GetResponse();


System.IO.StreamReader sr = new
System.IO.StreamReader(resp.GetResponseStream());

message = (sr.ReadToEnd().Trim()).ToString();

Log.Write("Received response of file:" +
ConfigurationManager.AppSettings[file].ToString());


postBytes = encoding.GetBytes(message);

System.IO.File.WriteAllBytes(numb.ToString() + "received.xml", postBytes);

resp.Close();

sr.Close();





On the server:( the server is an xml gateway built as an http handler that
use ODP.NET to intrect with some oracle backend)




public void ProcessRequest (HttpContext context) {

try

{



DataAccess da = new DataAccess();

context.Request.ContentType = "text/xml; charset=utf-8";

System.IO.StreamReader reqStream = new
System.IO.StreamReader(context.Request.InputStream);

irw.message = reqStream.ReadToEnd().Trim();

da.process_message(); // The file is proceesed and the response is stored in
the member "message"

context.Response.ContentType = "text/xml; charset=utf-8";

UTF8Encoding encoding = new UTF8Encoding();

byte[] postBytes = encoding.GetBytes(da.message);

context.Response.OutputStream.Write(postBytes, 0, postBytes.Length);



}

catch(Exception exe)

{

Log.Write(exe);

}




}



Thanks

JJ
 
On the server side, the default timeout is 30 minute what should be largely
enough . Should i be using ReadWriteTimeout instead of jus Timeout?

Thanks
JJ
 
You probably just want to use the Timeout property:

Timeout is the number of milliseconds that a subsequent synchronous request
made with the GetResponse method waits for a response, and the
GetRequestStream method waits for a stream. If the resource is not returned
within the time-out period, the request throws a WebException with the Status
property set to WebExceptionStatus.Timeout.

Timeout does not work if you are making asynchronous calls, in that case you
need to implement your own timeout mechanism.

Peter



--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




Jens Jensen said:
On the server side, the default timeout is 30 minute what should be largely
enough . Should i be using ReadWriteTimeout instead of jus Timeout?

Thanks
JJ
 
So how to explain the misterious timeout i experience using this class?


I set the timeout value to 100 000 milliseconds, and i do observe a timeout
exeption in about 90 seconds.

Has anyone seen anything similart before?
 
Thus wrote jens,
So how to explain the misterious timeout i experience using this
class?

I set the timeout value to 100 000 milliseconds, and i do observe a
timeout exeption in about 90 seconds.

Has anyone seen anything similart before?

Regarding my previous reply: Do you know whether this is a connect or a read/write
timeout?

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top