Solved

Timeout problems and general unreliability using msxml

Posted on 2006-06-22
6
443 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 500 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

Technology Partners: 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 recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

695 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