private static bool IsCategoryValidV2(string category)
        {
            //Test V2 API
            //It may take a while until the category is loaded on server
            bool returnvalue = true;

            for (int i = 0; i < 3; i++)
            {
                try
                {
                    string headerValue = GetHeaderValue();
                    var    bind        = new BasicHttpBinding {
                        Name = "BasicHttpBinding_LanguageService"
                    };
                    var epa = new EndpointAddress(EndPointAddress.Replace("https", "http") + "/V2/soap.svc");
                    LanguageServiceClient client = new LanguageServiceClient(bind, epa);
                    client.Translate(headerValue, "Test", "en", "fr", "text/plain", category, string.Empty);
                    returnvalue = true;
                    break;
                }
                catch (Exception e)
                {
                    string error = e.Message;
                    returnvalue = false;
                    Thread.Sleep(1000);
                    continue;
                }
            }
            return(returnvalue);
        }
        /// <summary>
        /// Call once to initialize the static variables
        /// </summary>
        public static void Initialize()
        {
            LoadCredentials();

            //Inspect the given Azure Key to see if this is host with appid auth
            string[] AuthComponents = _AzureKey.Split('?');
            if (AuthComponents.Length > 1)
            {
                EndPointAddress = AuthComponents[0];
                string[] appidComponents = AuthComponents[1].ToLowerInvariant().Split('=');
                if (appidComponents[0] == "appid")
                {
                    authMode = AuthMode.AppId;
                    appid    = appidComponents[1];
                }
                else
                {
                    return;
                }
            }
            try { if (!IsTranslationServiceReady())
                  {
                      return;
                  }
            }
            catch { return; }
            var bind = new BasicHttpBinding {
                Name = "BasicHttpBinding_LanguageService"
            };
            var epa = new EndpointAddress(EndPointAddress.Replace("https:", "http:") + "/V2/soap.svc");   //for some reason GetLanguagesForTranslate doesn't work with SSL.
            LanguageServiceClient client = new LanguageServiceClient(bind, epa);
            string headerValue           = GetHeaderValue();

            string[] languages     = client.GetLanguagesForTranslate(headerValue);
            string[] languagenames = client.GetLanguageNames(headerValue, Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName, languages, false);
            for (int i = 0; i < languages.Length; i++)
            {
                if (!AvailableLanguages.ContainsKey(languages[i]))
                {
                    AvailableLanguages.Add(languages[i], languagenames[i]);
                }
            }
            client.Close();
        }
        /// <summary>
        /// Check if the Translation service is ready to use, with a valid client ID and secret
        /// </summary>
        /// <returns>true if ready, false if not</returns>
        public static bool IsTranslationServiceReady()
        {
            switch (authMode)
            {
            case AuthMode.Azure:
                try
                {
                    AzureAuthToken authTokenSource = new AzureAuthToken(_AzureKey);
                    string         headerValue     = authTokenSource.GetAccessToken();
                    var            bind            = new BasicHttpBinding {
                        Name = "BasicHttpBinding_LanguageService"
                    };
                    var epa = new EndpointAddress(EndPointAddress.Replace("https:", "http:") + "/V2/soap.svc");
                    LanguageServiceClient client = new LanguageServiceClient(bind, epa);
                    string[] languages           = new string[1];
                    languages[0] = "en";
                    client.GetLanguageNames(GetHeaderValue(), Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName, languages, false);
                }
                catch { return(false); }
                break;

            case AuthMode.AppId:
                try
                {
                    var bind = new BasicHttpBinding {
                        Name = "BasicHttpBinding_LanguageService"
                    };
                    var epa = new EndpointAddress(EndPointAddress.Replace("https:", "http:") + "/V2/soap.svc");
                    LanguageServiceClient client = new LanguageServiceClient(bind, epa);
                    string[] languages           = new string[1];
                    languages[0] = "en";
                    client.GetLanguageNames(GetHeaderValue(), Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName, languages, false);
                }
                catch { return(false); }
                break;

            default:
                return(false);
            }
            return(true);
        }