-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0cf5f21
commit b263a01
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
The solution contains two solutions | ||
1. OrderService (gRPC service) | ||
2. Consumer ( Console Application) | ||
|
||
## OrderService | ||
|
||
Open the Protos\order.proto file and define your service: | ||
every new method you define here will be avaliable for implementation under your Service class | ||
|
||
Implement the service logic: | ||
Open the Services\OrderService.cs file and implement the endpoint defined in proto file. | ||
|
||
Open proto file properties | ||
Build action: Protobuf compiler | ||
gRPC Stub class: server only | ||
|
||
 | ||
|
||
## Consumer | ||
|
||
Add in csproj file: | ||
``` | ||
<ItemGroup> | ||
<PackageReference Include="Grpc.Net.Client" Version="2.41.0" /> | ||
<PackageReference Include="Google.Protobuf" Version="3.18.0" /> | ||
<PackageReference Include="Grpc.Tools" Version="2.41.0" /> | ||
</ItemGroup> | ||
``` | ||
|
||
Add refernec to your server project | ||
|
||
Add proto file | ||
in properties: | ||
Build action: Protobuf compiler | ||
gRPC Stub class: client only | ||
|
||
Create Channel | ||
using var channel = GrpcChannel.ForAddress("http://localhost:5039") #your uri to service, configure in appsettings | ||
|
||
Create Client | ||
var client = new Order.OrderClient(channel); | ||
|
||
Call Method | ||
var request = new BillingRequest { Name = name, Product = "Bread", Quantity = quantity }; | ||
var response = client.Checkout(request); | ||
|
||
Now, Run both the projects and give inputs to the prompts on the console: | ||
|
||
 | ||
|
||
|