简体   繁体   中英

Grpc client in .net standard fails when called from .net framework, but not .net core 3.1

This is my setup:

  • A: .Net Standard version=2.0 (gRPC Client library)
  • B: .Net Framework version=4.8 (web application - uses the client library)
  • C: .Net Core version=3.1 (WPF application - uses the client library)
  • D: .Net Core version=3.1 (gRPC Server, my own creation)
  • E: .Net Core Version=3 or 5 - I'm not sure. (gRPC Server, production)

Error = "HTTP/2 over TLS was not negotiated on an HTTP/2-only endpoint."

So... Someone else implemented this Grpc Server (E). I can call this one with both applications. No errors.

But to get a nice development environment for developing the two applications, I got the proto-file from the production server and developed my own implementation (D). I use this for testing error handling in the clients - I can control which responses the server gives.

I implemented two exactly alike unit tests, which are in fact integration tests. One in a .net framework project and one in a .net core project.

And it works for .net core test, but not the .net framework.

However, if I inject a WinHttpHandler instead of the HttpClientHandler , then it works. I really do not want to have to inject a handler (it's not even an interface).

Also the production gRPC server works, as mentioned before. But I do not know why mine fails and the production gRPC server works.

I think somehow my own implementation of the gRPC service is wrong (or lacking) but I do not know what I am missing.

Please help!

节目班

创业班

Grpc.Net.Client only works on .NET Framework (as opposed to .NET Core and .NET5+) with limitations. The reason is that .NET Framework doesn't really have a HTTP/2 implementation, which is a requirement for gRPC protocol (but not for grpc-web, it that's an option for you).

Grpc.Net.Client works on .NET Framework to some extent with WinHttpHandler (as you've discovered). The limitations are documented here:

Actually, I had this in my appsetting.json (which I had copied from another project):

"Kestrel": {
    "EndpointDefaults": {
      "Protocols": "Http2"
    }

Of cause, deleting that from the file solved my problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM