GRPC .net framework 4.6.2 连接在 AWS 中托管的服务器时出现问题
GRPC .net framework 4.6.2 problems connecting server hosted in AWS
)
我们正在尝试在 wpf 中开发一个 .net 应用程序,它正在使用部署在 AWS 上的 grpc 服务。
连接是通过 GRPC.
完成的
我们的代码如下:
public static GrpcManagerFactory GetGrpcManagerFactory(ConnectionConfiguration configuration, string connectionString, DataAccess.Util.Enumerations.LogLevel clientLogLevel, bool errorMode)
{
Logger logger = new Logger(connectionString, clientLogLevel);
var caRootsPem = File.ReadAllText(Path.Combine(@"..", "cacert.pem"));
var caRootsKey = new KeyCertificatePair(caRootsPem, File.ReadAllText(Path.Combine(@"..", "AmazonRootCA1.key")));
ChannelCredentials channelCredentials = new SslCredentials(caRootsPem, caRootsKey, VerifyPeerContext);
var channel = new Channel(configuration.GrpcHost, configuration.GrpcPort, channelCredentials, new List<ChannelOption> { });
channel.ConnectAsync(DateTime.Now.AddSeconds(10).ToUniversalTime());
var provider = DataAccess.DataProvider.Grpc.GrpcFactory.GetGrpcFactory(channel, configuration, logger.LogManager.LogController);
var manFactory = new GrpcManagerFactory(provider, channel, connectionString, configuration.InterfaceRetries, clientLogLevel);
manFactory.ErrorMode = errorMode;
return manFactory;
}
当我们尝试执行心跳或 grpc 请求 (.protos) 时,我们收到 DNS 错误,或者所有连接都失败....
有什么想法吗?
这是我们的连接配置
public ConnectionConfiguration ConnectionConfiguration
{
#if DEBUG
get
{
return new ConnectionConfiguration
{
ClientId = _client != null ? _client.ClientId : 0,
InterfaceRetries = _clientPreferences != null ? (_clientPreferences.Depot != null ? _clientPreferences.Depot.InterfaceRetries : 1) : 1,
WenAccessTokenUrl = "token",
WenClientId = "..",
WenClientSecret = "..",
RealWebServices = true,
GrpcHost = "..",
GrpcPort = ..,
GrpcChannelCredentials = ChannelCredentials.Insecure
};
}
}
我们尝试对我们的请求进行自签名,但我们遇到了同样的错误。
错误:
服务的 DNS 解析失败:(AWS 主机)
终于成功了。
.Net Framework 版本 4.6.2
通过以下方式
List<ChannelOption> channelOptions = new List<ChannelOption>()
{
new ChannelOption("grpc.ssl_target_name_override", "services.hosted.in.the.cloud.com"),
};
var channelCreds = new SslCredentials(File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + @".\xxxxxxxxxxxxx.pem"));
var channel = new Channel("services.hosted.in.the.cloud.com", 443, channelCreds, channelOptions);
和系统环境变量..
GRPC_DNS_RESOLVER: native
使用此设置它对我们有用,将 grpc 客户端连接到部署在 aws 云上的服务
)
我们正在尝试在 wpf 中开发一个 .net 应用程序,它正在使用部署在 AWS 上的 grpc 服务。 连接是通过 GRPC.
完成的我们的代码如下:
public static GrpcManagerFactory GetGrpcManagerFactory(ConnectionConfiguration configuration, string connectionString, DataAccess.Util.Enumerations.LogLevel clientLogLevel, bool errorMode)
{
Logger logger = new Logger(connectionString, clientLogLevel);
var caRootsPem = File.ReadAllText(Path.Combine(@"..", "cacert.pem"));
var caRootsKey = new KeyCertificatePair(caRootsPem, File.ReadAllText(Path.Combine(@"..", "AmazonRootCA1.key")));
ChannelCredentials channelCredentials = new SslCredentials(caRootsPem, caRootsKey, VerifyPeerContext);
var channel = new Channel(configuration.GrpcHost, configuration.GrpcPort, channelCredentials, new List<ChannelOption> { });
channel.ConnectAsync(DateTime.Now.AddSeconds(10).ToUniversalTime());
var provider = DataAccess.DataProvider.Grpc.GrpcFactory.GetGrpcFactory(channel, configuration, logger.LogManager.LogController);
var manFactory = new GrpcManagerFactory(provider, channel, connectionString, configuration.InterfaceRetries, clientLogLevel);
manFactory.ErrorMode = errorMode;
return manFactory;
}
当我们尝试执行心跳或 grpc 请求 (.protos) 时,我们收到 DNS 错误,或者所有连接都失败....
有什么想法吗?
这是我们的连接配置
public ConnectionConfiguration ConnectionConfiguration
{
#if DEBUG
get
{
return new ConnectionConfiguration
{
ClientId = _client != null ? _client.ClientId : 0,
InterfaceRetries = _clientPreferences != null ? (_clientPreferences.Depot != null ? _clientPreferences.Depot.InterfaceRetries : 1) : 1,
WenAccessTokenUrl = "token",
WenClientId = "..",
WenClientSecret = "..",
RealWebServices = true,
GrpcHost = "..",
GrpcPort = ..,
GrpcChannelCredentials = ChannelCredentials.Insecure
};
}
}
我们尝试对我们的请求进行自签名,但我们遇到了同样的错误。
错误:
服务的 DNS 解析失败:(AWS 主机)
终于成功了。
.Net Framework 版本 4.6.2
通过以下方式
List<ChannelOption> channelOptions = new List<ChannelOption>()
{
new ChannelOption("grpc.ssl_target_name_override", "services.hosted.in.the.cloud.com"),
};
var channelCreds = new SslCredentials(File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + @".\xxxxxxxxxxxxx.pem"));
var channel = new Channel("services.hosted.in.the.cloud.com", 443, channelCreds, channelOptions);
和系统环境变量..
GRPC_DNS_RESOLVER: native
使用此设置它对我们有用,将 grpc 客户端连接到部署在 aws 云上的服务