?
Solved

Timeout problems and general unreliability using msxml

Posted on 2006-06-22
6
Medium Priority
?
448 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
6 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

743 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