473,396 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem with WebRequest and timeout

Hello

I try to implement "retry" if connection to web ends with "time out". I want
to give a chance to prolong waiting for response. The following code is
taken from WebRequest.GetResponse() implementation. All I need to do is to
modify line with "to change". My client uses derrived HttpWebRequest. I
tried to implement new class MyHttpWebRequest and override GetResponse for
it, but how can I create instance of this class. In .Net there is used
special interface IWebRequestCreate and static method Create to creating
WebResponse object but I still don't know how to do this. Could somebody
help me? (maybee there is another solution?). Thanks a lot.

Shark

public override WebResponse GetResponse()
{
IAsyncResult result1;
Exception exception1;
if (this._HaveResponse)
{
this.CheckFinalStatus();
if (this._HttpResponse != null)
{
return this._HttpResponse;
}

}
result1 = base.BeginGetResponse(null, null);
if ((this._Timeout != -1) && !result1.IsCompleted)
{
try
{
result1.AsyncWaitHandle.WaitOne(this._Timeout, 0); //to change
if (!result1.IsCompleted)
{
base.Abort();
throw new WebException(SR.GetString("net_timeout"), 14);

}
}
catch (Exception exception2)
{
exception1 = exception2;
base.Abort();
throw;

}
Nov 16 '05 #1
2 9403
it should be rather "wait" insted "retry"
sorry
"news.microsoft.com" <as******@poczta.onet.pl> wrote in message
news:OO**************@TK2MSFTNGP09.phx.gbl...
Hello

I try to implement "retry" if connection to web ends with "time out". I
want to give a chance to prolong waiting for response. The following code
is taken from WebRequest.GetResponse() implementation. All I need to do is
to modify line with "to change". My client uses derrived HttpWebRequest.
I tried to implement new class MyHttpWebRequest and override GetResponse
for it, but how can I create instance of this class. In .Net there is used
special interface IWebRequestCreate and static method Create to creating
WebResponse object but I still don't know how to do this. Could somebody
help me? (maybee there is another solution?). Thanks a lot.

Shark

public override WebResponse GetResponse()
{
IAsyncResult result1;
Exception exception1;
if (this._HaveResponse)
{
this.CheckFinalStatus();
if (this._HttpResponse != null)
{
return this._HttpResponse;
}

}
result1 = base.BeginGetResponse(null, null);
if ((this._Timeout != -1) && !result1.IsCompleted)
{
try
{
result1.AsyncWaitHandle.WaitOne(this._Timeout, 0); //to change
if (!result1.IsCompleted)
{
base.Abort();
throw new WebException(SR.GetString("net_timeout"), 14);

}
}
catch (Exception exception2)
{
exception1 = exception2;
base.Abort();
throw;

}

Nov 16 '05 #2
news.microsoft.com wrote:
Hello

I try to implement "retry" if connection to web ends with "time out".
I want to give a chance to prolong waiting for response. The
following code is taken from WebRequest.GetResponse() implementation.
All I need to do is to modify line with "to change".
Hm...

result1.AsyncWaitHandle.WaitOne(this._Timeout, 0); //to change

The second parameter is false, not 0. As you can see, it already uses a
timeout, so there's no reason to toy with HttpWebRequest's innards ;-)
Just use the HttpWebRequest.Timeout property.
My client uses
derrived HttpWebRequest. I tried to implement new class
MyHttpWebRequest and override GetResponse for it, but how can I
create instance of this class. In .Net there is used special
interface IWebRequestCreate and static method Create to creating
WebResponse object but I still don't know how to do this. Could
somebody help me? (maybee there is another solution?). Thanks a lot.


You can also use the asynchronous BeginGetResponse(), which returns an
IAsyncResult object to create an timeout that is independent of the Timeout
property mentioned above. This looks roughly like this:

HttpWebRequest request =
(HttpWebRequest) WebRequest.Create(http://host/path/to/resource.html);

IAsynchResult ar = request.BeginGetResponse(
new AsyncCallback(ResponseCallback),
request);

ThreadPool.RegisterWaitForSingleObject(
ar.AsyncWaitHandle,
new WaitOrTimerCallback(TimeoutCallback),
request,
5000, // 5 secs
true);

Cheers,

--
Joerg Jooss
www.joergjooss.de
ne**@joergjooss.de
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Craig | last post by:
I wrote a generic page to do HttpWebRequest operations based on 3 querystring parameters for the uri, username, and password for basic authentication pages. The page is designed to help with...
1
by: aaronfude | last post by:
Hi, I'm running the following code to read a URL into a string. When the url is offline, it times out after about 10 seconds regardless of what I set myRequest.Timeout to. Any suggestions? ...
22
by: Kristof Thys | last post by:
Hello, I'm developing a C# - windows forms application. To get some information for my application, I'm connecting to an URL, wich gives me XML generated using php. With 90% of the users, this...
0
by: Ram P. Dash | last post by:
Hi: I had the following client proxy code autogenerated: Code I: public bool ProcessCondensateFile(CondensateFileContainer condensateFileContainer) { object results =...
9
by: Hasani \(remove nospam from address\) | last post by:
I have a website with 2 aspx pages Foo.aspx, and bar.aspx The content of both files is //in 1 file Hello <%=Session.ToString()%> ================
3
by: Stephane | last post by:
Hi, I'm trying to use PayPal and its Instant Payment Notification. In short, when a payment is made, PayPal send a post to my server and I post it back to PayPal. I'm using WebRequest to do...
0
by: Gordon | last post by:
I use the following code to get source HTML. The second line seems to work when I get no response from a site. However, I want to stop the request if it's taking more than 20 - 30 seconds. I can't...
3
by: Jonathan | last post by:
I appreciate anyone's insight on this as I am new to web programming with .NET. I have a simple method which I use to send various HTTP requests to a web server (snippet below). On the first...
2
by: Piotrekk | last post by:
Hi I am trying to upload a 700 mb file using webrequest/response model. At 3x% I am getting the same error: "Unable to write data to the transport connection: an established connection was...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.