HttpWebRequest and "The operation has timed-out"

Discussion in 'ASP .Net Web Services' started by Manso, Oct 26, 2005.

  1. Manso

    Manso Guest

    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
    Manso, Oct 26, 2005
    #1
    1. Advertising

  2. Manso

    Manso Guest

    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/d...HttpWebRequestClassMethodTopic.asp?frame=true

    Solution found thanks to:

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

    Regards,
    Manso
    Manso, Oct 26, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    0
    Views:
    3,969
  2. =?Utf-8?B?S2h1cnJhbSBJc2hmYXEgUmF0aG9y?=

    Operation has timed out in ASP.Net Application

    =?Utf-8?B?S2h1cnJhbSBJc2hmYXEgUmF0aG9y?=, Sep 2, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    4,227
    =?Utf-8?B?S2h1cnJhbSBJc2hmYXEgUmF0aG9y?=
    Sep 2, 2004
  3. =?Utf-8?B?TWFuc28=?=

    HttpWebRequest The operation has timed-out

    =?Utf-8?B?TWFuc28=?=, Oct 26, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    16,715
    Nyoti
    Jul 25, 2008
  4. =?Utf-8?B?QWxleCBQYXBhZGltb3VsaXM=?=

    HttpWebRequest Operation Has Timed Out After Numerous Requests

    =?Utf-8?B?QWxleCBQYXBhZGltb3VsaXM=?=, Jan 29, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    532
    =?Utf-8?B?QWxleCBQYXBhZGltb3VsaXM=?=
    Jan 29, 2006
  5. =?Utf-8?B?QWxleCBQYXBhZGltb3VsaXM=?=

    HttpWebRequest Operation Has Timed Out After Numerous Requests #2

    =?Utf-8?B?QWxleCBQYXBhZGltb3VsaXM=?=, Jan 30, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    2,494
    =?Utf-8?B?QWxleCBQYXBhZGltb3VsaXM=?=
    Jan 30, 2006
Loading...

Share This Page