XMLHTTP

Discussion in 'ASP .Net' started by Kapil Shah, Aug 10, 2004.

  1. Kapil Shah

    Kapil Shah Guest

    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>



    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Kapil Shah, Aug 10, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. S. Justin Gengo

    Re: Classic ASP to ASP.Net XMLHTTP

    S. Justin Gengo, Aug 27, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    523
    S. Justin Gengo
    Aug 27, 2003
  2. Paul
    Replies:
    0
    Views:
    511
  3. Matt
    Replies:
    3
    Views:
    558
  4. Martin Feuersteiner

    XMLHTTP component

    Martin Feuersteiner, Apr 28, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,306
    Martin Feuersteiner
    Apr 28, 2004
  5. yawnmoth

    Msxml*.XMLHTTP vs. Microsoft.XMLHTTP

    yawnmoth, Nov 7, 2006, in forum: Javascript
    Replies:
    11
    Views:
    400
    Matt Kruse
    Nov 9, 2006
Loading...

Share This Page