You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have followed the HTTP/1 client sample in this commit. However, I'm still having trouble getting it to work with gRPC. I've successfully set up the server and the client using .proto files, but the client's requests are not being processed (Internal Server Error). I suspect this is because the default protocol is HTTP, and I either need to call the client using the gRPC endpoint or, in some cases, create an interceptor to send additional metadata for the routing service.
Is there a recommended approach that is guaranteed to work with Aspire? It would be helpful for others participating in this discussion, especially since the documentation is still relatively new and the sample projects often employ similar setups that do not function well with gRPC clients generated from protobuf files.
usingDapr.Client;usingGrpc.Core;usingGrpc.Net.Client;usingMicrosoft.AspNetCore.Authentication;usingMicrosoft.AspNetCore.Authorization;usingMicrosoft.AspNetCore.Mvc;usingTestService1.Clients;usingTestService2;varbuilder=WebApplication.CreateBuilder(args);// Add services to the container.// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapibuilder.Services.AddOpenApi();builder.Services.AddDaprClient();// Adds Dapr authentication. By default, the token will be read from the APP_API_TOKEN environment variable.builder.Services.AddAuthentication().AddDapr();builder.Services.AddAuthorization(options =>{// Adds Dapr authorization. The authentication scheme is "Dapr."options.AddDapr();});varinvoker=DaprClient.CreateInvocationInvoker(appId:"service2",daprApiToken:Environment.GetEnvironmentVariable("APP_API_TOKEN"));vargreetClient=newGreeter.GreeterClient(invoker);builder.Services.AddSingleton<Greeter.GreeterClient>(greetClient);varapp=builder.Build();// Configure the HTTP request pipeline.if(app.Environment.IsDevelopment()){app.MapOpenApi();}app.UseHttpsRedirection();app.MapGet("/weatherforecast",async(DaprClientclient,[FromQuery]intpageSize=10)=>{returnawaitnewWeatherClient(client).GetWeatherForecastAsync(pageSize);}).WithName("GetWeatherForecast");app.MapGet("/greet",async(DaprClientclient,[FromQuery]stringname)=>{returnawaitclient.InvokeMethodGrpcAsync<HelloRequest,HelloReply>("service2","SayHello",newHelloRequest{Name=name});//return await client.SayHelloAsync(new HelloRequest() { Name = name });}).WithName("GetGreet");app.Run();publicrecordWeatherForecast(DateOnlyDate,intTemperatureC,string?Summary){publicintTemperatureF=>32+(int)(TemperatureC/0.5556);}//...
usingGrpc.Net.Client;usingMicrosoft.AspNetCore.Authentication;usingMicrosoft.AspNetCore.Authorization;usingSystem.Reflection;usingTestService2.Controllers.GRPC;varbuilder=WebApplication.CreateBuilder(args);// Add services to the container.// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapibuilder.Services.AddOpenApi();builder.Services.AddDaprClient();builder.Services.AddGrpc();builder.Services.AddControllers();// Adds Dapr authentication. By default, the token will be read from the APP_API_TOKEN environment variable.builder.Services.AddAuthentication().AddDapr();builder.Services.AddAuthorization(options =>{// Adds Dapr authorization. Authentication scheme is "Dapr"options.AddDapr();});varapp=builder.Build();// Configure the HTTP request pipeline.if(app.Environment.IsDevelopment()){app.MapOpenApi();}app.UseAuthentication();app.UseAuthorization();//app.UseHttpsRedirection();//app.UseRouting();app.MapGrpcService<GreeterService>();app.MapGet("/",()=>"Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909");app.MapControllers();app.Run();
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I have followed the HTTP/1 client sample in this commit. However, I'm still having trouble getting it to work with gRPC. I've successfully set up the server and the client using .proto files, but the client's requests are not being processed (Internal Server Error). I suspect this is because the default protocol is HTTP, and I either need to call the client using the gRPC endpoint or, in some cases, create an interceptor to send additional metadata for the routing service.
Is there a recommended approach that is guaranteed to work with Aspire? It would be helpful for others participating in this discussion, especially since the documentation is still relatively new and the sample projects often employ similar setups that do not function well with gRPC clients generated from protobuf files.
My current code setup samples:
AppHost
Service 1 (Server)
Service 1 project file
Service 2 (Client<->Server)
Service 2 project file
Client (Browser) Requests Server 2, which requests Server 1
Latest error with this setup:
Beta Was this translation helpful? Give feedback.
All reactions