Question Simanteniously Check Which Web Service is Available

babu

New member
Joined
Jun 16, 2020
Messages
3
Programming Experience
1-3
Team

We are having 2 webservice URL's, one pointing to Internet and another is Intranet. How to check both of them simultaneously.

Loop:
                    string[] urls = WebServiceURL.Split(new char[] { ';' });
                    foreach (string url in urls)
                    {
                        if (!IsInternetWorking(url)) continue;

                        return url;
                    }

IsInternetWorking:
        public static bool IsInternetWorking(string serviceUrl)
        {
            try
            {
                using (Service service = new Service())
                {
                    service.PreAuthenticate = true;
                    service.Credentials = CredentialCache.DefaultCredentials;

                    service.Url = serviceUrl;
                    service.AuthenticationUser();
                    return true;
                }
            }
            catch (Exception ex)
            {
                return false;
            }
        }
 
Use parallelism. It seems like parallel.foreach() may work.
 

Latest posts

Back
Top Bottom