Exemple #1
0
        public WebClient GetApiWebClient(string baseUri, string username, string password)
        {
            if (apiWebClient == null || apiWebClient.BaseAddress != baseUri || apiWebClientAuth.Item1 != username || apiWebClientAuth.Item2 != password)
            {
                apiWebClient = null;

                var client = new WebClientEx();
                client.BaseAddress = baseUri;

                var auth = new AuthenticationRequest
                {
                    Username = username,
                    Password = password
                };

                try
                {
                    string authResponse = this.ExecuteOnJsonServiceClient(client, auth);
                    apiWebClient = client;
                    apiWebClientAuth = new Tuple<string, string>(username, password);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Authentication is failed.");
                }
            }

            return apiWebClient;
        }