0

I have developed an app using Xamarin.Forms cross platform app. I am using following code to check whether my server is available or not.

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            request.Timeout = 8000;
            request.Method = "HEAD";

            try
            {
                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                {
                    if (response == null || response.StatusCode != HttpStatusCode.OK)
                    {
                        return false;
                    }
                    else
                    {
                        return true;
                    }

                }
            }
            catch (WebException)
            {
                return false;
            }

Above code throwing TimeOut Exception in our client's wifi setup, but it is working fine in our wifi. When client is using LTE, then TimeOut exception is not happening. Even pinging Google also giving TimeOut exception.

I tried setting KeepAlive, TimeOut.Infinite and few other things given in other SO threads, related to this issue. Changed pinging code also, nothing is working.

What is going wrong here?

Anything needs to enabled in wifi settings?

subha
  • 1,050
  • 2
  • 15
  • 42
  • Hard to say. Consider reporting the exception to yourself in the `catch` clause to get more information. – Thibault D. Aug 18 '16 at 08:51
  • @ThibaultD. Updated my question, do you have any idea how to fix above error? – subha Aug 18 '16 at 08:56
  • `NameResolutionFailure` is quite frequent for me too. Nothing unusual really, if somehow the connectivity is bad then the DNS resolution will be the first step to fail thus the error message. In some countries, mobile networks have expanded faster than wired networks (networks behind the WiFi I guess) which could explain more error rates there. – Thibault D. Aug 18 '16 at 08:59
  • But we can't answer your question for sure without getting the information that is discarded in your `catch` clause. I would really recommend you to send an update containing better error handling. You could for example report the exception using Xamarin Insights (or hockey app). Only then you will be able to get statistics about what is failing. – Thibault D. Aug 18 '16 at 09:00
  • I am intentionally returning false, without logging the exception, because my exception logging is happening in server using webservice. Here it can't even connect with server, hence it will get stuck indefinitely there. – subha Aug 18 '16 at 09:12
  • But obviously, you need client-side logging too. Because the answer from the server may never reach the client. Or the call from the client may never reach the server (which is the issue you are investigating, right?). Most insights libraries won't try to communicate in the catch clause, they'll just store an exception report and send it to your reporting backend as soon as they can. There is no other way for you to find out about what's happening in this `catch` clause. There are no fortune-tellers on SO. There's so many plausible reasons for a network call to fail. – Thibault D. Aug 18 '16 at 10:20
  • @ThibaultD. I have found, TimeOut exception is happening. I tried keep live and few other properties, nothing works. – subha Aug 18 '16 at 11:19
  • @ThibaultD.Could u please tell me one thing, problem is in code or wifi setup? No matter what I try always getting TimeOut error from client's wifi, but my office wifi is working fine, I couldn't ping even google also. – subha Aug 18 '16 at 12:03

0 Answers0