Syncronous call to webservice

Last post 07-04-2007 8:58 AM by KaziManzurRashid. 3 replies.

Sort Posts:

  • Syncronous call to webservice

    06-29-2007, 5:18 AM
    • Member
      3 point Member
    • Julito
    • Member since 06-29-2007, 8:27 AM
    • Posts 5

    I am implementing a control inherited from System.Web.UI.WebControls.BaseValidator,I want that the control perfoms client side validation against a web service in the evaluationfunction of the control.  I already do the script and web service registration and the call to the webservice inside the call to the evaluationfunction, the problem is that this call is asyncronous. There is a way to do this call syncronous or to wait to the callback function of the webservice?.

  • Re: Syncronous call to webservice

    07-04-2007, 2:43 AM
    Answer

     Hi,

    To call a web service synchronously, you can use XmlHttpRequest object, and specify it to send request synchronously. For example:

     UserName:<input id="Text2" type="text" />
        <input id="Button1" type="button" value="Client Check" onclick="CheckUserExist();" /><br />
        Result:<input id="Text1" type="text" />
    <script type="text/javascript">
    var client;

    function CheckUserExist()
    {
        if (window.XMLHttpRequest)
        {
            client = new XMLHttpRequest();       
        }
        else
        {
            if (window.ActiveXObject)
            {
                client = new ActiveXObject("Microsoft.XMLHTTP");
            }
        }
       
       // client.onreadystatechange = handler;
        client.open("POST", "http://localhost/Samples/MyService.asmx/IsUserExist", false); // This parameter sepcifies to request synchronously
        client.setrequestheader("Content-type", "application/x-www-form-urlencoded");
        client.send("userName=" + document.getElementById("Text2").value);
        alert(client.responseText);
    }

     

     

    [WebMethod]
        public string IsUserExist()
        {
            System.Threading.Thread.Sleep(3000);
            return "Hello World";
        }

     

    Hope this helps. 

  • Re: Syncronous call to webservice

    07-04-2007, 7:29 AM
    • Member
      3 point Member
    • Julito
    • Member since 06-29-2007, 8:27 AM
    • Posts 5

    Thanks a lot.

  • Re: Syncronous call to webservice

    07-04-2007, 8:58 AM
    • Contributor
      4,792 point Contributor
    • KaziManzurRashid
    • Member since 03-09-2003, 11:04 AM
    • Dhaka, Bangladesh
    • Posts 882
    Long Live .NET
    Kazi Manzur Rashid (Amit)
    _________________________
    Web: http //dotnetshoutout.com
    Blog: http://weblogs.asp.net/rashid
    Twitter: http://twitter.com/manzurrashid
Page 1 of 1 (4 items)