Esempio n. 1
0
        public async Task <List <Service> > Get()
        {
            var services = new List <Service>();

            var instances = await _client.GetServerAsync(_serviceName);

            if (instances != null && instances.Any())
            {
                services.AddRange(instances.Select(i => new Service(i.InstanceId, new ServiceHostAndPort(i.Ip, i.Port), "", "", new List <string>())));
            }

            return(await Task.FromResult(services));
        }
        public ActionResult <string> Test()
        {
            var baseUrl = _serverManager.GetServerAsync("App2").GetAwaiter().GetResult();

            if (string.IsNullOrWhiteSpace(baseUrl))
            {
                return("empty");
            }

            var url = $"{baseUrl}/api/values";

            using (HttpClient client = new HttpClient())
            {
                var result = client.GetAsync(url).GetAwaiter().GetResult();
                return(result.Content.ReadAsStringAsync().GetAwaiter().GetResult());
            }
        }
Esempio n. 3
0
        private async Task <string> GetResultAsync()
        {
            var baseUrl = await _serverManager.GetServerAsync("BaseService");

            if (string.IsNullOrWhiteSpace(baseUrl))
            {
                return("");
            }

            var url = $"{baseUrl}/api/values";

            var client = _clientFactory.CreateClient();

            var result = await client.GetAsync(url);

            return(await result.Content.ReadAsStringAsync());
        }
Esempio n. 4
0
        public async Task <string> Get(int bookid)
        {
            var baseUrl = _svc.GetServerAsync("reviewservice").GetAwaiter().GetResult();

            if (string.IsNullOrWhiteSpace(baseUrl))
            {
                return("empty");
            }
            // else
            // {
            //     return baseUrl;
            // }
            var client = _clientFactory.CreateClient();

            client.BaseAddress = new Uri(baseUrl);

            //string result = await client.GetStringAsync("/");
            string result = await client.GetStringAsync("/Reviews/Detailsjson/" + bookid.ToString());

            result = result + "\n" + "This result is from:" + baseUrl.ToString();

            return(result);
        }