-
Notifications
You must be signed in to change notification settings - Fork 769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue when using GrpcClient with HttpClientFactory on .NET 6 #1478
Comments
@thangchung Can you point to which doc you're using? The error you're seeing is expected because GrpcClient doesn't use HttpClient (and therefore you can't use ConfigureHttpClient). If you can share what you're trying to do with the ConfigureHttpClient, we might be able to help provide an alternate way to accomplish that. |
@adityamandaleeka I followed the guidance to add the support HTTP/3 for gPRC, the server part is okay, I can run it. But the gRPC client whenever I configure with httpClient.DefaultRequestVersion = HttpVersion.Version30;
httpClient.DefaultVersionPolicy = HttpVersionPolicy.RequestVersionExact; Then it did not allow me to do that, always throw the exception above. It's strange. The blog for setting it up at https://devblogs.microsoft.com/dotnet/http-3-support-in-dotnet-6/#grpc-with-http-3 |
You can set those properties using a Instead of configuring the channel to use the delegating handler, you'll configure client factory to use it. |
Hi @JamesNK and @adityamandaleeka , I would like to confirm that after following the docs that you wrote, then it works. But with some of the changes so that I put it here for someone who has got the issue just like me gRPC ServerWe have set up the using System.Net;
using AuditCenter.Services;
using Microsoft.AspNetCore.Server.Kestrel.Core;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddGrpc();
builder.WebHost.ConfigureKestrel((context, options) =>
{
options.Listen(IPAddress.Any, 5001, listenOptions =>
{
listenOptions.Protocols = HttpProtocols.Http3;
listenOptions.UseHttps();
});
});
var app = builder.Build();
app.UseHttpLogging();
// Configure the HTTP request pipeline.
app.MapGrpcService<GreeterService>();
app.MapGrpcService<AuditService>();
app.MapGet("/",
() =>
"AuditService is ready to serve you!!! What do you want from me?");
app.Run(); And after the run, it should run at gRPC ClientThe
<ItemGroup>
<RuntimeHostConfigurationOption Include="System.Net.SocketsHttpHandler.Http3Support" Value="true" />
</ItemGroup> The docs for it can be found at https://docs.microsoft.com/en-us/dotnet/core/extensions/httpclient-http3#using-httpclient
public class Http3Handler : DelegatingHandler
{
public Http3Handler(HttpMessageHandler innerHandler)
: base(innerHandler)
{
}
protected override Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request, CancellationToken cancellationToken)
{
request.Version = HttpVersion.Version30;
request.VersionPolicy = HttpVersionPolicy.RequestVersionExact;
return base.SendAsync(request, cancellationToken);
}
} And configure for gRPC Client builder.Services
.AddGrpcClient<Auditor.AuditorClient>("Auditor", o =>
{
o.Address = new Uri("https://localhost:5001");
})
.ConfigureChannel(options =>
{
options.HttpHandler = new Http3Handler(new HttpClientHandler());
})
.EnableCallContextPropagation(o => o.SuppressContextNotFoundErrors = true); And now we can run it perfectly. Thank you again for the guidance and shed the light on it @JamesNK 👍 |
Great. Thanks for the feedback. I've improved the doc some more: dotnet/AspNetCore.Docs#23857 |
What version of gRPC and what language are you using?
<PackageReference Include="Grpc.AspNetCore" Version="2.40.0" />
What operating system (Linux, Windows,...) and version?
Windows 11
What runtime / compiler are you using (e.g. .NET Core SDK version
dotnet --info
).NET 6.0.100
What did you do?
I just followed the guidance from MS docs to create the client and server using gRPC. The server part runs fine without errors.
But the client whenever I add the code below
What did you expect to see?
I expect the client part should run fine with the
ConfigureHttpClient
function in-placeWhat did you see instead?
The exception
The text was updated successfully, but these errors were encountered: