Using GRPC in C #

Source: Internet
Author: User
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 found protocol buffer is 2.4 and cannot be compiled

2. Define Proto

Design proto protocol files, including service protocols and data. GRPC must use protocol buffer3.0 version, so syntax is 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 reques T 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:

Protoc.exe-i=. --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.

The above is the use of GRPC in C # content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Related Article

    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.