From a0df169e85aa5d8fe6ac7d26e16a127d20fb3924 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Thu, 6 Jun 2024 18:28:41 +0200 Subject: [PATCH] Add a gRPC client --- .../RankingService/RankingClient/Program.cs | 13 ++++++++++ .../RankingClient/RankingClient.csproj | 25 +++++++++++++++++++ Tasks/Lab11/RankingService/RankingService.sln | 6 +++++ 3 files changed, 44 insertions(+) create mode 100644 Tasks/Lab11/RankingService/RankingClient/Program.cs create mode 100644 Tasks/Lab11/RankingService/RankingClient/RankingClient.csproj diff --git a/Tasks/Lab11/RankingService/RankingClient/Program.cs b/Tasks/Lab11/RankingService/RankingClient/Program.cs new file mode 100644 index 0000000..8a17afc --- /dev/null +++ b/Tasks/Lab11/RankingService/RankingClient/Program.cs @@ -0,0 +1,13 @@ +using Grpc.Net.Client; +using RankingService; +using static RankingService.Ranking; + +GrpcChannel channel = GrpcChannel.ForAddress("http://localhost:8000"); +RankingClient client = new RankingClient(channel); +var result = await client.GetRankingAsync(new RankingService.RankingRequest()); + +for (int i = 0; i < result.Competitors.Count; i++) +{ + Competitor competitor = result.Competitors[i]; + Console.WriteLine($"{i + 1}. {competitor.Name}, {competitor.Time}"); +} diff --git a/Tasks/Lab11/RankingService/RankingClient/RankingClient.csproj b/Tasks/Lab11/RankingService/RankingClient/RankingClient.csproj new file mode 100644 index 0000000..37385ed --- /dev/null +++ b/Tasks/Lab11/RankingService/RankingClient/RankingClient.csproj @@ -0,0 +1,25 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + Protos\ranking.proto + + + + diff --git a/Tasks/Lab11/RankingService/RankingService.sln b/Tasks/Lab11/RankingService/RankingService.sln index 1b84cf0..e9de41b 100644 --- a/Tasks/Lab11/RankingService/RankingService.sln +++ b/Tasks/Lab11/RankingService/RankingService.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 17.10.34928.147 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RankingService", "RankingService\RankingService.csproj", "{DE7F9795-772A-4134-895F-3F65193E86BE}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RankingClient", "RankingClient\RankingClient.csproj", "{9373A533-CDFC-4EEC-AE5A-9CE87F099697}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {DE7F9795-772A-4134-895F-3F65193E86BE}.Debug|Any CPU.Build.0 = Debug|Any CPU {DE7F9795-772A-4134-895F-3F65193E86BE}.Release|Any CPU.ActiveCfg = Release|Any CPU {DE7F9795-772A-4134-895F-3F65193E86BE}.Release|Any CPU.Build.0 = Release|Any CPU + {9373A533-CDFC-4EEC-AE5A-9CE87F099697}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9373A533-CDFC-4EEC-AE5A-9CE87F099697}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9373A533-CDFC-4EEC-AE5A-9CE87F099697}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9373A533-CDFC-4EEC-AE5A-9CE87F099697}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE