Skip to content

Commit c1c0f50

Browse files
Add gRPC client and server sample for ASP.NET Core 10 (#36732)
* Add gRPC client and server sample for ASP.NET Core 10 * fix the reference to vs-10 * Apply suggestions from code review Co-authored-by: Wade Pickett <wpickett@microsoft.com> --------- Co-authored-by: Wade Pickett <wpickett@microsoft.com>
1 parent 5057ea5 commit c1c0f50

16 files changed

Lines changed: 507 additions & 15 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# [Visual Studio](#tab/visual-studio)
2+
3+
* Press Ctrl+F5 to run without the debugger.
4+
5+
[!INCLUDE[](~/includes/trustCertVS26.md)]
6+
7+
Visual Studio:
8+
9+
* Starts [Kestrel](xref:fundamentals/servers/index#kestrel) server.
10+
* Launches a browser.
11+
* Navigates to `http://localhost:port`, such as `http://localhost:7042`.
12+
* *port*: A randomly assigned port number for the app.
13+
* `localhost`: The standard hostname for the local computer. Localhost only serves web requests from the local computer.
14+
15+
# [Visual Studio Code](#tab/visual-studio-code)
16+
17+
[!INCLUDE[](~/includes/trustCertVSC.md)]
18+
19+
* Press **Ctrl-F5** to run without the debugger.
20+
21+
Visual Studio Code:
22+
23+
* Starts [Kestrel](xref:fundamentals/servers/index#kestrel) server.
24+
* Launches a browser.
25+
* Navigates to `http://localhost:port`, such as `http://localhost:7042`.
26+
* *port*: A randomly assigned port number for the app.
27+
* `localhost`: The standard hostname for the local computer. Localhost only serves web requests from the local computer.
28+
29+
---
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Visual Studio displays the following dialog:
2+
3+
![This project is configured to use SSL. To avoid SSL warnings in the browser you can choose to trust the self-signed certificate that IIS Express has generated. Would you like to trust the IIS Express SSL certificate?](~/static/trustCertVS26.png)
4+
5+
Select **Yes** if you trust the IIS Express SSL certificate.
6+
7+
The following dialog is displayed:
8+
9+
![Security warning dialog](~/static/certVS26.png)
10+
11+
Select **Yes** if you agree to trust the development certificate.
12+
13+
[!INCLUDE[trust FF](~/includes/trust-ff.md)]

aspnetcore/static/certVS26.png

84.3 KB
Loading
16.2 KB
Loading

aspnetcore/tutorials/grpc/grpc-start.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ author: jamesnk
44
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.
55
monikerRange: '>= aspnetcore-3.0'
66
ms.author: wpickett
7-
ms.date: 01/30/2025
7+
ms.date: 02/02/2026
88
uid: tutorials/grpc/grpc-start
99
---
1010
# Tutorial: Create a gRPC client and server in ASP.NET Core
1111

12-
:::moniker range=">= aspnetcore-9.0"
12+
:::moniker range=">= aspnetcore-10.0"
1313
This tutorial shows how to create a .NET [gRPC](xref:grpc/index) client and an ASP.NET Core gRPC Server. At the end, you'll have a gRPC client that communicates with the gRPC Greeter service.
1414

1515
In this tutorial, you:
@@ -23,23 +23,23 @@ In this tutorial, you:
2323

2424
# [Visual Studio](#tab/visual-studio)
2525

26-
[!INCLUDE[](~/includes/net-prereqs-vs-9.0.md)]
26+
[!INCLUDE[](~/includes/net-prereqs-vs-10.md)]
2727

2828
# [Visual Studio Code](#tab/visual-studio-code)
2929

30-
[!INCLUDE[](~/includes/net-prereqs-vsc-9.0.md)]
30+
[!INCLUDE[](~/includes/net-prereqs-vsc-10.0.md)]
3131

3232
---
3333

3434
## Create a gRPC service
3535

3636
# [Visual Studio](#tab/visual-studio)
3737

38-
* Start Visual Studio 2022 and select **New Project**.
38+
* Start Visual Studio and select **Create a new Project**.
3939
* In the **Create a new project** dialog, search for `gRPC`. Select **ASP.NET Core gRPC Service** and select **Next**.
4040
* In the **Configure your new project** dialog, enter `GrpcGreeter` for **Project name**. It's important to name the project *GrpcGreeter* so the namespaces match when you copy and paste code.
4141
* Select **Next**.
42-
* In the **Additional information** dialog, select **.NET 9.0 (Standard Term Support)** and then select **Create**.
42+
* In the **Additional information** dialog, select **.NET 10.0 (Long Term Support)** and then select **Create**.
4343

4444
# [Visual Studio Code](#tab/visual-studio-code)
4545

@@ -64,7 +64,7 @@ The tutorial assumes familiarity with VS Code. For more information, see [Gettin
6464

6565
### Run the service
6666

67-
[!INCLUDE[](~/includes/run-the-app9.0.md)]
67+
[!INCLUDE[](~/includes/run-the-app10.0.md)]
6868

6969
The logs show the service listening on `https://localhost:<port>`, where `<port>` is the localhost port number randomly assigned when the project is created and set in `Properties/launchSettings.json`.
7070

@@ -78,15 +78,15 @@ info: Microsoft.Hosting.Lifetime[0]
7878
```
7979

8080
> [!NOTE]
81-
> 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. The gRPC service localhost port number is randomly assigned when the project is created and set in the *Properties\launchSettings.json* file of the gRPC service project.
81+
> 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. The gRPC service localhost port number is randomly assigned when the project is created and set in the *Properties\launchSettings.json* file of the gRPC service project.
8282
8383
### Examine the project files
8484

8585
*GrpcGreeter* project files:
8686

8787
* `Protos/greet.proto`: defines the `Greeter` gRPC and is used to generate the gRPC server assets. For more information, see [Introduction to gRPC](xref:grpc/index).
8888
* `Services` folder: Contains the implementation of the `Greeter` service.
89-
* `appSettings.json`: Contains configuration data such as the protocol used by Kestrel. For more information, see <xref:fundamentals/configuration/index>.
89+
* `appsettings.json`: Contains configuration data such as the protocol used by Kestrel. For more information, see <xref:fundamentals/configuration/index>.
9090
* `Program.cs`, which contains:
9191
* The entry point for the gRPC service. For more information, see <xref:fundamentals/host/generic-host>.
9292
* Code that configures app behavior. For more information, see [App startup](xref:fundamentals/startup).
@@ -95,10 +95,10 @@ info: Microsoft.Hosting.Lifetime[0]
9595

9696
# [Visual Studio](#tab/visual-studio)
9797

98-
* Open a second instance of Visual Studio and select **New Project**.
98+
* Open a second instance of Visual Studio and select **Create a new project**.
9999
* In the **Create a new project** dialog, select **Console App**, and select **Next**.
100100
* In the **Project name** text box, enter **GrpcGreeterClient** and select **Next**.
101-
* In the **Additional information** dialog, select **.NET 9.0 (Standard Term Support)** and then select **Create**.
101+
* In the **Additional information** dialog, select **.NET 10.0 (Long Term Support)** and then select **Create**.
102102

103103
# [Visual Studio Code](#tab/visual-studio-code)
104104

@@ -203,7 +203,7 @@ dotnet add GrpcGreeterClient.csproj package Grpc.Tools
203203
204204
* Update the gRPC client `Program.cs` file with the following code.
205205

206-
[!code-csharp[](~/tutorials/grpc/grpc-start/sample/sample9/GrpcGreeterClient/Program.cs?name=snippet2&highlight=5)]
206+
[!code-csharp[](~/tutorials/grpc/grpc-start/sample/sample10/GrpcGreeterClient/Program.cs?name=snippet2&highlight=5)]
207207

208208
* In the preceding highlighted code, replace the localhost port number `7042` with the `HTTPS` port number specified in `Properties/launchSettings.json` within the `GrpcGreeter` service project.
209209

@@ -214,17 +214,17 @@ The Greeter client is created by:
214214
* Instantiating a `GrpcChannel` containing the information for creating the connection to the gRPC service.
215215
* Using the `GrpcChannel` to construct the Greeter client:
216216

217-
[!code-csharp[](~/tutorials/grpc/grpc-start/sample/sample9/GrpcGreeterClient/Program.cs?name=snippet&highlight=1-3)]
217+
[!code-csharp[](~/tutorials/grpc/grpc-start/sample/sample10/GrpcGreeterClient/Program.cs?name=snippet&highlight=1-3)]
218218

219219
The Greeter client calls the asynchronous `SayHello` method. The result of the `SayHello` call is displayed:
220220

221-
[!code-csharp[](~/tutorials/grpc/grpc-start/sample/sample9/GrpcGreeterClient/Program.cs?name=snippet&highlight=4-6)]
221+
[!code-csharp[](~/tutorials/grpc/grpc-start/sample/sample10/GrpcGreeterClient/Program.cs?name=snippet&highlight=4-6)]
222222

223223
## Test the gRPC client with the gRPC Greeter service
224224

225225
Update the `appsettings.Development.json` file by adding the following highlighted lines:
226226

227-
[!code-csharp[](~/tutorials/grpc/grpc-start/sample/sample9/GrpcGreeter/appsettings.Development.json?highlight=6-7)]
227+
[!code-csharp[](~/tutorials/grpc/grpc-start/sample/sample10/GrpcGreeter/appsettings.Development.json?highlight=6-7)]
228228

229229
# [Visual Studio](#tab/visual-studio)
230230

@@ -278,6 +278,8 @@ info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
278278

279279
:::moniker-end
280280

281+
[!INCLUDE[](~/tutorials/grpc/grpc-start/includes/grpc-start9.md)]
282+
281283
[!INCLUDE[](~/tutorials/grpc/grpc-start/includes/grpc-start8.md)]
282284

283285
[!INCLUDE[](~/tutorials/grpc/grpc-start/includes/grpc-start7.md)]

0 commit comments

Comments
 (0)