Using GRPC in C #

Source: Internet
Author: User

Using GRPC in C #

My articles are the use of GRPC example, not directly compiled example, but a new project, from adding dependencies, compiling example code, execute example. This can be used as a reference for us to create our own projects. If you are familiar with GRPC build apps, you can ignore this series.

Directory

I. Overview

Second, compiling GRPC

Third, use GRPC in C #

Iv. using GRPC in C + +

Because of NuGet, C # is very simple to configure a project.

1. Add Protocolbuffer and Grpc references in NuGet

Protocol Buffer version 3.0, select Include prerelease in the NuGet plugin interface to find Google protocol buffer.
If you do not select Include rerelease, the protocol buffer found is 2.4 and cannot be compiled example through GRPC.

2. Define Proto

Design proto protocol files, including service protocols and data. GRPC must use the Protocol buffer3.0 version, so syntax set to proto3 .
Greeter is the service name
Hellorequest is the request data
Helloreply is the reply data

Syntax ="Proto3";Option Java_multiple_files =true; option java_package =  "Io.grpc.examples.helloworld"; option java_outer_classname =  "Helloworldproto"; option objc_class_prefix = " HLW ";p ackage helloworld;//The greeting service Definition.service Greeter {//sends a greeting RPC SayHello (hellorequest) returns (helloreply) {}}//the request message containing the user ' s name. message hellorequest {string name = 1;} The response message containing the Greetingsmessage helloreply {string message = 1;}   
3. Generate Proto Access class

Once the proto file is defined, the access class is generated through the Protoc.exe tool provided by protocol buffer3.0. Instead of using ProtoGen.exe, the Protoc C # plug-in Grpc_csharp_plugin.exe defined by GRPC is used here.
Place the following files in the same folder:

grpc_csharp_plugin.exehelloworld.protoprotoc.exe

Create a bat file and write the following command line:

--csharp_out=. --grpc_out=. --plugin=protoc-gen-grpc=grpc_csharp_plugin.exe helloworld.proto

Execute the bat file to get the Proto Access class:

helloworld.cshelloworldGrpc.cs
4. Create a C # project

Add two access class files to your C # project, copy grpc C # example to Program.cs, and compile through.

Using GRPC in C #

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.