标签:string Proto Grpc System TestGrpc using message 客户端
1、新建netcore控制台应用程序
2、NuGet包下载安装
Grpc.Net.Client
Google.ProtoBuf
Grpc.Tools
3、新建Protos文件夹,将服务端的greet.proto复制到该文件夹下
syntax = "proto3";
option csharp_namespace = "MyGrpcWeb";
package MyGrpc;
// The greeting service definition.
service TestGrpc {
// Sends a greeting
rpc TestSay (TestRequest) returns (TestReply);
rpc StreamingFromServer(ExampleRequest) returns (stream ExampleResponse);
rpc StreamingFromClient(stream ExampleRequest) returns (ExampleResponse);
rpc StreamingBothWays(stream ExampleRequest) returns (stream ExampleResponse);
}
// The request message containing the user's name.
message TestRequest {
string name = 1;
}
// The response message containing the greetings.
message TestReply {
string message = 1;
}
message ExampleRequest{
int32 pageIndex=1;
int32 pageSize=2;
bool isDescending=3;
}
message ExampleResponse{
string name=1;
string sex=2;
}
4、设置属性
5、重新生成解决方案
6、客户端引用
7、新建GrpcServer.cs
using Grpc.Net.Client;
using MyGrpcWeb;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace WebApplication1.GrpcService
{
public class GrpcServer
{
private readonly TestGrpc.TestGrpcClient _testGrpcClient;
private readonly GrpcChannel _channel;
public TestGrpc.TestGrpcClient MyGrpcClient
{
get { return _testGrpcClient; }
}
public GrpcServer()
{
_channel = GrpcChannel.ForAddress("http://localhost:5000");
_testGrpcClient = new TestGrpc.TestGrpcClient(_channel);
}
}
}
标签:string,Proto,Grpc,System,TestGrpc,using,message,客户端 来源: https://blog.csdn.net/lhwpc/article/details/120189855
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。