Skip to content

Commit 892cfb5

Browse files
Merge pull request #2 from codepossible/master
Adding gRPC investigations folder
2 parents 542528b + 7c82eeb commit 892cfb5

File tree

15 files changed

+505
-1
lines changed

15 files changed

+505
-1
lines changed

.gitignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,24 @@ venv.bak/
102102

103103
# mypy
104104
.mypy_cache/
105+
106+
# Visual Studio
107+
.vs/
108+
.vscode/
109+
110+
# CSharp
111+
[Oo]bj/
112+
[Dd]ebug/
113+
[Rr]elease/
114+
[Pp]roperties/
115+
*.dll
116+
*.exe
117+
appsettings.json
118+
appsettings.*.json
119+
120+
# Certificate files
121+
*.cer
122+
*.pfx
123+
124+
125+

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"workbench.colorCustomizations": {}
2+
"workbench.colorCustomizations": {},
3+
"python.pythonPath": "C:\\Users\\shbanerj\\.conda\\envs\\py-azurefunctions\\python.exe"
34
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp3.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="Google.Protobuf" Version="3.10.0" />
10+
<PackageReference Include="Grpc.Net.Client" Version="2.23.2" />
11+
<PackageReference Include="Grpc.Tools" Version="2.24.0">
12+
<PrivateAssets>all</PrivateAssets>
13+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
14+
</PackageReference>
15+
</ItemGroup>
16+
<ItemGroup>
17+
<Protobuf Include="Protos\greet.proto" GrpcServices="Client" />
18+
</ItemGroup>
19+
</Project>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
using System.Net.Http;
3+
using System.Threading.Tasks;
4+
using DotNetGrpcService;
5+
using Grpc.Net.Client;
6+
7+
namespace GrpcGreeterClient
8+
{
9+
class Program
10+
{
11+
static async Task Main(string[] args)
12+
{
13+
// The port number(5001) must match the port of the gRPC server.
14+
15+
Console.WriteLine("Calling C# Endpoint...");
16+
await CallEndpoint("http://localhost:5000", true);
17+
18+
Console.WriteLine("Calling Python Endpoint...");
19+
await CallEndpoint("http://localhost:50051", true);
20+
21+
22+
Console.WriteLine("Press any key to exit...");
23+
Console.ReadKey();
24+
}
25+
26+
static GrpcChannel GetChannel(string grpcEndpointAddress, bool isInsecure = false)
27+
{
28+
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", isInsecure);
29+
return GrpcChannel.ForAddress(grpcEndpointAddress);
30+
}
31+
32+
static async Task CallEndpoint(string grpcEndpointAddress, bool isInsecure = false)
33+
{
34+
var channel = GetChannel(grpcEndpointAddress, isInsecure);
35+
var client = new Greeter.GreeterClient(channel);
36+
37+
var reply = await client.SayHelloAsync(
38+
new HelloRequest { Name = "GreeterClient" });
39+
Console.WriteLine("Greeting: " + reply.Message);
40+
}
41+
}
42+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
syntax = "proto3";
2+
3+
option csharp_namespace = "DotNetGrpcService";
4+
5+
package Greet;
6+
7+
// The greeting service definition.
8+
service Greeter {
9+
// Sends a greeting
10+
rpc SayHello (HelloRequest) returns (HelloReply);
11+
}
12+
13+
// The request message containing the user's name.
14+
message HelloRequest {
15+
string name = 1;
16+
}
17+
18+
// The response message containing the greetings.
19+
message HelloReply {
20+
string message = 1;
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<Protobuf Include="Protos\greet.proto" GrpcServices="Server" />
9+
</ItemGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Google.Protobuf" Version="3.10.0" />
13+
<PackageReference Include="Grpc.AspNetCore" Version="2.23.1" />
14+
<PackageReference Include="Grpc.Net.Client" Version="2.23.2" />
15+
<PackageReference Include="Grpc.Tools" Version="2.24.0">
16+
<PrivateAssets>all</PrivateAssets>
17+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
18+
</PackageReference>
19+
</ItemGroup>
20+
21+
</Project>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29316.153
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotNetGrpcService", "DotNetGrpcService.csproj", "{6D265B48-69E0-4511-9E77-A8B6501AAB48}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNetGrpcClient", "..\DotNetGrpcClient\DotNetGrpcClient.csproj", "{3E1D7598-32EE-43DC-B9E6-22C3568742FF}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{6D265B48-69E0-4511-9E77-A8B6501AAB48}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{6D265B48-69E0-4511-9E77-A8B6501AAB48}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{6D265B48-69E0-4511-9E77-A8B6501AAB48}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{6D265B48-69E0-4511-9E77-A8B6501AAB48}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{3E1D7598-32EE-43DC-B9E6-22C3568742FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{3E1D7598-32EE-43DC-B9E6-22C3568742FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{3E1D7598-32EE-43DC-B9E6-22C3568742FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{3E1D7598-32EE-43DC-B9E6-22C3568742FF}.Release|Any CPU.Build.0 = Release|Any CPU
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {75B6A36C-EF88-4E3A-83FD-5BD41A270F0C}
30+
EndGlobalSection
31+
EndGlobal
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore.Hosting;
7+
using Microsoft.Extensions.Hosting;
8+
9+
namespace DotNetGrpcService
10+
{
11+
public class Program
12+
{
13+
public static void Main(string[] args)
14+
{
15+
CreateHostBuilder(args).Build().Run();
16+
}
17+
18+
// Additional configuration is required to successfully run gRPC on macOS.
19+
// For instructions on how to configure Kestrel and gRPC clients on macOS, visit https://go.microsoft.com/fwlink/?linkid=2099682
20+
public static IHostBuilder CreateHostBuilder(string[] args) =>
21+
Host.CreateDefaultBuilder(args)
22+
.ConfigureWebHostDefaults(webBuilder =>
23+
{
24+
webBuilder.UseStartup<Startup>();
25+
});
26+
}
27+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
syntax = "proto3";
2+
3+
option csharp_namespace = "DotNetGrpcService";
4+
5+
package Greet;
6+
7+
// The greeting service definition.
8+
service Greeter {
9+
// Sends a greeting
10+
rpc SayHello (HelloRequest) returns (HelloReply);
11+
}
12+
13+
// The request message containing the user's name.
14+
message HelloRequest {
15+
string name = 1;
16+
}
17+
18+
// The response message containing the greetings.
19+
message HelloReply {
20+
string message = 1;
21+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Grpc.Core;
6+
using Microsoft.Extensions.Logging;
7+
8+
namespace DotNetGrpcService
9+
{
10+
public class GreeterService : Greeter.GreeterBase
11+
{
12+
private readonly ILogger<GreeterService> _logger;
13+
public GreeterService(ILogger<GreeterService> logger)
14+
{
15+
_logger = logger;
16+
}
17+
18+
public override Task<HelloReply> SayHello(HelloRequest request, ServerCallContext context)
19+
{
20+
return Task.FromResult(new HelloReply
21+
{
22+
Message = "Hello " + request.Name
23+
});
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)