当前位置:网站首页>. Net core 3.0 grpc custom service
. Net core 3.0 grpc custom service
2022-06-09 04:48:00 【Wind god Shura envoy】
Server side
newly build gRPC project 
Right click Protos Folder –> Create a new one .proto, Select the protocol buffer file , Used to describe gRPC Messages and services for 
Name at will , It's called UpImg Well 
Then put the package name , The service name , Modify the parameter and return value names 
Set the default method name SayHello And parameters and return values are also modified 
Change to our own defined parameters and return values 
Create a new one UpImgService, Implement what we just defined above gRPC The service description UpImg.proto
Note that the new service cannot be found by direct implementation 
Because it's not there yet obj\Debug\netcoreapp3.0 The following generates the corresponding class
You need to double-click our project to edit csproj file , Put the new UpImg.proto Add to the configuration 
Add it to the configuration and save it in obj\Debug\netcoreapp3.0 The corresponding class can be generated in 
Then continue to implement UpImg.proto, The implementation is very simple. Just pay attention to the parameters and return values 
client
The client needs to add a package :Grpc.Net.Client、Google.Protobuf、Grpc.Tools
<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.11.2" />
<PackageReference Include="Grpc.Net.Client" Version="2.26.0" />
<PackageReference Include="Grpc.Tools" Version="2.26.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
hold UpImg.proto Copy to... In the client Proto( Here we use direct copy )
Also add configuration on the client , Adding configuration and client will automatically generate corresponding code 
And then call it :
public async void UpLoad()
{
// Settings allow unsafe HTTP2 Support
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
var channel = GrpcChannel.ForAddress("http://localhost:50001");
var client = new UpImg.UpImgClient(channel);
var reply = await client.DoUpLoadAsync(new UpImgRequest {
Img = "hello girl" });
Console.WriteLine(reply.Message);
}
gRPC The call was actively rejected by the target computer , Unable to connect .
Modify port settings , May be https Caused by the 
Code :
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.ConfigureKestrel(options => {
options.ListenLocalhost(8099,a=>a.Protocols= Microsoft.AspNetCore.Server.Kestrel.Core.HttpProtocols.Http2);
});
webBuilder.UseStartup<Startup>();
});
There is also the possibility of error Grpc.Core.RpcException:“Status(StatusCode=Unimplemented, Detail="Service is unimplemented.")”
Think you haven't started the service you called yet 
边栏推荐
- P5321 [bjoi2019] farewell (LCT)
- Openstack Learning Series 12: installing CEPH and docking openstack
- PHP e签宝电子签名Saas API 对接流程
- Listing of Yubang new material on Shenzhen Stock Exchange: market value of 4.7 billion, net profit deducted in the first quarter decreased by 18%
- 2022年安全员-B证上岗证题目及在线模拟考试
- Installation and performance test of API gateway Apache APIs IX on AWS graviton3
- JVM interview
- (3)数据绑定指令
- Win10安装appium环境
- Golang ---image-- overlap of thermal maps and photos
猜你喜欢

Debugging -- debugging objects and events

(5) Bidirectional data binding

150 basic acoustic knowledge that acoustic engineers should know (full text)

2022年高处安装、维护、拆除特种作业证考试题库及模拟考试

number-precision--使用/实例

2022年高压电工考试模拟100题及答案

openGL_ 05 simple application of shader

The half year revenue of mushroom street was 168million yuan: a year-on-year decrease of 29% and an operating loss of 240million yuan

故障排查:阿里云轻量应用服务器中的MySQL容器自行停止

openGL_ 04 drawing with index array
随机推荐
The latest JMeter pressure test in the whole network is not much to say. I just want to teach you to use JMeter to write script pressure test as soon as possible
TypeScript 学习【8】枚举类型
P5354 [ynoi2017] yoyo OJ (tree section and bit operation)
Mmdet detection box font color modification
(5) 双向数据绑定
PDQ环境变量
2022 safety officer-b certificate work certificate title and online simulation examination
Ultimate shell - Zsh
Typescript learning [7] advanced types: Union type and cross type
(3)数据绑定指令
TypeScript 学习【9】泛型
PHP e-signature SaaS API docking process
2022年安全员-B证上岗证题目及在线模拟考试
Format interchange among Yolo, coco and VOC datasets
Troubleshooting: MySQL containers in alicloud lightweight application servers stop automatically
Nacos1.1.4版本本地源码启动
Types, advantages and disadvantages of MySQL indexes
openGL_01-创建窗口
渗透测试路径字典、爆破字典
(2) V-cloak instruction