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.






    Tuesday, March 30, 2010 9:06 AM


  • 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;
                    request = (HttpWebRequest)WebRequest.Create(objUrl);
                    response = (HttpWebResponse)request.GetResponse();
                    if (response.StatusCode == HttpStatusCode.OK)
                        connected = true;
                catch (WebException ex)
                    connected = false;
                     if (response != null)

                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