You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: "This tutorial shows how to create a gRPC Service and gRPC client on ASP.NET Core."
3
+
description: "Sample projects for a gRPC Service and gRPC client on ASP.NET Core."
4
4
languages:
5
5
- csharp
6
6
products:
@@ -10,192 +10,14 @@ products:
10
10
urlFragment: create-grpc-client
11
11
---
12
12
13
-
# Create a gRPC client and server in ASP.NET Core 3.0 using Visual Studio
13
+
# Create a gRPC client and server in ASP.NET Core 3.1
14
14
15
-
This tutorial shows how to create a .NET Core [gRPC](https://grpc.io/docs/guides/) client and an ASP.NET Core gRPC Server.
15
+
This sample demonstrates a .NET Core [gRPC](https://grpc.io/docs/guides/) client and an ASP.NET Core gRPC Server.
16
16
17
-
At the end, you'll have a gRPC client that communicates with the gRPC Greeter service.
18
-
19
-
In this tutorial, you;
20
-
21
-
* Create a gRPC Server.
22
-
* Create a gRPC client.
23
-
* Test the gRPC client service with the gRPC Greeter service.
24
-
25
-
## Create a gRPC service
26
-
27
-
* From the Visual Studio **File** menu, select **New** > **Project**.
28
-
* In the **Create a new project** dialog, select **ASP.NET Core Web Application**.
29
-
* Select **Next**
30
-
* Name the project **GrpcGreeter**. It's important to name the project *GrpcGreeter* so the namespaces will match when you copy and paste code.
31
-
* Select **Create**
32
-
* In the **Create a new ASP.NET Core Web Application** dialog:
33
-
* Select **.NET Core** and **ASP.NET Core 3.0** in the dropdown menus.
34
-
* Select the **gRPC Service** template.
35
-
* Select **Create**
36
-
37
-
### Run the service
38
-
39
-
* Press `Ctrl+F5` to run the gRPC service without the debugger.
40
-
41
-
Visual Studio runs the service in a command prompt.
42
-
43
-
The logs show the service listening on `https://localhost:5001`.
44
-
45
-
```console
46
-
info: Microsoft.Hosting.Lifetime[0]
47
-
Now listening on: https://localhost:5001
48
-
info: Microsoft.Hosting.Lifetime[0]
49
-
Application started. Press Ctrl+C to shut down.
50
-
info: Microsoft.Hosting.Lifetime[0]
51
-
Hosting environment: Development
52
-
info: Microsoft.Hosting.Lifetime[0]
53
-
```
54
-
55
-
> [!NOTE]
56
-
> The gRPC template is configured to use [Transport Layer Security (TLS)](https://tools.ietf.org/html/rfc5246). gRPC clients need to use HTTPS to call the server.
57
-
>
58
-
> macOS doesn't support ASP.NET Core gRPC with TLS. Additional configuration is required to successfully run gRPC services on macOS. For more information, see [gRPC and ASP.NET Core on macOS](xref:grpc/aspnetcore#grpc-and-aspnet-core-on-macos).
59
-
60
-
### Examine the project files
61
-
62
-
*GrpcGreeter* project files:
63
-
64
-
**greet.proto*: The *Protos/greet.proto* file defines the `Greeter` gRPC and is used to generate the gRPC server assets. For more information, see [Introduction to gRPC](xref:grpc/index).
65
-
**Services* folder: Contains the implementation of the `Greeter` service.
66
-
**appSettings.json*: Contains configuration data, such as protocol used by Kestrel. For more information, see <xref:fundamentals/configuration/index>.
67
-
**Program.cs*: Contains the entry point for the gRPC service. For more information, see <xref:fundamentals/host/generic-host>.
68
-
**Startup.cs*: Contains code that configures app behavior. For more information, see [App startup](xref:fundamentals/startup).
69
-
70
-
## Create the gRPC client in a .NET console app
71
-
72
-
* Open a second instance of Visual Studio.
73
-
* Select **File** > **New** > **Project** from the menu bar.
74
-
* In the **Create a new project** dialog, select **Console App (.NET Core)**.
75
-
* Select **Next**
76
-
* In the **Name** text box, enter "GrpcGreeterClient".
77
-
* Select **Create**.
78
-
79
-
### Add required packages
80
-
81
-
The gRPC client project requires the following packages:
82
-
83
-
*[Grpc.Net.Client](https://www.nuget.org/packages/Grpc.Net.Client), which contains the .NET Core client.
84
-
*[Google.Protobuf](https://www.nuget.org/packages/Google.Protobuf/), which contains protobuf message APIs for C#.
85
-
*[Grpc.Tools](https://www.nuget.org/packages/Grpc.Tools/), which contains C# tooling support for protobuf files. The tooling package isn't required at runtime, so the dependency is marked with `PrivateAssets="All"`.
86
-
87
-
Install the packages using either the Package Manager Console (PMC) or Manage NuGet Packages.
*Program.cs* contains the entry point and logic for the gRPC client.
158
-
159
-
The Greeter client is created by:
160
-
161
-
* Instantiating a `GrpcChannel` containing the information for creating the connection to the gRPC service.
162
-
* Using the `GrpcChannel` to construct the Greeter client.
163
-
164
-
## Test the gRPC client with the gRPC Greeter service
165
-
166
-
* In the Greeter service, press `Ctrl+F5` to start the server without the debugger.
167
-
* In the `GrpcGreeterClient` project, press `Ctrl+F5` to start the client without the debugger.
168
-
169
-
The client sends a greeting to the service with a message containing its name "GreeterClient". The service sends the message "Hello GreeterClient" as a response. The "Hello GreeterClient" response is displayed in the command prompt:
170
-
171
-
```console
172
-
Greeting: Hello GreeterClient
173
-
Press any key to exit...
174
-
```
175
-
176
-
The gRPC service records the details of the successful call in the logs written to the command prompt.
Request finished in 78.32260000000001ms 200 application/grpc
195
-
```
17
+
For a tutorial on this sample see [Tutorial: Create a gRPC client and server in ASP.NET Core](https://docs.microsoft.com/aspnet/core/tutorials/grpc/grpc-start?view=aspnetcore-3.1&tabs=visual-studio)
196
18
197
19
### Docs help & next steps for gRPC
198
20
199
21
*[Introduction to gRPC on ASP.NET Core](https://docs.microsoft.com/aspnet/core/grpc/index?view=aspnetcore-3.0)
200
22
*[gRPC services with C#](https://docs.microsoft.com/aspnet/core/grpc/basics?view=aspnetcore-3.0)
201
-
*[Migrating gRPC services from C-core to ASP.NET Core](https://docs.microsoft.com/aspnet/core/grpc/migration?view=aspnetcore-3.0)
23
+
*[Migrating gRPC services from C-core to ASP.NET Core](https://docs.microsoft.com/aspnet/core/grpc/migration?view=aspnetcore-3.0)
0 commit comments