Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify Service Invocation sample #902

Merged
merged 3 commits into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions service_invocation/csharp/http/checkout/Program.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using Dapr.Client;

var baseURL = (Environment.GetEnvironmentVariable("BASE_URL") ?? "http://localhost") + ":" + (Environment.GetEnvironmentVariable("DAPR_HTTP_PORT") ?? "3500");

var client = new HttpClient();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
// Adding app id as part of the header
client.DefaultRequestHeaders.Add("dapr-app-id", "order-processor");
var client = DaprClient.CreateInvokeHttpClient(appId: "order-processor");

for (int i = 1; i <= 20; i++) {
var order = new Order(i);
var orderJson = JsonSerializer.Serialize<Order>(order);
var content = new StringContent(orderJson, Encoding.UTF8, "application/json");

var cts = new CancellationTokenSource();
Console.CancelKeyPress += (object? sender, ConsoleCancelEventArgs e) => cts.Cancel();

// Invoking a service
var response = await client.PostAsync($"{baseURL}/orders", content);
var response = await client.PostAsJsonAsync("/orders", order, cts.Token);

Console.WriteLine("Order passed: " + order);

await Task.Delay(TimeSpan.FromSeconds(1));
Expand Down
7 changes: 6 additions & 1 deletion service_invocation/csharp/http/checkout/checkout.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

</Project>
<ItemGroup>
<PackageReference Include="Dapr.Client" Version="1.12.0" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="6.0.0" />
</ItemGroup>

</Project>
Loading