为什么我在尝试从 gRPC 服务获取数据时得到 Grpc.Core.RpcException 写入 .net 核心

Why am I getting an Grpc.Core.RpcException when trying to get data from gRPC service written .net core

我有一个 gRPC 服务(用 .net core 3.1 编写)部署在 windows 服务器中作为 kerstel 中的自托管服务 运行。

我添加了以下配置以在 https.

中获取服务 运行
"Kestrel": {
"EndpointDefaults": {
  "Protocols": "Http2"
},
"Endpoints": {
  "HttpsInlineCertFile": {
    "Url": "https://hostname:8081",
    "Protocols": "Http2",
    "Certificate": {
      "Path": "path to .pfx file",
      "Password": "Super secret password"
    }
  }
}

使用下面的代码

using GrpcChannel channel = GrpcChannel.ForAddress(httpsHost);
var client = new MyClient(channel);
var response = client.GetEntity(RequestCreator.GetRequest());
Console.WriteLine("Recieved: " + response.ToString());

我得到下面的异常,内部异常为空。

Status(StatusCode=Internal, Detail="Error starting gRPC call: The SSL connection could not be established, see inner exception.")

我应该添加什么来让客户端从服务中获取数据吗?

提前致谢

抱歉,我的问题回复晚了。问题是代理。我最终做的是创建一个 webproxy,将 gRPC 服务 url 添加到 bypassArrayList,创建 httpClientHandler,分配创建的 proyx,然后创建一个使用该 httpClientHandler 的 httpClient。

        var proxy = new WebProxy
        {
            Address = new Uri(proxyServer),
            UseDefaultCredentials = true,
            BypassProxyOnLocal = true,
            Credentials = CredentialCache.DefaultNetworkCredentials
        };

        proxy.BypassArrayList.Add(serviceUrl);

        var httpClientHandler = new HttpClientHandler
        {
            Proxy = proxy,
            DefaultProxyCredentials = CredentialCache.DefaultNetworkCredentials,
            UseDefaultCredentials = true,
            UseProxy = true,
        };
        var client = new HttpClient(httpClientHandler)
        {
            DefaultRequestVersion = HttpVersion.Version20
        };

        using var channel = GrpcChannel.ForAddress(serviceUrl, new GrpcChannelOptions
        {
            HttpClient = client
        });