我正在尝试连接到 .NetFramework 4.5 Windows 应用程序中的 gRPC 服务。我目前正在使用元包 nuget Grpc,我知道它现在仅处于维护模式......
我需要访问不在主机:端口位置但有子路径、子目录的服务。我的服务位于这里“https://example.com/mySubpath https://example.com/mySubpath"
有没有办法在.NetFramework中为gRPC调用指定子目录、子路径?
- 对于.NetFramework4.5,如果我指定完整路径(其中包含“mySubpath”部分),它将不起作用
var channel = new Channel("example.com/mySubpath", ChannelCredentials.SecureSsl);
我看到我还可以向 Channel 构造函数添加一个 List 参数,但不知道是否有一个选项可以用于此目的。
- 我目前正在尝试升级到 .NetFramework 4.6.1,看看是否可以使用 Grpc.Net.Client,我知道如果使用 WinHttpHandler,它比 .NetFramework 4.6.1 有一些支持。 (https://learn.microsoft.com/en-us/aspnet/core/grpc/netstandard?view=aspnetcore-6.0 https://learn.microsoft.com/en-us/aspnet/core/grpc/netstandard?view=aspnetcore-6.0)
我在这里找到了解决方案https://github.com/grpc/grpc-dotnet/issues/880 https://github.com/grpc/grpc-dotnet/issues/880对于.NetCore,我想看看是否可以将其用于.NetFramework 4.6。我使用了链接中定义的 SubdirectoryHandler 类来更改 RequestUri 并分配了一个 WinHttpHandler
var handler = new SubdirectoryHandler(new WinHttpHandler(), subpath);
var httpClient = new HttpClient(handler);
GrpcChannel channel = GrpcChannel.ForAddress(address, new GrpcChannelOptions { HttpClient = httpClient });
但我收到与程序集 System.Buffers、Version=4.0.2.0 相关的异常。
StatusCode="Unavailable",
Detail="Error starting gRPC call. HttpRequestException: Error while copying content to a stream. FileLoadException: Could not load file or assembly 'System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)",
我认为这是因为 Grpc.Net.Client 引用 version=4.0.2.0,而 System.Net.Http.WinHttpHandler 引用版本 4.0.3.0。
知道我需要更改什么才能使用 .NetFramework 4.6.1 或 .NetFramework4.5 的子目录、子路径吗?