-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
62 lines (50 loc) · 2 KB
/
Program.cs
File metadata and controls
62 lines (50 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System.Net;
using Grpc.Net.Client;
using SampleGrpcClient.DataTransferObjects;
namespace SampleGrpcClient;
class Program
{
static void Main(string[] args)
{
#region Init
// Configure Http client
var httpClient = ConfigureHttpClient();
// Create mapper
var mapper = new MapsterMapper.Mapper();
// Create new configuration for converting data
mapper.Config.NewConfig<SampleData, SampleGrpcDto>()
.ConstructUsing(src => new SampleGrpcDto(src.Id, src.CreateDate, src.UpdateDate, src.SampleStringData, src.SampleIntData));
// Create sample grpc client
var sampleClient = new Sample.SampleClient(
GrpcChannel.ForAddress(
address: "https://localhost:5111",
channelOptions: new GrpcChannelOptions()
{
HttpClient = httpClient,
MaxRetryAttempts = 5,
}
)
);
#endregion
// Call
var replyResult = sampleClient.GetAll(new GetAllRequest(), new Grpc.Core.Metadata());
// Map and print out data
var mappedSampleData = mapper.Map<List<SampleData>>(replyResult.Sample);
var mappedValue = mapper.Map<List<SampleGrpcDto>>(mappedSampleData);
foreach (var data in mappedValue)
{
System.Console.WriteLine("Guid: {0}, Create Date: {1}, Update Date: {2}, Sample String: {3}, Sample Int: {4}"
, data.Id, data.CreateDate, data.UpdateDate, data.SampleStringData, data.SampleIntData);
}
}
static HttpClient ConfigureHttpClient()
{
// Create new http client
var httpClient = new HttpClient();
// Set http request version to Http3
httpClient.DefaultRequestVersion = HttpVersion.Version30;
// Set default version policy to accept Http3 or lower version of http
httpClient.DefaultVersionPolicy = HttpVersionPolicy.RequestVersionOrLower;
return httpClient;
}
}