Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > HttpWebRequest and "The operation has timed-out"

Reply
Thread Tools

HttpWebRequest and "The operation has timed-out"

 
 
Manso
Guest
Posts: n/a
 
      10-26-2005
Hi,

I have an ASP.NET 1.1 app running on Windows XP SP2 that is requesting
information from a WebService which works just fine. Another part of the app
is doing a server-side post to antoher system using HttpWebRequest. Code as
follows:

==============================
Dim objWebReq As HttpWebRequest
Dim objStream As Stream
Dim strData As String
Dim arrPostArray As Byte()

'Construct form data
strData = "field1=x&field2=y"
arrPostArray = System.Text.Encoding.ASCII.GetBytes(strData)

objWebReq = WebRequest.Create("http://www.xx.yy/page.aspx")
objWebReq.Method = "POST"
objWebReq.KeepAlive = False
objWebReq.ContentType = "application/x-www-form-urlencoded"
objWebReq.ContentLength = arrPostArray.Length

'Maintain between state calls
If Not Session("comsess") Is Nothing Then
objWebReq.CookieContainer = CType(Session("comsess"),
System.Net.CookieContainer)
End If

objStream = objWebReq.GetRequestStream
objStream.Write(arrPostArray, 0, arrPostArray.Length)
objStream.Close
==============================

This works fine but suddenly subsequent WebService calls bombs out with:

==============================
System.Net.WebException: The operation has timed-out.

Line 47: Dim results() As Object = Me.Invoke("RetrieveData", New Object()
{strArg1, strArg2})
==============================

Feels like something doesn't get closed in the HttpWebRequest and clogs up
the following WebRequest call. I can't find any method to close it with. KB
http://support.microsoft.com/kb/821268 is talking about this problem but it
happens after just one post and it feels like something else goes wrong. The
reason we're using HttpWebRequest instead of WebClient is because WebClient
doesn't support CookieContainer.

I'm really grateful for any and all help with this issue.

Many thanks,
Manso
 
Reply With Quote
 
 
 
 
Manso
Guest
Posts: n/a
 
      10-26-2005
Ok, I found the solution (which wasn't obvious). The problem is that I didn't
take care of and closed the response stream. Adding these lines:

objWebRes = objWebReq.GetResponse
objWebRes.Close

at the end made it work. The confusing thing here is that many of the
examples in the HttpWebRequest documentation are faulty, e.g.

http://msdn.microsoft.com/library/de...asp?frame=true

Solution found thanks to:

http://blogs.msdn.com/feroze_daud/ar.../21/61400.aspx

Regards,
Manso
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Boolean operation and arithmetic operation Buzz Lightyear C++ 10 08-12-2009 01:27 PM
HttpWebRequest The operation has timed-out =?Utf-8?B?TWFuc28=?= ASP .Net 2 07-25-2008 07:02 AM
Does bit operation always work more efficiently than math operation? david ullua C Programming 13 03-01-2006 11:02 PM
HttpWebRequest Operation Has Timed Out After Numerous Requests #2 =?Utf-8?B?QWxleCBQYXBhZGltb3VsaXM=?= ASP .Net 0 01-30-2006 09:05 PM
HttpWebRequest Operation Has Timed Out After Numerous Requests =?Utf-8?B?QWxleCBQYXBhZGltb3VsaXM=?= ASP .Net 0 01-29-2006 05:39 PM



Advertisments