Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to share gRPC proto data between client and server

I just started learning gRPC and I got an issue with proto files, as I understand these files define the model of incoming-outgoing data.

On the server side everything is OK. The server compiles and runs fine, but the client side does not recognize proto files from the server. Using Visual Studio 2019, it suggest to add the whole server as a reference.

At this point I believed I went too far. Looking for a solution, I read that I need to add it as a Service Reference, but Visual Studio 2019 only offers WCF and Azure service. Do I need to copy paste proto files from the server to the client since looking on other "tutorials" I noticed that proto files copy pasted to client, client and server are .NET Core 3.0 and ASP.NET Core 3.0.

like image 537
Joel2 Avatar asked Aug 10 '19 10:08

Joel2


People also ask

How do you share on Proto?

You can share your Proto.io project using Share links, that is, links that others can access. You can choose to share your prototype as: Live Version: Share a live version of your prototype. Any changes made to your prototype will be visible to the people who access this Share link.

Can gRPC server call client?

No, a server cannot invoke calls on the client. gRPC works with HTTP, and HTTP has not had such semantics in the past.


Video Answer


1 Answers

Go to your client app

  • right click on "Dependencies" > "Add Connected Service"
  • click "Service References" tab
  • choose "Add new gRPC service reference"

In a popup window specify path to .proto file and choose type of class to be generated - "Client". Now you will have one .proto file for two projects.

This is instruction for Visual Studio 2019.

like image 93
Yaroslav N. Avatar answered Nov 08 '22 17:11

Yaroslav N.