Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

xmlhttp timeout, synchronous behaviour from an asynchronous call

1 view
Skip to first unread message

Michael Lawless

unread,
Dec 3, 2001, 10:31:34 AM12/3/01
to
I need to use msxml.xmlhttp within javascript within an IE5 Behavior.
This needs to be able to make a call to either a SOAP service or an
ASP page etc and process the returned XML....easy....but I need to be
able to post the data and then only wait so long for either the call
to timeout or the document to come back.

As I understand it, xmlhttp does not support timeouts( am i correct in
this?). As I cannot user XMLHTTPServer I have attempted to use xmlhttp
asynchronously:

xmlhttp = new ActiveXObject("Msxml2.XMLHttp");
xmlhttp.Open("POST", sURL ,True);
xmlhttp.onreadystatechange= HandleStateChange;
xmlhttp.Send(xmldoc);

which would be fine, but I need some way of stopping execution
returning to the calling page/function until either an allotted time
has passed or xmlhttp.readyState == 4, so that it appears to be
synchronous....

Does anyone have ideas as to a solutin or what I have missed?

David Carnes

unread,
Dec 3, 2001, 1:29:02 PM12/3/01
to
Michael:
Here's a snippet from an Access 97 app. Code is in VBA I am displaying a
progress bar that slowly increments until the request is finished (eye candy
for the users) or times out after sixty seconds. Haven't had to do this in
an ASP page, so I'm not sure how it'll work. Might be enough to get you
started.

Ciao,
Dave


With xmlHTTP
.Open "POST", g_strWebServer & "/download.asp?" & intA, True,
g_strUserName, g_strPassword
.setRequestHeader "Content-Type", "text/xml"
.send

intSecondCount = 0
sTime = Timer
Me.ProgressBar.Value = 0
Do Until intSecondCount > 60
If .readyState = 4 Then
Exit Do
End If
If Timer > sTime + 1 Then
Me.ProgressBar.Value = Me.ProgressBar + 1.6
intSecondCount = intSecondCount + 1
sTime = Timer
End If
Loop
Me.ProgressBar.Value = 100

If .readyState <> 4 Then
MsgBox "No response from server while requesting data. Please try
again later", _
vbExclamation, _
"Operation timed out"
GoTo CloseConnection
End If
...
...
...
End With


Michael Lawless

unread,
Dec 4, 2001, 7:15:31 AM12/4/01
to
Thanks David, but I cannot use this approach unless there is something
similar available to IE5.5 that I can be confident will be present on
all installations....and currently I cannot find anything but it is a
nice work around for use in VB & VBA with Forms etc...

Any ideas?


"David Carnes" <dav...@NOSPAMbrandtinfo.com> wrote in message news:<uDiq0hCfBHA.2144@tkmsftngp02>...

David Carnes

unread,
Dec 4, 2001, 2:06:53 PM12/4/01
to
No concrete ideas, as of yet. I am starting to work on a web-based
application in which I am planning to use a little XML. After re-reading
your original post I can see that I may run into the same issue. I'll check
with some of my JavaScript junkie friends and see if there's anything that
might work for you. If not, I'll try working something out myself. I'll
keep you posted. I'm trying to finalize my Oracle database design today;
with luck I'll be back to coding by the end of the week. I'll see if I
can't work something in soon. I am hampered a bit by a lack of experience
in web development, but then I'm also glad that I am able to break the
Access 97 mold that I've had to work in for the past year. I does what they
pays me for.

Ciao,
Dave

Mathew

unread,
Dec 5, 2001, 5:10:12 PM12/5/01
to
Use the following object and the method
Set g_oHtpprequest = New MSXML2.ServerXMLHTTP
after the send method call this method.
g_oHtpprequest.waitForResponse 20
On the server the serverXMLHttp object should be used .
This object is Thread safe and more Efficient..
Mathew
>.
>

Michael Lawless

unread,
Dec 6, 2001, 4:56:10 AM12/6/01
to
Thanks Mathew,

Unfortunately I am definately client side and consequently cannot be
confident that ServerXMLHTTP will work as it is said in the MS
documentation that 'Supported platforms include Microsoft Windows®
2000, or Microsoft Windows NT® 4.0 with Microsoft Internet Explorer
5.01 (or later) installed. ServerXMLHTTP fails on other platforms,
such as Microsoft Windows 95 or Microsoft Windows 98.' ( from MS XML
3.0 - XML Reference )....and there is every liklehood that 95 & 98
will be potential client platforms...


"Mathew" <mut...@MegapathDsl.net> wrote in message news:<06dd01c17dd9$9c1176d0$35ef2ecf@TKMSFTNGXA11>...

Karthik Ravindran

unread,
Dec 7, 2001, 11:22:21 AM12/7/01
to

Hello,

The send method of the XMLHTTP object is synchronous or asynchronous,
depending on the value of the bAsync parameter in the open method call. If
open is called with bAsync == False, this call does not return until the
entire response is received or the protocol stack times out. If open is
called with bAsync == True, this call returns immediately.

WinInet is the protocol stack used by the XMLHTTP object. Hence if the Send
method is executed synchronously (async == False), the call will timeout
only after the WinHTTP timeout interval (5 minutes).

I can see one way to address your requirement. This is described below:

a) Capture and store the time before executing the send method in a script
variable

b) Instantiate a DHTML Timer (window.setInterval) and set it to execute a
user defined function after a specific amount of time has elapsed (The
number of minutes for which you want to wait for the response)

c) Execute the send method asynchronously and set the onreadystatechange
property of the XMLHTTP object to reference a callback procedure. In the
callback procedure check the readystate of the XMLHTTP object. If it is
equal to 4 and the timer interval has not elapsed, then it would indicate
that the response was obtained within the required time. If this is the
case then cancel the timer (window.clearInterval) and process the retrieved
result.

d) In the timer procedure (Will execute only when the amount of time for
which you wish to wait has elapsed) call the abort method of the XMLHTTP
object to cancel the request that you executed.

You will need to reference the IE DHTML MSDN documentation on the
setInterval and clearInterval methods for information and code samples on
how to use them.

Thanks

This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure? For information about the Strategic Technology Protection
Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.com/security.

0 new messages