文章目录
- 前言
- 一、问题一解决方法
- 二、问题二解决方法
前言
第一次建立GRPC服务端,客服端一直通不到服务端;
问题1:
One or more errors occurred. (Status(StatusCode=Internal, Detail="Error starting gRPC call. HttpRequestException: The SSL connection could not be established, see inner exception. IOException: The handshake failed due to an unexpected packet format."))
Status(StatusCode=Internal, Detail="Error starting gRPC call. HttpRequestException: The SSL connection could not be established, see inner exception. IOException: The handshake failed due to an unexpected packet format.")
问题2:
One or more errors occurred. (Status(StatusCode="Unimplemented", Detail="Bad gRPC response. HTTP status code: 404"))
Status(StatusCode="Unimplemented", Detail="Bad gRPC response. HTTP status code: 404")
参考链接:Go-gRPC 实践指南
一、问题一解决方法
原因:
gRPC默认内置了两种认证方式:
SSL/TLS认证方式
基于Token的认证方式
服务端建立https即可
二、问题二解决方法
原因是因为服务端没有注册成功GRPC
1.需要配置GRPC,在ConfigureServices方法中
//1.配置grpc
services.AddGrpc();
2.开启GRPC,在ConfigRoute方法中
app.UseEndpoints(endpoints =>{//2开启Grpcendpoints.MapGrpcService<GisPointDeviceServiceImpl>();endpoints.MapControllers();});
GisPointDeviceServiceImpl,是对应的服务
- 第三步在报错前是已经做过的;
在ConfigureProduction方法中加入以下代码
string address = Environment.GetEnvironmentVariable("TSPSERVER_ADDRESS", EnvironmentVariableTarget.Process);
app.UseConsul(address, "GIS", address);
string grpcAddress = Environment.GetEnvironmentVariable("TSPGRPC_ADDRESS", EnvironmentVariableTarget.Process);
app.UseConsul(grpcAddress, "GISGrpc", address);