?
Solved

Timeout problems and general unreliability using msxml

Posted on 2006-06-22
6
Medium Priority
?
457 Views
Last Modified: 2012-05-05
Hi all,

This is turning into a real annoyance. I am trying to use MSXML server objects to load ASP pages into my website template. This works about 80% of the time, really fast and efficient, but the other 20%, the script just times out. I'm connecting to a page within the same web server, so there shouldn't really be any network traffic issues. I've tried with MSXML2.ServerXMLHTTP v 2, 3, 4, and 6 and they all suffer the same unreliability.
I'm using these server side (obviously). I reckon the problem sort of lies with the While....Wend statement but don't really know how to fix it.

My Script is below, though because it is part of a bigger class, some of the variables etc may not be obvious. Need all the stuff to do with cookies and referers due to login post-thru requirements.

Hope you can help!!


Public Sub GetXMLHTTP(vDoc, vType)
      Dim oXMLHTTP, vReferer, vHTTP
      Set oXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
      If Request.ServerVariables("HTTPS") = "on" Then vHTTP = "https://" : Else vHTTP = "http://"

      vReferer = vHTTP & Request.ServerVariables("HTTP_HOST") & Request.ServerVariables("SCRIPT_NAME") & "?" & Request.QueryString
      If len(pCookies) = 0 Then pCookies = "nothing=nothing"

      If CheckTextRequest(pPost) Then pFormPost = pFormPost & pPost
      If CheckTextRequest(CStr(Request.Form)) Then pFormPost = pFormPost & CStr(Request.Form)
            Err.Clear()
            oXMLHTTP.Open "POST", vDoc, False
            oXMLHTTP.SetRequestHeader("Cookie") = "nothing=nothing"
            oXMLHTTP.SetRequestHeader("Cookie") = pCookies
            If CheckTextRequest(pFormPost) Then
                  oXMLHTTP.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
                  oXMLHTTP.SetRequestHeader "Referer", vReferer
                  oXMLHTTP.Send CStr(pFormPost)
            Else
                  oXMLHTTP.Send
            End If      

            While oXMLHTTP.ReadyState <> 4
                  oXMLHTTP.WaitForResponse 1000
            Wend
      
      Dim strHeaders, hArr
      strHeaders = oXMLHTTP.getAllResponseHeaders()

    hArr = split(strHeaders,"Set-Cookie: ")
      For kk = 1 to ubound(hArr)  
          theCookie = left(hArr(kk),instr(hArr(kk),"path=/")-2)  
          pCookies = pCookies & " " & theCookie
      Next
      
      Select Case vType
            Case 1            Set oXMLDoc = oXMLHTTP.ResponseXML
            Case 2            oXMLDocText = replace(oXMLHTTP.responsetext,"../",baseURL)
            Case Else      Set oXMLDoc = oXMLHTTP.ResponseXML
                              oXMLDocText = replace(oXMLHTTP.responsetext,"../",baseURL)
      End Select
      Set oXMLHTTP = Nothing
End Sub

0
Comment
Question by:wildtangent
  • 2
  • 2
4 Comments
 
LVL 14

Expert Comment

by:CyrexCore2k
ID: 16961617
Change This:

oXMLHTTP.Open "POST", vDoc, False

To

oXMLHTTP.Open "POST", vDoc, True
0
 

Author Comment

by:wildtangent
ID: 16962120
Hi, I've tried both of those options but it doesn't seem to make a lot of difference. The errors occur pretty inconclusively randomly, though seem to be less frequent with msxml6 installed.

Cheers tho, any more suggestions?
0
 
LVL 14

Accepted Solution

by:
CyrexCore2k earned 2000 total points
ID: 16962229
Well this part of your code negates the effects:

While oXMLHTTP.ReadyState <> 4
               oXMLHTTP.WaitForResponse 1000
Wend

Basically you need a timeout function of your own.

Function dataRetrieved(xmlHTTP, Location, Cookies, Referer, Postdata)
          dataRetrieved = False
          XMLHTTP.Open "POST", Location, True
          XMLHTTP.SetRequestHeader("Cookie") = "nothing=nothing"
          XMLHTTP.SetRequestHeader("Cookie") = Cookies
          If CheckTextRequest(Postdata) Then
               XMLHTTP.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
               XMLHTTP.SetRequestHeader "Referer", Referer
               XMLHTTP.Send CStr(pFormPost)
          Else
               XMLHTTP.Send
          End If    

          startTime = now()
          While XMLHTTP.ReadyState <> 4 and _
               DateDiff("s", startTime, now()) < 2
          Wend
          If XMLHTTP.ReadyState = 4 Then
               dataRetrieved = True
          End If
End Function

Public Sub GetXMLHTTP(vDoc, vType)
     Dim oXMLHTTP, vReferer, vHTTP, Retries
     Retries = 3

     Set oXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")

     If Request.ServerVariables("HTTPS") = "on" Then vHTTP = "https://" : Else vHTTP = "http://"

     vReferer = vHTTP & Request.ServerVariables("HTTP_HOST") & Request.ServerVariables("SCRIPT_NAME") & "?" & Request.QueryString
     If len(pCookies) = 0 Then pCookies = "nothing=nothing"

     If CheckTextRequest(pPost) Then pFormPost = pFormPost & pPost
     If CheckTextRequest(CStr(Request.Form)) Then pFormPost = pFormPost & CStr(Request.Form)
          Err.Clear()
          Do While Not dataRetrieved(oXMLHTTP, vDoc, pCookies, vReferer, pFormPost) and Retries > 0
               Retries = Retries - 1
          Loop
          If oXMLHTTP.ReadyState <> 4 Then
               Response.Write "Failed to open address."
               Response.End
          End If
     Dim strHeaders, hArr
     strHeaders = oXMLHTTP.getAllResponseHeaders()

    hArr = split(strHeaders,"Set-Cookie: ")
     For kk = 1 to ubound(hArr)  
         theCookie = left(hArr(kk),instr(hArr(kk),"path=/")-2)  
         pCookies = pCookies & " " & theCookie
     Next
     
     Select Case vType
          Case 1          Set oXMLDoc = oXMLHTTP.ResponseXML
          Case 2          oXMLDocText = replace(oXMLHTTP.responsetext,"../",baseURL)
          Case Else     Set oXMLDoc = oXMLHTTP.ResponseXML
                         oXMLDocText = replace(oXMLHTTP.responsetext,"../",baseURL)
     End Select
     Set oXMLHTTP = Nothing
End Sub


The timeout function gives the object two seconds to download the source. You may want to adjust this depending on the size of the pages you're downloading.
0
 

Author Comment

by:wildtangent
ID: 16962376
looks good, will try tomorrow. Thanks!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question