3

In a VBScript, having instantiated:

On Error Resume Next
Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")

I am doing a sequence of synchronous HTTP PUTs like this:

xmlhttp.open "PUT", TheURL, False
xmlhttp.setRequestHeader "Content-type","application/json"
xmlhttp.setRequestHeader "Accept","application/json"
xmlhttp.send TheXML
If xmlhttp.readyState <> 4 Then
    xmlhttp.waitForResponse 1
End If
If xmlhttp.status >= 300 Then
    WScript.Echo "Failure: " & TheURL & "<BR>" & TheXML
End If

After a few I check for an error and discover:

-2147483638: The data necessary to complete this operation is not yet available.

Given that I have made these using synchronous calls, how is this possible? How can I avoid this error?

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
feetwet
  • 3,248
  • 7
  • 46
  • 84
  • 2
    While your *calls* are synchronous, the server-side operations triggered by these calls may not be. – Ansgar Wiechers Sep 18 '16 at 16:40
  • 1
    @AnsgarWiechers - Right, but doesn't the `xmlhttp.waitForResponse` guarantee I wait for them to complete? And even if they had not returned, is the `xmlhttp` object not available for ongoing use as described without raising this error? – feetwet Sep 18 '16 at 16:52
  • 2
    As [documented](https://msdn.microsoft.com/en-us/library/ms765535%28v=vs.85%29.aspx), `waitForResponse` is for asynchronous `send()` operations. You're doing a synchronous `send()`, so `waitForResponse` doesn't do anything in your case. If the application on the server returns immediately and runs whatever it's supposed to do asynchronously in the background I don't think there's anything you can do on the client-side but try and wait. – Ansgar Wiechers Sep 18 '16 at 17:05
  • @AnsgarWiechers: I suppose I have no need to use the ServerXMLHTTP object. Using the MSXML2.XMLHTTP object would avoid this? – feetwet Sep 18 '16 at 17:08
  • 1
    There's no telling without knowing what the server-side is actually doing, but I'd doubt it. Currently your question boils down to: "I'm calling some functions (won't tell you what they're doing), and sometime later I get this error. What's wrong?" – Ansgar Wiechers Sep 18 '16 at 18:05
  • @AnsgarWiechers is right, we need more information to help. At the moment it's all just guess work *(educated guess work but guess work nonetheless)*. Without some indication of what the server-side is doing we can't help much further. Have you tried `xmlhttp.open "PUT", TheURL, True` so you are making a async request? – user692942 Sep 19 '16 at 10:46
  • An example of a `async` callback here - http://stackoverflow.com/a/6712069/692942 – user692942 Sep 19 '16 at 10:55
  • @Lankymart: Well I confirmed that the error can be produced using async calls. But that's the only time I can imagine it making sense. If the `xmlhttp` object says `readyState = 1`, then why can't I get its `status`? I.e., how else would I determine that datum is not yet available? – feetwet Sep 19 '16 at 18:54

1 Answers1

0

Change this line

Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")

To

Set xmlhttp = CreateObject("Msxml2.ServerXMLHTTP.6.0")

And add this:

xmlhttp.setTimeouts 15000, 15000, 15000, 15000
Zvi Redler
  • 1,708
  • 1
  • 18
  • 29