In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you how to use gRPC in C#. The content is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
1. Add ProtocolBuffer and gRPC references to NuGet
Protocol buffer version 3.0, select Include Prerelease in the NuGet plug-in interface and find google protocol buffer.
If you do not select include rerelease, the found protocol buffer is 2.4, and example that passes through gRPC cannot be compiled.
two。 Define proto
Design proto protocol files, including service agreements and data. GRPC must use the protocol buffer3.0 version, so syntax is set to proto3.
Greeter is the name of the service
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"; package 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 classes
After defining the proto file, 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.
Put 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-Illumination. -- csharp_out=. -- grpc_out=. -- plugin=protoc-gen-grpc=grpc_csharp_plugin.exe helloworld.proto
Execute the bat file to get the access class for proto:
The above content of helloworld.cshelloworldGrpc.cs is how to use gRPC in C#. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.