-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial project with Grpc Client and Server
- Loading branch information
0 parents
commit 796382a
Showing
13 changed files
with
718 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.26124.0 | ||
MinimumVisualStudioVersion = 15.0.26124.0 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "grpcAsyncStreamServer", "grpcAsyncStreamServer\grpcAsyncStreamServer.csproj", "{F2C728C7-9708-447E-920A-99479984E76D}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "grpcAsyncStreamClient", "grpcAsyncStreamClient\grpcAsyncStreamClient.csproj", "{A2A11C84-4C9D-4990-B603-04A846DE2DB5}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Debug|x64 = Debug|x64 | ||
Debug|x86 = Debug|x86 | ||
Release|Any CPU = Release|Any CPU | ||
Release|x64 = Release|x64 | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{F2C728C7-9708-447E-920A-99479984E76D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{F2C728C7-9708-447E-920A-99479984E76D}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{F2C728C7-9708-447E-920A-99479984E76D}.Debug|x64.ActiveCfg = Debug|Any CPU | ||
{F2C728C7-9708-447E-920A-99479984E76D}.Debug|x64.Build.0 = Debug|Any CPU | ||
{F2C728C7-9708-447E-920A-99479984E76D}.Debug|x86.ActiveCfg = Debug|Any CPU | ||
{F2C728C7-9708-447E-920A-99479984E76D}.Debug|x86.Build.0 = Debug|Any CPU | ||
{F2C728C7-9708-447E-920A-99479984E76D}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{F2C728C7-9708-447E-920A-99479984E76D}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{F2C728C7-9708-447E-920A-99479984E76D}.Release|x64.ActiveCfg = Release|Any CPU | ||
{F2C728C7-9708-447E-920A-99479984E76D}.Release|x64.Build.0 = Release|Any CPU | ||
{F2C728C7-9708-447E-920A-99479984E76D}.Release|x86.ActiveCfg = Release|Any CPU | ||
{F2C728C7-9708-447E-920A-99479984E76D}.Release|x86.Build.0 = Release|Any CPU | ||
{A2A11C84-4C9D-4990-B603-04A846DE2DB5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{A2A11C84-4C9D-4990-B603-04A846DE2DB5}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{A2A11C84-4C9D-4990-B603-04A846DE2DB5}.Debug|x64.ActiveCfg = Debug|Any CPU | ||
{A2A11C84-4C9D-4990-B603-04A846DE2DB5}.Debug|x64.Build.0 = Debug|Any CPU | ||
{A2A11C84-4C9D-4990-B603-04A846DE2DB5}.Debug|x86.ActiveCfg = Debug|Any CPU | ||
{A2A11C84-4C9D-4990-B603-04A846DE2DB5}.Debug|x86.Build.0 = Debug|Any CPU | ||
{A2A11C84-4C9D-4990-B603-04A846DE2DB5}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{A2A11C84-4C9D-4990-B603-04A846DE2DB5}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{A2A11C84-4C9D-4990-B603-04A846DE2DB5}.Release|x64.ActiveCfg = Release|Any CPU | ||
{A2A11C84-4C9D-4990-B603-04A846DE2DB5}.Release|x64.Build.0 = Release|Any CPU | ||
{A2A11C84-4C9D-4990-B603-04A846DE2DB5}.Release|x86.ActiveCfg = Release|Any CPU | ||
{A2A11C84-4C9D-4990-B603-04A846DE2DB5}.Release|x86.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Grpc.Net.Client; | ||
using grpcAsyncStreamServer; | ||
|
||
namespace grpcAsyncStreamClient | ||
{ | ||
class Program | ||
{ | ||
static async Task Main(string[] args) | ||
{ | ||
var channel = GrpcChannel.ForAddress("https://localhost:5001"); | ||
var client = new Greeter.GreeterClient(channel); | ||
|
||
var reply = await client.SayHelloAsync(new HelloRequest { Name = "Laurent" }); | ||
|
||
Console.WriteLine(reply.Message); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
syntax = "proto3"; | ||
|
||
option csharp_namespace = "grpcAsyncStreamServer"; | ||
|
||
package Greet; | ||
|
||
// The greeting service definition. | ||
service Greeter { | ||
// Sends a greeting | ||
rpc SayHello (HelloRequest) returns (HelloReply); | ||
} | ||
|
||
// The request message containing the user's name. | ||
message HelloRequest { | ||
string name = 1; | ||
} | ||
|
||
// The response message containing the greetings. | ||
message HelloReply { | ||
string message = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp3.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Google.Protobuf" Version="3.9.1" /> | ||
<PackageReference Include="Grpc.Core" Version="2.23.0" /> | ||
<PackageReference Include="Grpc.Net.Client" Version="0.2.23-pre2" /> | ||
<PackageReference Include="Grpc.Tools" Version="2.23.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Protobuf Include="Protos\greet.proto"> | ||
<GrpcServices>Client</GrpcServices> | ||
<Access>Public</Access> | ||
<ProtoCompile>True</ProtoCompile> | ||
<ProtoRoot></ProtoRoot> | ||
<CompileOutputs>True</CompileOutputs> | ||
<OutputDir>obj\Debug\netcoreapp3.0\</OutputDir> | ||
<Generator>MSBuild:Compile</Generator> | ||
</Protobuf> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace grpcAsyncStreamServer | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
CreateHostBuilder(args).Build().Run(); | ||
} | ||
|
||
// Additional configuration is required to successfully run gRPC on macOS. | ||
// For instructions on how to configure Kestrel and gRPC clients on macOS, visit https://go.microsoft.com/fwlink/?linkid=2099682 | ||
public static IHostBuilder CreateHostBuilder(string[] args) => | ||
Host.CreateDefaultBuilder(args) | ||
.ConfigureWebHostDefaults(webBuilder => | ||
{ | ||
webBuilder.UseStartup<Startup>(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"profiles": { | ||
"grpcAsyncStream": { | ||
"commandName": "Project", | ||
"launchBrowser": false, | ||
"applicationUrl": "https://localhost:5001", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
syntax = "proto3"; | ||
|
||
option csharp_namespace = "grpcAsyncStreamServer"; | ||
|
||
package Greet; | ||
|
||
// The greeting service definition. | ||
service Greeter { | ||
// Sends a greeting | ||
rpc SayHello (HelloRequest) returns (HelloReply); | ||
} | ||
|
||
// The request message containing the user's name. | ||
message HelloRequest { | ||
string name = 1; | ||
} | ||
|
||
// The response message containing the greetings. | ||
message HelloReply { | ||
string message = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Grpc.Core; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace grpcAsyncStreamServer | ||
{ | ||
public class GreeterService : Greeter.GreeterBase | ||
{ | ||
private readonly ILogger<GreeterService> _logger; | ||
public GreeterService(ILogger<GreeterService> logger) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
public override Task<HelloReply> SayHello(HelloRequest request, ServerCallContext context) | ||
{ | ||
return Task.FromResult(new HelloReply | ||
{ | ||
Message = "Hello " + request.Name | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace grpcAsyncStreamServer | ||
{ | ||
public class Startup | ||
{ | ||
// This method gets called by the runtime. Use this method to add services to the container. | ||
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 | ||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
services.AddGrpc(); | ||
} | ||
|
||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | ||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | ||
{ | ||
if (env.IsDevelopment()) | ||
{ | ||
app.UseDeveloperExceptionPage(); | ||
} | ||
|
||
app.UseRouting(); | ||
|
||
app.UseEndpoints(endpoints => | ||
{ | ||
endpoints.MapGrpcService<GreeterService>(); | ||
|
||
endpoints.MapGet("/", async context => | ||
{ | ||
await context.Response.WriteAsync("Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909"); | ||
}); | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Debug", | ||
"System": "Information", | ||
"Grpc": "Information", | ||
"Microsoft": "Information" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Warning", | ||
"Microsoft.Hosting.Lifetime": "Information" | ||
} | ||
}, | ||
"AllowedHosts": "*", | ||
"Kestrel": { | ||
"EndpointDefaults": { | ||
"Protocols": "Http2" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.0</TargetFramework> | ||
<RootNamespace>grpcAsyncStream</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Protobuf Include="Protos\greet.proto" GrpcServices="Server" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Grpc.AspNetCore" Version="0.2.23-pre2" /> | ||
</ItemGroup> | ||
|
||
</Project> |