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
Copy file name to clipboardExpand all lines: aspnetcore/tutorials/grpc/grpc-start.md
+46-42
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ author: juntaoluo
4
4
description: This tutorial shows how to create a gRPC Service and gRPC client on ASP.NET Core. Learn how to create a gRPC Service project, edit a proto file, and add a duplex streaming call.
5
5
monikerRange: '>= aspnetcore-3.0'
6
6
ms.author: johluo
7
-
ms.date: 8/22/2019
7
+
ms.date: 8/23/2019
8
8
uid: tutorials/grpc/grpc-start
9
9
---
10
10
# Tutorial: Create a gRPC client and server in ASP.NET Core
@@ -45,13 +45,15 @@ In this tutorial, you:
45
45
# [Visual Studio](#tab/visual-studio)
46
46
47
47
* Start Visual Studio and select **Create a new project**. Alternatively, from the Visual Studio **File** menu, select **New** > **Project**.
48
-
* In the **Create a new project** dialog, select **gPRC Service** and select **Next**.
48
+
* In the **Create a new project** dialog, select **gPRC Service** and select **Next**:
49
+
49
50

51
+
50
52
* Name the project **GrpcGreeter**. It's important to name the project *GrpcGreeter* so the namespaces will match when you copy and paste code.
51
-
* Select **Create**
53
+
* Select **Create**.
52
54
* In the **Create a new gRPC service** dialog:
53
55
* The **gRPC Service** template is selected.
54
-
* Select **Create**
56
+
* Select **Create**.
55
57
56
58
# [Visual Studio Code](#tab/visual-studio-code)
57
59
@@ -68,7 +70,7 @@ In this tutorial, you:
68
70
* The `code` command opens the *GrpcGreeter* folder in a new instance of Visual Studio Code.
69
71
70
72
A dialog box appears with **Required assets to build and debug are missing from 'GrpcGreeter'. Add them?**
71
-
* Select **Yes**
73
+
* Select **Yes**.
72
74
73
75
# [Visual Studio for Mac](#tab/visual-studio-mac)
74
76
@@ -83,9 +85,7 @@ The preceding commands use the [.NET Core CLI](/dotnet/core/tools/dotnet) to cre
83
85
84
86
### Open the project
85
87
86
-
From Visual Studio, select **File > Open**, and then select the *GrpcGreeter.sln* file.
87
-
88
-
<!-- End of VS tabs -->
88
+
From Visual Studio, select **File** > **Open**, and then select the *GrpcGreeter.sln* file.
89
89
90
90
---
91
91
@@ -97,11 +97,13 @@ From Visual Studio, select **File > Open**, and then select the *GrpcGreeter.sln
97
97
98
98
Visual Studio runs the service in a command prompt.
99
99
100
-
# [Visual Studio Code / Visual Studio for Mac](#tab/visual-studio-code+visual-studio-mac)
100
+
# [Visual Studio Code](#tab/visual-studio-code)
101
101
102
102
* Run the gRPC Greeter project *GrpcGreeter* from the command line using `dotnet run`.
103
103
104
-
<!-- End of combined VS/Mac tabs -->
104
+
# [Visual Studio for Mac](#tab/visual-studio-mac)
105
+
106
+
* Run the gRPC Greeter project *GrpcGreeter* from the command line using `dotnet run`.
**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).
130
+
**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).
129
131
**Services* folder: Contains the implementation of the `Greeter` service.
130
-
**appSettings.json*: Contains configuration data, such as protocol used by Kestrel. For more information, see <xref:fundamentals/configuration/index>.
131
-
**Program.cs*: Contains the entry point for the gRPC service. For more information, see <xref:fundamentals/host/generic-host>.
132
-
**Startup.cs*: Contains code that configures app behavior. For more information, see [App startup](xref:fundamentals/startup).
132
+
**appSettings.json*– Contains configuration data, such as protocol used by Kestrel. For more information, see <xref:fundamentals/configuration/index>.
133
+
**Program.cs*– Contains the entry point for the gRPC service. For more information, see <xref:fundamentals/host/generic-host>.
134
+
**Startup.cs*– Contains code that configures app behavior. For more information, see [App startup](xref:fundamentals/startup).
133
135
134
136
## Create the gRPC client in a .NET console app
135
137
136
-
##[Visual Studio](#tab/visual-studio)
138
+
# [Visual Studio](#tab/visual-studio)
137
139
138
140
* Open a second instance of Visual Studio and select **Create a new project**.
139
141
* In the **Create a new project** dialog, select **Console App (.NET Core)** and select **Next**.
* Change directories (`cd`) to a folder which will contain the project.
146
148
* Run the following commands:
147
149
148
-
```console
149
-
dotnet new console -o GrpcGreeterClient
150
-
code -r GrpcGreeterClient
151
-
```
150
+
```console
151
+
dotnet new console -o GrpcGreeterClient
152
+
code -r GrpcGreeterClient
153
+
```
152
154
153
155
# [Visual Studio for Mac](#tab/visual-studio-mac)
154
156
155
-
Follow the instructions [here](/dotnet/core/tutorials/using-on-mac-vs-full-solution) to create a console app with the name *GrpcGreeterClient*.
156
-
157
-
<!-- End of VS tabs -->
157
+
Follow the instructions in [Building a complete .NET Core solution on macOS using Visual Studio for Mac](/dotnet/core/tutorials/using-on-mac-vs-full-solution) to create a console app with the name *GrpcGreeterClient*.
158
158
159
159
---
160
160
@@ -166,7 +166,7 @@ The gRPC client project requires the following packages:
166
166
*[Google.Protobuf](https://www.nuget.org/packages/Google.Protobuf/), which contains protobuf message APIs for C#.
167
167
*[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"`.
168
168
169
-
###[Visual Studio](#tab/visual-studio)
169
+
# [Visual Studio](#tab/visual-studio)
170
170
171
171
Install the packages using either the Package Manager Console (PMC) or Manage NuGet Packages.
172
172
@@ -176,11 +176,11 @@ Install the packages using either the Package Manager Console (PMC) or Manage Nu
176
176
* From the **Package Manager Console** window, run `cd GrpcGreeterClient` to change directories to the folder containing the *GrpcGreeterClient.csproj* files.
177
177
* Run the following commands:
178
178
179
-
```powershell
180
-
Install-Package Grpc.Net.Client -prerelease
181
-
Install-Package Google.Protobuf -prerelease
182
-
Install-Package Grpc.Tools -prerelease
183
-
```
179
+
```powershell
180
+
Install-Package Grpc.Net.Client -prerelease
181
+
Install-Package Google.Protobuf -prerelease
182
+
Install-Package Grpc.Tools -prerelease
183
+
```
184
184
185
185
#### Manage NuGet Packages option to install packages
## Test the gRPC client with the gRPC Greeter service
262
262
263
-
###[Visual Studio](#tab/visual-studio)
263
+
# [Visual Studio](#tab/visual-studio)
264
264
265
265
* In the Greeter service, press `Ctrl+F5` to start the server without the debugger.
266
266
* In the `GrpcGreeterClient` project, press `Ctrl+F5` to start the client without the debugger.
267
267
268
-
###[Visual Studio Code / Visual Studio for Mac](#tab/visual-studio-code+visual-studio-mac)
268
+
# [Visual Studio Code](#tab/visual-studio-code)
269
269
270
270
* Start the Greeter service.
271
271
* Start the client.
272
272
273
-
<!-- End of combined VS/Mac tabs -->
273
+
274
+
# [Visual Studio for Mac](#tab/visual-studio-mac)
275
+
276
+
* Start the Greeter service.
277
+
* Start the client.
274
278
275
279
---
276
280
277
-
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:
281
+
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:
278
282
279
283
```console
280
284
Greeting: Hello GreeterClient
281
285
Press any key to exit...
282
286
```
283
287
284
-
The gRPC service records the details of the successful call in the logs written to the command prompt.
288
+
The gRPC service records the details of the successful call in the logs written to the command prompt:
0 commit comments