Događaj
Power BI DataViz Svetsko prvenstvo
14. feb 16 - 31. mar 16
Sa 4 šanse za ulazak, možete osvojiti konferencijski paket i stići do LIVE Grand Finale u Las Vegasu
Saznajte višeOvaj pregledač više nije podržan.
Nadogradite na Microsoft Edge biste iskoristili najnovije funkcije, bezbednosne ispravke i tehničku podršku.
Napomena
This isn't the latest version of this article. For the current release, see the .NET 9 version of this article.
Upozorenje
This version of ASP.NET Core is no longer supported. For more information, see the .NET and .NET Core Support Policy. For the current release, see the .NET 9 version of this article.
Važno
This information relates to a pre-release product that may be substantially modified before it's commercially released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
For the current release, see the .NET 9 version of this article.
gRPC is a language agnostic, high-performance Remote Procedure Call (RPC) framework.
The main benefits of gRPC are:
These benefits make gRPC ideal for:
gRPC uses a contract-first approach to API development. Services and messages are defined in .proto
files:
syntax = "proto3";
service Greeter {
rpc SayHello (HelloRequest) returns (HelloReply);
}
message HelloRequest {
string name = 1;
}
message HelloReply {
string message = 1;
}
.NET types for services, clients, and messages are automatically generated by including .proto
files in a project:
.proto
files to the <Protobuf>
item group.<ItemGroup>
<Protobuf Include="Protos\greet.proto" />
</ItemGroup>
For more information on gRPC tooling support, see gRPC services with C#.
gRPC services can be hosted on ASP.NET Core. Services have full integration with ASP.NET Core features such as logging, dependency injection (DI), authentication, and authorization.
gRPC requires the Grpc.AspNetCore package. For information on configuring gRPC in a .NET app, see Configure gRPC.
The ASP.NET Core gRPC Service project template provides a starter service:
public class GreeterService : Greeter.GreeterBase
{
private readonly ILogger<GreeterService> _logger;
public GreeterService(ILogger<GreeterService> logger)
{
_logger = logger;
}
public override Task<HelloReply> SayHello(HelloRequest request,
ServerCallContext context)
{
_logger.LogInformation("Saying hello to {Name}", request.Name);
return Task.FromResult(new HelloReply
{
Message = "Hello " + request.Name
});
}
}
GreeterService
inherits from the GreeterBase
type, which is generated from the Greeter
service in the .proto
file. The service is made accessible to clients in Program.cs
:
app.MapGrpcService<GreeterService>();
To learn more about gRPC services on ASP.NET Core, see gRPC services with ASP.NET Core.
gRPC clients are concrete client types that are generated from .proto
files. The concrete gRPC client has methods that translate to the gRPC service in the .proto
file.
var channel = GrpcChannel.ForAddress("https://localhost:5001");
var client = new Greeter.GreeterClient(channel);
var response = await client.SayHelloAsync(
new HelloRequest { Name = "World" });
Console.WriteLine(response.Message);
A gRPC client is created using a channel, which represents a long-lived connection to a gRPC service. A channel can be created using GrpcChannel.ForAddress
.
For more information on creating clients, and calling different service methods, see Call gRPC services with the .NET client.
gRPC is a language agnostic, high-performance Remote Procedure Call (RPC) framework.
The main benefits of gRPC are:
These benefits make gRPC ideal for:
gRPC uses a contract-first approach to API development. Services and messages are defined in .proto
files:
syntax = "proto3";
service Greeter {
rpc SayHello (HelloRequest) returns (HelloReply);
}
message HelloRequest {
string name = 1;
}
message HelloReply {
string message = 1;
}
.NET types for services, clients, and messages are automatically generated by including .proto
files in a project:
.proto
files to the <Protobuf>
item group.<ItemGroup>
<Protobuf Include="Protos\greet.proto" />
</ItemGroup>
For more information on gRPC tooling support, see gRPC services with C#.
gRPC services can be hosted on ASP.NET Core. Services have full integration with ASP.NET Core features such as logging, dependency injection (DI), authentication, and authorization.
gRPC requires the Grpc.AspNetCore package. For information on configuring gRPC in a .NET app, see Configure gRPC.
The gRPC service project template provides a starter service:
public class GreeterService : Greeter.GreeterBase
{
private readonly ILogger<GreeterService> _logger;
public GreeterService(ILogger<GreeterService> logger)
{
_logger = logger;
}
public override Task<HelloReply> SayHello(HelloRequest request,
ServerCallContext context)
{
_logger.LogInformation("Saying hello to {Name}", request.Name);
return Task.FromResult(new HelloReply
{
Message = "Hello " + request.Name
});
}
}
GreeterService
inherits from the GreeterBase
type, which is generated from the Greeter
service in the .proto
file. The service is made accessible to clients in Startup.cs
:
app.UseEndpoints(endpoints =>
{
endpoints.MapGrpcService<GreeterService>();
});
To learn more about gRPC services on ASP.NET Core, see gRPC services with ASP.NET Core.
gRPC clients are concrete client types that are generated from .proto
files. The concrete gRPC client has methods that translate to the gRPC service in the .proto
file.
var channel = GrpcChannel.ForAddress("https://localhost:5001");
var client = new Greeter.GreeterClient(channel);
var response = await client.SayHelloAsync(
new HelloRequest { Name = "World" });
Console.WriteLine(response.Message);
A gRPC client is created using a channel, which represents a long-lived connection to a gRPC service. A channel can be created using GrpcChannel.ForAddress
.
For more information on creating clients, and calling different service methods, see Call gRPC services with the .NET client.
Povratne informacije za ASP.NET Core
ASP.NET Core je projekat otvorenog koda. Izaberite vezu da biste pružili povratne informacije:
Događaj
Power BI DataViz Svetsko prvenstvo
14. feb 16 - 31. mar 16
Sa 4 šanse za ulazak, možete osvojiti konferencijski paket i stići do LIVE Grand Finale u Las Vegasu
Saznajte višeObuka
Putanja učenja
Create cloud-native apps and services with .NET and ASP.NET Core - Training
Create independently deployable, highly scalable, and resilient apps and services using the free and open-source .NET platform. With .NET you can use popular microservice technology like Docker, Kubernetes, Dapr, Azure Container Registry, and more for .NET and ASP.NET Core applications and services.
Dokumentacija
Create a .NET Core gRPC client and server in ASP.NET Core
This tutorial shows how to create a gRPC Service and gRPC client on ASP.NET Core. Learn how to create a gRPC Service project, edit a proto file, and add a duplex streaming call.
Learn the basic concepts when writing gRPC services with C#.
Migrate gRPC from C-core to gRPC for .NET
Learn how to move an existing C-core based gRPC app to run on top of gRPC for .NET.