473,654 Members | 3,068 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

WebRequest hanging, no timeout

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 several invocations, the debugger will
actually stop in the catch block.

However, after a number of invocations (variant) the program just hangs on
waiting for the GetResponse(). I would expect the timeout/Webexception to
occur. In monitoring the traffic on the webserver, the requests are coming
in and the server appears to be responding appropriately.

On an additional note, if I comment out the explicit setting of the timeout
to 100 ms (from what I read in the WROX book, default is 100,000 anyway),
then the application never steps into the catch block.

bool sendWebRequest( string URIstring)
{
WebRequest webReq = WebRequest.Crea te(URIstring);
webReq.Timeout = 100;
try
{
WebResponse webResp = webReq.GetRespo nse();
return true;
}
catch (WebException e)
{
return false;
}
}
Jun 14 '06 #1
3 2900
Just take away the timeout. I got another sample here:
http://msdn2.microsoft.com/en-us/lib...st(d=ide).aspx

chanmm

"Jonathan@IbisT ek" <jj****@ibistek .com.(D0N0tSp@m )> wrote in message
news:9F******** *************** ***********@mic rosoft.com...
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 several invocations, the debugger
will
actually stop in the catch block.

However, after a number of invocations (variant) the program just hangs on
waiting for the GetResponse(). I would expect the timeout/Webexception to
occur. In monitoring the traffic on the webserver, the requests are
coming
in and the server appears to be responding appropriately.

On an additional note, if I comment out the explicit setting of the
timeout
to 100 ms (from what I read in the WROX book, default is 100,000 anyway),
then the application never steps into the catch block.

bool sendWebRequest( string URIstring)
{
WebRequest webReq = WebRequest.Crea te(URIstring);
webReq.Timeout = 100;
try
{
WebResponse webResp = webReq.GetRespo nse();
return true;
}
catch (WebException e)
{
return false;
}
}

Jun 14 '06 #2
Thanks - but if I actually remove the explicit timeout, it hangs forever.

I played with the numbers and found that 1000000 msec will produce results,
but that is just wayyyy too slow for our purposes. I think I'm going to need
to bypass .NET's web widgets and go the low-level socket route.

Which doesn't make sense, because the response in IE is super fast...?

--
Ibis Tek
www.ibistek.com
912 Pittsburgh Road
Butler, PA 16002
"chanmm" wrote:
Just take away the timeout. I got another sample here:
http://msdn2.microsoft.com/en-us/lib...st(d=ide).aspx

chanmm

"Jonathan@IbisT ek" <jj****@ibistek .com.(D0N0tSp@m )> wrote in message
news:9F******** *************** ***********@mic rosoft.com...
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 several invocations, the debugger
will
actually stop in the catch block.

However, after a number of invocations (variant) the program just hangs on
waiting for the GetResponse(). I would expect the timeout/Webexception to
occur. In monitoring the traffic on the webserver, the requests are
coming
in and the server appears to be responding appropriately.

On an additional note, if I comment out the explicit setting of the
timeout
to 100 ms (from what I read in the WROX book, default is 100,000 anyway),
then the application never steps into the catch block.

bool sendWebRequest( string URIstring)
{
WebRequest webReq = WebRequest.Crea te(URIstring);
webReq.Timeout = 100;
try
{
WebResponse webResp = webReq.GetRespo nse();
return true;
}
catch (WebException e)
{
return false;
}
}


Jun 14 '06 #3
Thus wrote jj****@ibistek. com.(D0N0tSp@m),
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 several invocations, the
debugger will actually stop in the catch block.

However, after a number of invocations (variant) the program just
hangs on waiting for the GetResponse(). I would expect the
timeout/Webexception to occur. In monitoring the traffic on the
webserver, the requests are coming in and the server appears to be
responding appropriately.

On an additional note, if I comment out the explicit setting of the
timeout to 100 ms (from what I read in the WROX book, default is
100,000 anyway), then the application never steps into the catch
block.

bool sendWebRequest( string URIstring)
{
WebRequest webReq = WebRequest.Crea te(URIstring);
webReq.Timeout = 100;
try
{
WebResponse webResp = webReq.GetRespo nse();
return true;
}
catch (WebException e)
{
return false;
}
}


HttpWebResponse is an IDisposable. You have to close it explictly, otherwise
it blocks an underlying TCP connection -- and by default you only get two
persistent connections per server. Use a using block to safely dispose the
response:

using(WebRespon se response = request.GetResp onse()
{
// Process response...
}

Cheers,
--
Joerg Jooss
ne********@joer gjooss.de
Jun 14 '06 #4

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

Similar topics

5
3631
by: C# Learner | last post by:
Is it possible to create a WebRequest instance and, instead of giving it a URI, give it an actual HTTP request? e.g.: GET / HTTP/1.1 Host: www.google.com CR LF CR LF Thanks in advance.
2
9443
by: news.microsoft.com | last post by:
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...
1
4252
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? WebRequest myRequest = WebRequest.Create (inURL); WebResponse myResponse = myRequest.GetResponse();
3
2801
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 this. I receive the PayPal post, but I can't post it back. It's always giving me a Time out. Here's my code:
4
1055
by: SStory | last post by:
Have noticed that my app sometimes hangs in memory. It is a multithreaded app with a main thread and a worker thread but I call something to spin it down on quiting. Any ideas as to why this would be happening? Anyone else had this? Thanks,
0
2211
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 seem to make it work. Please point out the mistakes that I have. Thanks code............. WebRequest = WebRequest.Create(URL) WebRequest.Timeout() = RunInfo.ConnectTimeout WebResponse = WebRequest.GetResponse 'WEBRESPONSE IS A PUBLIC OBJECT...
1
2682
by: Christian Urbanczyk | last post by:
Hello! I have a problem with the Webrequest. I've search everywhere to find an answer but it seems that no one has the the problem before. So i hope somebody can help me here! Following Code: _________________________________________ WebRequest wrq = WebRequest.Create(URL); WebResponse wrs = wrq.GetResponse();
0
1426
by: thomasabcd | last post by:
Hi, During the user's registration I wan't to geo-code an address using localsearchmaps.com/geo. For that purpose I use a webrequest like this: string url = "http://www.localsearchmaps.com/geo/?street=" + StreetNumber + "+" + StreetName + "&city=" + City + "&country=DK&google2=1"; System.Net.WebRequest webRequest =
1
3298
by: Chrace | last post by:
Hi all, I have a problem with with Thread.Join( Timeout ) where the timeout never occurs. I basically need to make a connection to an AS400 box which works fine. Once in a blue moon the AS400 gets a problem and the way this is handled on AS400 is by hanging. If I was to connect directly this would mean my main process would hang as well, so I've spawned a worker thread and used a Thread.Join( Timeout ) to make sure it always returns with...
0
8285
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8706
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8475
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8591
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7304
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6160
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5621
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2709
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.