Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2005

Tip: Looking for answers? Try searching our database.

HttpWebRequest The operation has timed-out

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Manso - 26 Oct 2005 21:38 GMT
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 WebService 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
Manso - 26 Oct 2005 22:34 GMT
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/default.asp?url=/library/en-us/cpref/html/frlr
fSystemNetHttpWebRequestClassMethodTopic.asp?frame=true


Solution found thanks to:

http://blogs.msdn.com/feroze_daud/archive/2004/01/21/61400.aspx

Regards,
Manso

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.