网站首页 > 博客文章 正文
1、使用dotnet new grpc -o GrpcGreeter && cd GrpcGreeter && code . ,进入项目文件中,使用code .使用vscode打开。
[注]你可能会遇到'code' command not found?
解决办法:1)首次使用打开vscode -> command+shift+p -> 输入shell -> 提示Shell Command:Install 'code' in PATH -> 点击安装
2)额外知识点:mac在命令行中可以使用open .打开文件夹
2、项目文件打开了,这个时候我们使用dotnet run运行项目。
[注]你可能会遇到
1)https certificate not found
解决办法:一般的解决办法是直接按照提示运行dotnet dev-certs https --trust就可以了,但是我遇到了一个很奇葩的事情
2)cannot create developer certificate on Mac
解决办法:我重启了下电脑shutdown -r now,然后运行dotnet dev-certs https --trust,输入验证密码,然后ok了
3)无法绑定到 IPv4 环回接口上的 https://localhost:5001:在 macOS 上不支持 HTTP/2,因为缺少 ALPN 支持。 "。
解决办法:无法在macOS启动ASP.NET Core gRPC应用
1 public static IHostBuilder CreateHostBuilder(string[] args) => 2 Host.CreateDefaultBuilder(args) 3 .ConfigureWebHostDefaults(webBuilder => 4 { 5 webBuilder.ConfigureKestrel(options => 6 { 7 options.ListenLocalhost(5000, o => o.Protocols = HttpProtocols.Http2); 8 }); 9 webBuilder.UseStartup<Startup>(); 10 });
3、创建客户端项目dotnet new console -o GrpcGreeterClient,并引入以下三个包:
dotnet add GrpcGreeterClient.csproj package Grpc.Net.Client
dotnet add GrpcGreeterClient.csproj package Google.Protobuf
dotnet add GrpcGreeterClient.csproj package Grpc.Tools
4、将服务端的Protos/greet.proto拷贝到客户端Protos/greet.proto下,并在GrpcGreeterClient.csproj项目文件中添加元素项组
<ItemGroup> <Protobuf Include="Protos\greet.proto" GrpcServices="Client" /> </ItemGroup>
5、在客户端程序中
using System; using System.Net.Http; using System.Threading.Tasks; using GrpcGreeter; using Grpc.Net.Client; namespace GrpcGreeterClient { class Program { static async Task Main(string[] args) { var channel = GrpcChannel.ForAddress("http://localhost:5000"); var client = new Greeter.GreeterClient(channel); var reply = await client.SayHelloAsync( new HelloRequest { Name = "GreeterClient" }); Console.WriteLine("Greeting: " + reply.Message); } } }
6、运行客户端程序,发现报错
于是我们想到可能是我们为了解决http2问题引起的,如何解决呢?
解决办法:允许客户端进行不安全连接,添加下行代码
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
7、客户-服务端正常通信
原文地址:https://www.cnblogs.com/az4215/p/11961331.html
猜你喜欢
- 2024-09-21 Mac系统VSCode设置向下复制粘贴快捷键(Ctrl+D)
- 2024-09-21 解决Mac下VSCode打开zsh乱码(mac vs code如何设置中文)
- 2024-09-21 Atom, Vim, Visual Studio Code, Emacs 哪个好?
- 2024-09-21 分享一份嵌入式软件工具清单(嵌入式相关软件)
- 2024-09-21 老生常谈:Windows和MacOS到底哪个好用?
- 2024-09-21 TensorFlow为新旧Mac特供新版本,速度最高提升7倍
- 2024-09-21 macOS平台使用vscode调试ffmpeg(mac的vscode实现c程序)
- 2024-09-21 人生苦短,我要在VSCode里面用Python
- 2024-09-21 mac vscode找不到git(mac安装vscode找不到)
- 2024-09-21 快乐Coding,必须要有一个高颜值的代码编辑器,主题+字体推荐
你 发表评论:
欢迎- 07-02在线学习在爱奇艺信息流推荐业务中的探索与实践
- 07-02Diallyl Trisulfide(H2S donor)二烯丙基三硫:合成方法与工艺
- 07-02MitoSOX Red Mitochondrial Superoxide Indicator使用方法
- 07-02深度时空网络、记忆网络与特征表达学习在 CTR 预估中的应用
- 07-02iFluor 488标记鬼笔环肽可通过标记F-actin,研究细胞在迁移等
- 07-02快速了解红色线粒体超氧化物荧光探针的基本特性
- 07-02腔肠素400A(Coelenteramine 400a)综合解析,一文掌握所有要点!
- 07-02Chinese doctor Zhang Junqiao's heroic act exemplifies deep China-Africa friendship: FM spokesperson
- 最近发表
-
- 在线学习在爱奇艺信息流推荐业务中的探索与实践
- Diallyl Trisulfide(H2S donor)二烯丙基三硫:合成方法与工艺
- MitoSOX Red Mitochondrial Superoxide Indicator使用方法
- 深度时空网络、记忆网络与特征表达学习在 CTR 预估中的应用
- iFluor 488标记鬼笔环肽可通过标记F-actin,研究细胞在迁移等
- 快速了解红色线粒体超氧化物荧光探针的基本特性
- 腔肠素400A(Coelenteramine 400a)综合解析,一文掌握所有要点!
- Chinese doctor Zhang Junqiao's heroic act exemplifies deep China-Africa friendship: FM spokesperson
- 用Python写了一个上课点名系统(附源码)(自制考勤系统)
- Kubernetes中的PV、PVC、Configmap介绍
- 标签列表
-
- ifneq (61)
- messagesource (56)
- aspose.pdf破解版 (56)
- promise.race (63)
- 2019cad序列号和密钥激活码 (62)
- window.performance (66)
- qt删除文件夹 (72)
- mysqlcaching_sha2_password (64)
- ubuntu升级gcc (58)
- nacos启动失败 (64)
- ssh-add (70)
- jwt漏洞 (58)
- macos14下载 (58)
- yarnnode (62)
- abstractqueuedsynchronizer (64)
- source~/.bashrc没有那个文件或目录 (65)
- springboot整合activiti工作流 (70)
- jmeter插件下载 (61)
- 抓包分析 (60)
- idea创建mavenweb项目 (65)
- vue回到顶部 (57)
- qcombobox样式表 (68)
- vue数组concat (56)
- tomcatundertow (58)
- pastemac (61)
本文暂时没有评论,来添加一个吧(●'◡'●)