일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- nullable
- git
- File
- 코딩테스트
- WPF
- dotNET
- ListView
- IValueConverter
- Github
- csharp
- Binding
- windows10
- commit
- programmers
- windows
- C#
- .net
- string
- convert
- algorithm
- tls
- Coding
- logging
- Microsoft
- mysql
- coding-test
- log
- chashtag
- Visual Studio
- Process
- Today
- Total
CHashtag
[.net] gRPC 개발 본문
참고자료: https://www.youtube.com/watch?v=CXH_jEa8dUw&t=255s
(newtonsoft의 창시자.. 멋진분..)
gRPC 프로젝트 생성
권장 환경: Visual Studio 2022
"ASP.NET 및 웹 개발" 설치
그럼 gRPC Project를 생성할 수 있다.
아래와 같은 구성의 프로젝트가 생성된다.
이제 client를 생성해보자
그냥 Console App을 생성해주고
Server와 연결해줘야 한다.
Dependencies -> Manage Connected Services
File -> Server쪽 proto 파일 선택
그럼 자동으로 Client단에 필요한 gRPC관련 nuget packages를 다운받아주고 세팅이 된다.
Program.cs 는 아래와 같이 구성.
(.NET 6프로젝트를 생성하니 기본 생성 파일이 매우 단조로워졌네요,, 멋진 변화 굿)
using Grpc.Net.Client;
using gRPC_example;
var channel = GrpcChannel.ForAddress("http://localhost:5052");
var client = new Greeter.GreeterClient(channel);
var reply = await client.SayHelloAsync(
new HelloRequest { Name = "Chashtag" }
);
Console.WriteLine(reply.Message);
여기서 ForAddress의 인자는 Server Project의 launchSettings.json의 applicationUrl를 넣어주면 됨.
그 후 Server 실행
Client도 실행해보면,, GreeterService.cs에 정의되어 있는 것처럼 Response가 오는것을 확인할 수 있다!!
프로젝트 소스코드
https://github.com/Hyo-Seong/dotnet-gRPC-example
GitHub - Hyo-Seong/dotnet-gRPC-example: This is the sample project that make gRPC service.
This is the sample project that make gRPC service. - GitHub - Hyo-Seong/dotnet-gRPC-example: This is the sample project that make gRPC service.
github.com
감사합니다.
'C# > ASP.NET' 카테고리의 다른 글
Memory Leak 분석 1 - 들어가기 앞서,, (0) | 2025.03.03 |
---|---|
asp.net DI의 life cycle (Singleton, Scope, Transient) (0) | 2024.05.13 |
asp.net core에서 swagger 직접 세팅하기 (0) | 2023.02.20 |
Docker + ASP.NET core 6.0 + EF Core + Mysql (0) | 2022.09.29 |
[C#] [ASP.NET] Nancy CS0234, CS0012 어셈블리 참조 에러 해결법 (0) | 2021.05.11 |