[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Timeout problems and general unreliability using msxml

Posted on 2006-06-22
6
Medium Priority
?
454 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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
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/…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

656 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