Reputation: 65
I'm trying to migrate grpc server to the new package.
The app that hosts the grpc server runs on IIS Experess and uses the ASP.NET Core 3.1 framework.
In the old version, we built a server (from Grpc.Core) and defined the host and port (this port is different from the iis port):
// var grpcServer = new Server
// {
// Services =
// {
// },
// Ports = { new ServerPort("localhost", 50055, ServerCredentials.Insecure) },
// RequestCallTokensPerCompletionQueue = 32768
// };
// grpcServer.Start();
Now that server class is not available in Grpc.AspNetCore.Server
, we use services.AddGrpc
, but there's nowhere to define the port we need:
services.AddGrpc(options =>
{
options.EnableDetailedErrors = true;
});
and:
app.UseEndpoints(endpoints =>
{
endpoints.MapGrpcService<AppProtosImpl>().RequireHost($"http://localhost:50055");
});
My launchSettings.json
is :
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:53590",
"sslPort": 44313
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Debug",
"APP_VERSION": ""
},
"ancmHostingModel": "OutOfProcess"
},
To sum up, I need that my app will listen to both ports: 50055 and 53590.
Does anybody know how to do it?
Thanks
Upvotes: 1
Views: 367
Reputation: 2912
What server are you using? As far as I know, there seems to be no way to set a specific port for the GRPC service. If your ASP.NET Core application only has GRPC services, you can set the port for listening on the kestrel server. The Grpc service is also running on the asp.net core kestrel server, the server will listen on the port instead of the service. If you have multiple services, such as MVC web api or other services, RequireHost is the best solution to allow only specific ports to access grpc services. If you want to prompt that the routing system of the GRPC service needs to specify a port, you can use the following ports:
routes.MapGrpcService<MyService>().RequireHost("*:port")
;
For the monitoring configuration of Kestrel server, refer to this post:
Bind gRPC services to specific port in aspnetcore
Upvotes: 1