locked
Exception occure RRS feed

  • Question

  • Hi All,

    I am add the web reference of wcf web service in to windwo mobile application.

    when i am call the wcf web service some time give "Could not establish connection to network".  I think it is due to internet problem.

    so i want if internet not present then not call the web service.

    How it do that

    plz help me.

     

    --

    Thanks

     

     

    Tuesday, March 30, 2010 9:06 AM

Answers

  • Hi Dhiraj,

     

    I Hope method below will help you.  It returns true if connection available else return false

    public static bool IsNetworkAvailable()
            {
                String objUrl= "http://www.dhiraj.com/";
                bool connected = false;
                HttpWebRequest request = null;
                HttpWebResponse response = null;
                try
                {
                    request = (HttpWebRequest)WebRequest.Create(objUrl);
                    response = (HttpWebResponse)request.GetResponse();
                    request.Abort();
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        connected = true;
                    }
                }
                catch (WebException ex)
                {
                    connected = false;
                }
                finally
                {
                     if (response != null)
                        response.Close();
                }

                return connected;
            }

     

     

    Have Happy Coding. :)


    Thanks, Mohsin Shaikh. If you find my post is helpful for you then mark it as answer.
    Tuesday, March 30, 2010 9:52 AM