Grpc.Web - Hosting issues under IIS or Application Service Plan
See original GitHub issueWe’ve already got some gRPC clients (Dotnet Core Worker Service) running using reverse proxies and Kestrel and this works fine. But we are keen to switch to App Service Plans (or even a VM and IIS) as this is the business standard approach. As such, this post was a great bit of news and so we quickly set about converting the start up in both client and server to support it.
Having deployed to both VM running IIS and then an Application Service plan we keep getting met with the same error message, I’m fairly sure it’s to do with IIS configuration but I can’t find anything that helps with the issue.
A static page on the application can be displayed and proves the system is running and accepting requests, so it is a purely gRPC issue as far as I can tell.
The VM is running Server 2016 and Dotnet Core 3.1.1 Hosting Bundle and has the latest Windows updates installed, the application was deployed as an In-Process set up. The application service plan we tried was the standard Azure Application Service Plan (Windows based), it returned the same client error as the VM.
gRPC in Visual Studio Debug gives:
Status(StatusCode=Internal, Detail=”Content-Type ‘application/grpc-web-text’ is not supported.”)
The logs from the IIS server show the following:
warn: Microsoft.AspNetCore.DataProtection.Repositories.EphemeralXmlRepository[50] Using an in-memory repository. Keys will not be persisted to storage.
warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[59] Neither user profile nor HKLM registry available. Using an ephemeral key repository. Protected data will be unavailable when application exits.
warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35] No XML encryptor configured. Key {d496f657-222b-4e28-8648-a2619138201f} may be persisted to storage in unencrypted form.
info: Microsoft.Hosting.Lifetime[0] Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0] Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0] Content root path:
fail: Grpc.AspNetCore.Server.ServerCallHandler[6] Error when executing service method ‘AuthenticateApp’.
System.InvalidOperationException: Trailers are not supported for this response. The server may not support gRPC.
at Grpc.AspNetCore.Server.Internal.GrpcProtocolHelpers.GetTrailersDestination(HttpResponse response)
at Grpc.AspNetCore.Server.Internal.HttpResponseExtensions.ConsolidateTrailers(HttpResponse httpResponse, HttpContextServerCallContext context)
at Grpc.AspNetCore.Server.Internal.HttpContextServerCallContext.EndCallCore()
at Grpc.AspNetCore.Server.Internal.HttpContextServerCallContext.EndCallAsync()
at Grpc.AspNetCore.Server.Internal.CallHandlers.ServerCallHandlerBase3.<HandleCallAsync>g__AwaitHandleCall|17_0(HttpContextServerCallContext serverCallContext, Method
2 method, Task handleCall)
fail: Microsoft.AspNetCore.Server.IIS.Core.IISHttpServer[2] Connection ID “7566047384183026471”, Request ID “8000b328-0002-6900-b63f-84710c7967bb”: An unhandled exception was thrown by the application.
System.InvalidOperationException: Trailers are not supported for this response. The server may not support gRPC.
at Grpc.AspNetCore.Server.Internal.GrpcProtocolHelpers.GetTrailersDestination(HttpResponse response)
at Grpc.AspNetCore.Server.Internal.HttpResponseExtensions.ConsolidateTrailers(HttpResponse httpResponse, HttpContextServerCallContext context)
at Grpc.AspNetCore.Server.Internal.HttpContextServerCallContext.ProcessHandlerError(Exception ex, String method)
at Grpc.AspNetCore.Server.Internal.HttpContextServerCallContext.ProcessHandlerErrorAsync(Exception ex, String method)
at Grpc.AspNetCore.Server.Internal.CallHandlers.ServerCallHandlerBase3.<HandleCallAsync>g__AwaitHandleCall|17_0(HttpContextServerCallContext serverCallContext, Method
2 method, Task handleCall)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.g__AwaitMatcher|8_0(EndpointRoutingMiddleware middleware, HttpContext httpContext, Task1 matcherTask)
at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT
1.ProcessRequestAsync()
fail: Grpc.AspNetCore.Server.ServerCallHandler[6] Error when executing service method ‘AuthenticateApp’.
System.InvalidOperationException: Trailers are not supported for this response. The server may not support gRPC. at Grpc.AspNetCore.Server.Internal.GrpcProtocolHelpers.GetTrailersDestination(HttpResponse response) at Grpc.AspNetCore.Server.Internal.HttpResponseExtensions.ConsolidateTrailers(HttpResponse httpResponse, HttpContextServerCallContext context) at Grpc.AspNetCore.Server.Internal.HttpContextServerCallContext.EndCallCore() at Grpc.AspNetCore.Server.Internal.HttpContextServerCallContext.EndCallAsync() at Grpc.AspNetCore.Server.Internal.CallHandlers.ServerCallHandlerBase`3.g__AwaitHandleCall|17_0(HttpContextServerCallContext serverCallCon
Issue Analytics
- State:
- Created 4 years ago
- Comments:34 (14 by maintainers)
Top GitHub Comments
Your problem is UseGrpcWeb needs to be between UseRouting and UseEndpoints.
I finally made it work. My app was running with .NET Core 3.1 runtime which seems not working with Linux AppService.
With a Linux AppService the app (it’s a docker container Behring the scène not managed by me) just doesn’t start:
So I downgraded to .NET Core 3.0 and deployed on a Windows AppService and it works fine now.
It was not a CORS issue, browsers raise an unexpected CORS error when the remote API crashes, because CORS headers are not sent.
Demo here: https://anthonygiretti.blob.core.windows.net/grpcwebdemo/index.html (The Angular 8 app is deployed in static website.)
About my HttpClient which failed to call your AppService I never found the solution, I just started a new project from scratch and it works fine now.
Thanks for your support and I hope this will help people