Velocity Reviews - Computer Hardware Reviews

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

Thread Tools

HttpWebRequest and "The operation has timed-out"

Posts: n/a

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

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"),
End If

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

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 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,
Reply With Quote
Posts: n/a
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

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

Solution found thanks to:

Reply With Quote

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