Created
May 9, 2011 16:58
-
-
Save benjamine/962875 to your computer and use it in GitHub Desktop.
Revisions
-
Benjamín Eidelman revised this gist
May 9, 2011 . 2 changed files with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ Cscript webservicetest.js pause This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ processSend(); function processSend(attempts) { -
Benjamín Eidelman created this gist
May 9, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,53 @@ processSend(); function processSend(attempts) { var xmlhttp = new ActiveXObject("MSXML2.ServerXMLHTTP"); var data = '{"prefixText":"iron","count":5,"contextKey":"Nw,ct,en"}'; var svcurl = "http://localhost/website/services/itemtablewebsvc.asmx"; var svcmethod = "GetAutoCompleteItems"; xmlhttp.open("POST", svcurl + "/" + svcmethod, false); xmlhttp.setRequestHeader("Content-Type", "application/json; charset=utf-8"); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4) { dataReceived(xmlhttp); } }; xmlhttp.setTimeouts(5000, 60000, 10000, 10000); try { xmlhttp.send(data); } catch (err) { WScript.Echo("Error:" + err.description + "\n"); if (!attempts || attempts < 5) { WScript.Echo("Retry " + ((attempts || 0) + 1) + "..."); processSend((attempts || 0) + 1); } else { WScript.Echo("Too many attemtps."); } } } function dataReceived(xmlhttp) { var response; if (xmlhttp.responseXML.parseError.errorCode != 0) { response = xmlhttp.responseText & " " & xmlhttp.responseXML.parseError.reason; WScript.Echo("Response: " + response); } else { // response = xmlhttp.responseXML.getElementsByTagName("string")(0).childNodes(0).text; // response = xmlhttp.responseXML; response = xmlhttp.responseText; WScript.Echo("Response:\n" + response + "\n"); var data = eval("(" + xmlhttp.responseText + ")"); WScript.Echo("Data:"); for (var i = 0; i < data.d.length; i++) { WScript.Echo(i + ":" + eval("(" + data.d[i] + ")").First); } } }