K
Kapil Shah
Hello Everybody,
I am trying to develop code to use the correct version of XMLHTTP and
use it to send SOAP envelope to WebService . The code works fine for the
first time but then after that I get an error that objHttp(XMLHTTP) is
null or not an object. Pls guide where I am going wrong?
Rahil
<script language="jscript">
var objXmlDoc;
var objHttp;
var bDocument=false;
var bHttp= false;
var interval=1000;
var aszHttpProgIDs;
function getWebServiceResultsAfterInit()
{
// Must be using IE for this to work
if(window.ActiveXObject)
{
// Create the XML Document object
var aszDocumentProgIDs=[ "MSXML2.DOMDocument.4.0",
"MSXML2.DOMDocument.3.0",
"MSXML2.DOMDocument",
"MSXML.DOMDocument",
"Microsoft.XmlDom"];
for(var k=0; !bDocument && k<aszDocumentProgIDs.length; k++)
{
if (bDocument==false)
{
try{
objXmlDoc=new ActiveXObject(aszDocumentProgIDs[k]);
bDocument=true;
if(bDocument==true)
{
alert(bDocument);
}
}
catch (objException)
{
// error handling elided for clarity
}
}// End of if(bDocument==false)
} // End of For Loop
try
{
if(bDocument==false)
{
throw "MSXML not found on your computer.";
return;
}
} // End of Try
catch(er)
{
if(er=="MSXML not found on your computer.")
alert("Please contact system Administrator");
} //End of catch
init();
} // End of If statement
} // End of function
function getxmlhttp()
{
if(window.ActiveXObject)
{
aszHttpProgIDs=["MSXML2.XMLHTTP.4.0",
"MSXML2.XMLHTTP.3.0",
"MSXML2.XMLHTTP",
"Microsoft.XMLHTTP"];
for ( var i=0;!bHttp && i<aszHttpProgIDs.length; i++)
{
if(bHttp==false)
{
try
{
objHttp= new ActiveXObject(aszHttpProgIDs);
bHttp=true;
if(bHttp==true)
{
alert(bHttp);
}
}
catch (objException)
{
// error handling elided for clarity
}
}
}// End of For Loop
try
{
if(bHttp==false)
{
throw "MSXML not found on your computer.";
return;
}
} // End of Try
catch(er)
{
if(er=="MSXML not found on your computer.")
alert("Please contact system Administrator");
} //End of catch
go();
}// End of window.ActiveXObject
} // End of Function
function init()
{
sEnvelope= " <soap:Envelope
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">";
sEnvelope += "<soap:Body>";
sEnvelope += "<GetUserQueue
xmlns=\"http://tempuri.org//PBXService\">";
sEnvelope += " <userName>kshah</userName>";
sEnvelope += " <phoneNumber>kshah</phoneNumber>";
sEnvelope += " <remoteYN>N</remoteYN>";
sEnvelope += " </GetUserQueue>";
sEnvelope += " </soap:Body>";
sEnvelope += "</soap:Envelope>";
go();
}
function go(){setTimeout(callWebService,interval);}
function callWebService()
{
getxmlhttp() ;
objHttp.onreadystatechange = objHttp_change;
objHttp.open("Post","http://ecpcrm/services/pbxservice.asmx");
objHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
objHttp.setRequestHeader("SOAPAction",
"http://tempuri.org//PBXService/GetUserQueue");
objHttp.send(sEnvelope);
}
function objHttp_change()
{
if (objHttp.readystate != 4)
return;
// Try to parse the XML string into DOM object
objXmlDoc.loadXML(objHttp.responseText);
alert(objHttp.responseText);
test.innerText =
objXmlDoc.selectSingleNode("//GetUserQueueResult").text;
alert(test.innerText);
objHttp = null;
go();
}
</script>
</head>
<body onload= getWebServiceResultsAfterInit() >
<form id="Form1" method="post" runat="server">
</form>
<span id="test"></span>
</body>
</html>
I am trying to develop code to use the correct version of XMLHTTP and
use it to send SOAP envelope to WebService . The code works fine for the
first time but then after that I get an error that objHttp(XMLHTTP) is
null or not an object. Pls guide where I am going wrong?
Rahil
<script language="jscript">
var objXmlDoc;
var objHttp;
var bDocument=false;
var bHttp= false;
var interval=1000;
var aszHttpProgIDs;
function getWebServiceResultsAfterInit()
{
// Must be using IE for this to work
if(window.ActiveXObject)
{
// Create the XML Document object
var aszDocumentProgIDs=[ "MSXML2.DOMDocument.4.0",
"MSXML2.DOMDocument.3.0",
"MSXML2.DOMDocument",
"MSXML.DOMDocument",
"Microsoft.XmlDom"];
for(var k=0; !bDocument && k<aszDocumentProgIDs.length; k++)
{
if (bDocument==false)
{
try{
objXmlDoc=new ActiveXObject(aszDocumentProgIDs[k]);
bDocument=true;
if(bDocument==true)
{
alert(bDocument);
}
}
catch (objException)
{
// error handling elided for clarity
}
}// End of if(bDocument==false)
} // End of For Loop
try
{
if(bDocument==false)
{
throw "MSXML not found on your computer.";
return;
}
} // End of Try
catch(er)
{
if(er=="MSXML not found on your computer.")
alert("Please contact system Administrator");
} //End of catch
init();
} // End of If statement
} // End of function
function getxmlhttp()
{
if(window.ActiveXObject)
{
aszHttpProgIDs=["MSXML2.XMLHTTP.4.0",
"MSXML2.XMLHTTP.3.0",
"MSXML2.XMLHTTP",
"Microsoft.XMLHTTP"];
for ( var i=0;!bHttp && i<aszHttpProgIDs.length; i++)
{
if(bHttp==false)
{
try
{
objHttp= new ActiveXObject(aszHttpProgIDs);
bHttp=true;
if(bHttp==true)
{
alert(bHttp);
}
}
catch (objException)
{
// error handling elided for clarity
}
}
}// End of For Loop
try
{
if(bHttp==false)
{
throw "MSXML not found on your computer.";
return;
}
} // End of Try
catch(er)
{
if(er=="MSXML not found on your computer.")
alert("Please contact system Administrator");
} //End of catch
go();
}// End of window.ActiveXObject
} // End of Function
function init()
{
sEnvelope= " <soap:Envelope
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">";
sEnvelope += "<soap:Body>";
sEnvelope += "<GetUserQueue
xmlns=\"http://tempuri.org//PBXService\">";
sEnvelope += " <userName>kshah</userName>";
sEnvelope += " <phoneNumber>kshah</phoneNumber>";
sEnvelope += " <remoteYN>N</remoteYN>";
sEnvelope += " </GetUserQueue>";
sEnvelope += " </soap:Body>";
sEnvelope += "</soap:Envelope>";
go();
}
function go(){setTimeout(callWebService,interval);}
function callWebService()
{
getxmlhttp() ;
objHttp.onreadystatechange = objHttp_change;
objHttp.open("Post","http://ecpcrm/services/pbxservice.asmx");
objHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
objHttp.setRequestHeader("SOAPAction",
"http://tempuri.org//PBXService/GetUserQueue");
objHttp.send(sEnvelope);
}
function objHttp_change()
{
if (objHttp.readystate != 4)
return;
// Try to parse the XML string into DOM object
objXmlDoc.loadXML(objHttp.responseText);
alert(objHttp.responseText);
test.innerText =
objXmlDoc.selectSingleNode("//GetUserQueueResult").text;
alert(test.innerText);
objHttp = null;
go();
}
</script>
</head>
<body onload= getWebServiceResultsAfterInit() >
<form id="Form1" method="post" runat="server">
</form>
<span id="test"></span>
</body>
</html>