Wednesday, August 01, 2012 12:02 PM
Can any one help me?
I am using HttpWebRequest to upload files to server from a windows application. I set my request timeout property to infinite. i can not limit it to some predefined time as my File size may vary and net connection speed may vary from client to client.
Now my problem is, when request is waiting for response from server, if any network problem occurs at server side it won't send any response to client and my client application continuously waiting for the response and will block uploading other files.
Is there any way that i can terminate my connection in these cases.
So how can i know if any network related problem occurred at server side.
My HttpWebRequest Properties:
theRequest.AllowWriteStreamBuffering = False
theRequest.Accept = "*/*"
theRequest.Credentials = CredentialCache.DefaultCredentials
theRequest.KeepAlive = True
theRequest.Method = "POST"
theRequest.SendChunked = True
theRequest.Timeout = System.Threading.Timeout.Infinite
theRequest.UseDefaultCredentials = True
theRequest.UserAgent = My.Application.Info.ProductName
theRequest.CookieContainer = New CookieContainer()
- Edited by srinivas koneti Thursday, August 02, 2012 4:48 AM
Thursday, August 02, 2012 6:25 AM
I think the HttpWebRequest.Timeout applies to the "wait" to get the response stream, and doesn't matter once the receive has began. So it's wrong to think because you need to download big file, you should set the timeout to infinate.
To specify the amount of time to wait before a read or write operation times out, use the ReadWriteTimeout property.
Hope that it helps.
Thursday, August 02, 2012 7:43 AM
Thanks for your replay.
In my case i am uploading files to web server. I am getting this error after i write entire file into request stream and waiting for response form the server.
ReadWriteTimeout property will help me when writing to or reading from a stream.
Thanks Srinivas Koneti
Thursday, August 02, 2012 10:06 AM
I see. Is the "web server" side code written by you too? If you can issue concurrent request (using different threads) to upload all the files at the same time, that'd help ease the blocking problem. (The requests will be treated as if they belongs to the same logon session as long as you pass the same CookieContainer to them)
Unfortunately the GetRequestStream() method does not return NetworkStream, so there's little you can do to control the "stuck in transfer" behaviour.
Friday, August 03, 2012 5:18 AM
i only written web server code, in my case i can not upload all the files at same time because i may have lot of file at the same time.
is there any other method where i can send the file in chunks and for each chunk i will get a acknowledgement from server.
Thanks Srinivas Koneti
- Edited by srinivas koneti Friday, August 03, 2012 5:19 AM
Friday, August 03, 2012 6:52 AMYou may want to try using DotNetZip library to compress the files into spanned archives, upload them one by one, and combine them to recovery the file at the server. In this way you get response for each (now much smaller) files you've uploaded.