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)!