diff --git a/all.sln b/all.sln index 8f5cd97d0..53399a78c 100644 --- a/all.sln +++ b/all.sln @@ -64,8 +64,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Client", "Client", "{A7F410 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StateManagement", "examples\Client\StateManagement\StateManagement.csproj", "{F70AC78E-8925-4770-832A-2FC67A620EB2}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServiceInvocation", "examples\Client\ServiceInvocation\ServiceInvocation.csproj", "{8B570E70-0E73-4042-A4B6-1CC3CC782A65}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dapr.E2E.Test", "test\Dapr.E2E.Test\Dapr.E2E.Test.csproj", "{4AA9E7B7-36BF-4AAE-BFA3-C9CE8740F4A0}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dapr.E2E.Test.App", "test\Dapr.E2E.Test.App\Dapr.E2E.Test.App.csproj", "{345FC3FB-D1E9-4AE8-9052-17D20AB01FA2}" @@ -327,10 +325,6 @@ Global {F70AC78E-8925-4770-832A-2FC67A620EB2}.Debug|Any CPU.Build.0 = Debug|Any CPU {F70AC78E-8925-4770-832A-2FC67A620EB2}.Release|Any CPU.ActiveCfg = Release|Any CPU {F70AC78E-8925-4770-832A-2FC67A620EB2}.Release|Any CPU.Build.0 = Release|Any CPU - {8B570E70-0E73-4042-A4B6-1CC3CC782A65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8B570E70-0E73-4042-A4B6-1CC3CC782A65}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8B570E70-0E73-4042-A4B6-1CC3CC782A65}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8B570E70-0E73-4042-A4B6-1CC3CC782A65}.Release|Any CPU.Build.0 = Release|Any CPU {4AA9E7B7-36BF-4AAE-BFA3-C9CE8740F4A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {4AA9E7B7-36BF-4AAE-BFA3-C9CE8740F4A0}.Debug|Any CPU.Build.0 = Debug|Any CPU {4AA9E7B7-36BF-4AAE-BFA3-C9CE8740F4A0}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -636,7 +630,6 @@ Global {CC0A5C98-ACDE-4139-BA2F-2995A9B8E18C} = {02374BD0-BF0B-40F8-A04A-C4C4D61D4992} {A7F41094-8648-446B-AECD-DCC2CC871F73} = {D687DDC4-66C5-4667-9E3A-FD8B78ECAA78} {F70AC78E-8925-4770-832A-2FC67A620EB2} = {A7F41094-8648-446B-AECD-DCC2CC871F73} - {8B570E70-0E73-4042-A4B6-1CC3CC782A65} = {A7F41094-8648-446B-AECD-DCC2CC871F73} {F80F837E-D2FC-4FFC-B68F-3CF0EC015F66} = {A7F41094-8648-446B-AECD-DCC2CC871F73} {35031EDB-C0DE-453A-8335-D2EBEA2FC640} = {A7F41094-8648-446B-AECD-DCC2CC871F73} {07578B6C-9B96-4B3D-BA2E-7800EFCA7F99} = {27C5D71D-0721-4221-9286-B94AB07B58CF} diff --git a/examples/Client/ConfigurationApi/Controllers/ConfigurationController.cs b/examples/Client/ConfigurationApi/Controllers/ConfigurationController.cs index faad24079..e0b783f34 100644 --- a/examples/Client/ConfigurationApi/Controllers/ConfigurationController.cs +++ b/examples/Client/ConfigurationApi/Controllers/ConfigurationController.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Threading.Tasks; using ControllerSample; using Dapr; @@ -54,6 +55,7 @@ public Task SubscribeAndWatchConfiguration() #nullable enable [HttpPost("withdraw")] + [Obsolete] public async Task> CreateAccountHandler(Transaction transaction) { // Check if the V2 method is enabled. @@ -83,4 +85,4 @@ public async Task> CreateAccountHandler(Transaction transa return await this.client.InvokeMethodAsync("controller", "withdraw", transaction); } #nullable disable -} \ No newline at end of file +} diff --git a/examples/Client/DistributedLock/Controllers/BindingController.cs b/examples/Client/DistributedLock/Controllers/BindingController.cs index bd056564b..64228df43 100644 --- a/examples/Client/DistributedLock/Controllers/BindingController.cs +++ b/examples/Client/DistributedLock/Controllers/BindingController.cs @@ -18,7 +18,6 @@ public class BindingController(DaprClient client, ILogger log private string appId = Environment.GetEnvironmentVariable("APP_ID"); [HttpPost("cronbinding")] - [Obsolete] public async Task HandleBindingEvent() { logger.LogInformation("Received binding event on {appId}, scanning for work.", appId); @@ -40,7 +39,6 @@ public async Task HandleBindingEvent() return Ok(); } - [Obsolete] private async Task AttemptToProcessFile(string fileName) { // Locks are Disposable and will automatically unlock at the end of a 'using' statement. @@ -78,7 +76,6 @@ private async Task AttemptToProcessFile(string fileName) } } - [Obsolete] private async Task GetFile(string fileName) { try diff --git a/examples/Client/DistributedLock/Services/GeneratorService.cs b/examples/Client/DistributedLock/Services/GeneratorService.cs index 345ce2247..29d0ef6db 100644 --- a/examples/Client/DistributedLock/Services/GeneratorService.cs +++ b/examples/Client/DistributedLock/Services/GeneratorService.cs @@ -9,7 +9,6 @@ public class GeneratorService { Timer generateDataTimer; - [Obsolete] public GeneratorService() { // Generate some data every second. @@ -19,7 +18,6 @@ public GeneratorService() } } - [Obsolete] public async void GenerateData(Object stateInfo) { using (var client = new DaprClientBuilder().Build()) @@ -27,7 +25,6 @@ public async void GenerateData(Object stateInfo) var rand = new Random(); var state = new StateData(rand.Next(100)); - // NOTE: It is no longer best practice to use this method - this example will be modified in the 1.18 release await client.InvokeBindingAsync("localstorage", "create", state); } } diff --git a/examples/Client/DistributedLock/Startup.cs b/examples/Client/DistributedLock/Startup.cs index daf9ee469..d6f2f58c2 100644 --- a/examples/Client/DistributedLock/Startup.cs +++ b/examples/Client/DistributedLock/Startup.cs @@ -18,7 +18,6 @@ public Startup(IConfiguration configuration) public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. - [Obsolete] public void ConfigureServices(IServiceCollection services) { services.AddControllers().AddDapr(); diff --git a/examples/Client/ServiceInvocation/Example.cs b/examples/Client/ServiceInvocation/Example.cs deleted file mode 100644 index 507bdcfd8..000000000 --- a/examples/Client/ServiceInvocation/Example.cs +++ /dev/null @@ -1,24 +0,0 @@ -// ------------------------------------------------------------------------ -// Copyright 2021 The Dapr Authors -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// ------------------------------------------------------------------------ - -using System.Threading; -using System.Threading.Tasks; - -namespace Samples.Client; - -public abstract class Example -{ - public abstract string DisplayName { get; } - - public abstract Task RunAsync(CancellationToken cancellationToken); -} \ No newline at end of file diff --git a/examples/Client/ServiceInvocation/InvokeServiceGrpcByDaprProxyExample.cs b/examples/Client/ServiceInvocation/InvokeServiceGrpcByDaprProxyExample.cs deleted file mode 100644 index 47fa2dc53..000000000 --- a/examples/Client/ServiceInvocation/InvokeServiceGrpcByDaprProxyExample.cs +++ /dev/null @@ -1,82 +0,0 @@ -// ------------------------------------------------------------------------ -// Copyright 2021 The Dapr Authors -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// ------------------------------------------------------------------------ - -using System; -using System.Threading; -using System.Threading.Tasks; -using Dapr.Client; -using Grpc.Net.Client; -using GrpcServiceSample.Generated; - -namespace Samples.Client -{ - public class InvokeServiceGrpcByDaprProxyExample : Example - { - public override string DisplayName => "Invoking a existing proto-based gRPC service with DaprClient"; - public override async Task RunAsync(CancellationToken cancellationToken) - { - Console.WriteLine("** use sdk created client **"); - await UseSdkCreateClient(cancellationToken); - Console.WriteLine("** use sdk created client completed **"); - - Console.WriteLine("** use grpc client **"); - await UseSdkCreateClient(cancellationToken); - Console.WriteLine("** use grpc client completed **"); - } - - private async Task UseSdkCreateClient(CancellationToken cancellationToken) - { - var invoker = DaprClient.CreateInvocationInvoker("grpcsample"); - var client = new Greeter.GreeterClient(invoker); - - await InvokeExample(client, cancellationToken); - } - private async Task UseGrpcClientOnly(CancellationToken cancellationToken) - { - var daprEndpoint = Environment.GetEnvironmentVariable("DAPR_GRPC_ENDPOINT"); - if (string.IsNullOrEmpty(daprEndpoint)) - { - throw new InvalidOperationException("Dapr endpoint not set"); - } - var channel = GrpcChannel.ForAddress(daprEndpoint); - var client = new Greeter.GreeterClient(channel); - - await InvokeExample(client, cancellationToken); - } - private static async Task InvokeExample(Greeter.GreeterClient client, CancellationToken cancellationToken) - { - - Console.WriteLine("Invoking grpc SayHello"); - var helloRequest = new HelloRequest { Name = "a request through dapr" }; - var helloReply = await client.SayHelloAsync(helloRequest, cancellationToken: cancellationToken); - Console.WriteLine("Returned: message:{0}", helloReply.Message); - Console.WriteLine("Completed grpc SayHello"); - - Console.WriteLine("Invoking grpc Bi-directional streaming SayHelloStream"); - var helloStream = client.SayHelloStream(cancellationToken: cancellationToken); - for (int i = 0; i < 5; i++) - { - var helloStreamRequest = new HelloRequest { Name = $"a request through dapr {i}" }; - await helloStream.RequestStream.WriteAsync(helloStreamRequest); - if (!await helloStream.ResponseStream.MoveNext(cancellationToken)) - { - break; - } - Console.WriteLine("Returned: message:{0}", helloStream.ResponseStream.Current.Message); - } - Console.WriteLine("Completed grpc Bi-directional streaming SayHelloStream"); - } - - - } -} diff --git a/examples/Client/ServiceInvocation/InvokeServiceGrpcExample.cs b/examples/Client/ServiceInvocation/InvokeServiceGrpcExample.cs deleted file mode 100644 index 127d90037..000000000 --- a/examples/Client/ServiceInvocation/InvokeServiceGrpcExample.cs +++ /dev/null @@ -1,47 +0,0 @@ -// ------------------------------------------------------------------------ -// Copyright 2021 The Dapr Authors -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// ------------------------------------------------------------------------ - -using System; -using System.Threading; -using System.Threading.Tasks; -using Dapr.Client; -using GrpcServiceSample.Generated; - -namespace Samples.Client; - -public class InvokeServiceGrpcExample : Example -{ - public override string DisplayName => "Invoking a gRPC service with gRPC semantics and Protobuf with DaprClient"; - - // Note: the data types used in this sample are generated from data.proto in GrpcServiceSample - public override async Task RunAsync(CancellationToken cancellationToken) - { - using var client = new DaprClientBuilder().Build(); - - Console.WriteLine("Invoking grpc deposit"); - var deposit = new GrpcServiceSample.Generated.Transaction() { Id = "17", Amount = 99 }; - var account = await client.InvokeMethodGrpcAsync("grpcsample", "deposit", deposit, cancellationToken); - Console.WriteLine("Returned: id:{0} | Balance:{1}", account.Id, account.Balance); - Console.WriteLine("Completed grpc deposit"); - - Console.WriteLine("Invoking grpc withdraw"); - var withdraw = new GrpcServiceSample.Generated.Transaction() { Id = "17", Amount = 10, }; - await client.InvokeMethodGrpcAsync("grpcsample", "withdraw", withdraw, cancellationToken); - Console.WriteLine("Completed grpc withdraw"); - - Console.WriteLine("Invoking grpc balance"); - var request = new GetAccountRequest() { Id = "17", }; - account = await client.InvokeMethodGrpcAsync("grpcsample", "getaccount", request, cancellationToken); - Console.WriteLine($"Received grpc balance {account.Balance}"); - } -} \ No newline at end of file diff --git a/examples/Client/ServiceInvocation/InvokeServiceHttpClientExample.cs b/examples/Client/ServiceInvocation/InvokeServiceHttpClientExample.cs deleted file mode 100644 index 415e984e7..000000000 --- a/examples/Client/ServiceInvocation/InvokeServiceHttpClientExample.cs +++ /dev/null @@ -1,56 +0,0 @@ -// ------------------------------------------------------------------------ -// Copyright 2021 The Dapr Authors -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// ------------------------------------------------------------------------ - -using System; -using System.Net.Http.Json; -using System.Threading; -using System.Threading.Tasks; -using Dapr.Client; - -namespace Samples.Client; - -public class InvokeServiceHttpClientExample : Example -{ - public override string DisplayName => "Invoking an HTTP service with HttpClient"; - - public override async Task RunAsync(CancellationToken cancellationToken) - { - var client = DaprClient.CreateInvokeHttpClient(appId: "routing"); - - var deposit = new Transaction { Id = "17", Amount = 99m }; - var response = await client.PostAsJsonAsync("/deposit", deposit, cancellationToken); - var account = await response.Content.ReadFromJsonAsync(cancellationToken: cancellationToken); - Console.WriteLine("Returned: id:{0} | Balance:{1}", account?.Id, account?.Balance); - - var withdraw = new Transaction { Id = "17", Amount = 10m, }; - response = await client.PostAsJsonAsync("/withdraw", withdraw, cancellationToken); - response.EnsureSuccessStatusCode(); - - account = await client.GetFromJsonAsync("/17", cancellationToken); - Console.WriteLine($"Received balance {account?.Balance}"); - } - - internal class Transaction - { - public string? Id { get; set; } - - public decimal? Amount { get; set; } - } - - internal class Account - { - public string? Id { get; set; } - - public decimal? Balance { get; set; } - } -} \ No newline at end of file diff --git a/examples/Client/ServiceInvocation/InvokeServiceHttpExample.cs b/examples/Client/ServiceInvocation/InvokeServiceHttpExample.cs deleted file mode 100644 index 5595ae268..000000000 --- a/examples/Client/ServiceInvocation/InvokeServiceHttpExample.cs +++ /dev/null @@ -1,61 +0,0 @@ -// ------------------------------------------------------------------------ -// Copyright 2021 The Dapr Authors -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// ------------------------------------------------------------------------ - -using System; -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; -using Dapr.Client; - -namespace Samples.Client; - -public class InvokeServiceHttpExample : Example -{ - public override string DisplayName => "Invoking an HTTP service with DaprClient"; - - public override async Task RunAsync(CancellationToken cancellationToken) - { - using var client = new DaprClientBuilder().Build(); - - // Invokes a POST method named "deposit" that takes input of type "Transaction" as define in the RoutingSample. - Console.WriteLine("Invoking deposit"); - var data = new { id = "17", amount = 99m }; - var account = await client.InvokeMethodAsync("routing", "deposit", data, cancellationToken); - Console.WriteLine("Returned: id:{0} | Balance:{1}", account.Id, account.Balance); - - // Invokes a POST method named "Withdraw" that takes input of type "Transaction" as define in the RoutingSample. - Console.WriteLine("Invoking withdraw"); - data = new { id = "17", amount = 10m, }; - await client.InvokeMethodAsync("routing", "Withdraw", data, cancellationToken); - Console.WriteLine("Completed"); - - // Invokes a GET method named "hello" that takes input of type "MyData" and returns a string. - Console.WriteLine("Invoking balance"); - account = await client.InvokeMethodAsync(HttpMethod.Get, "routing", "17", cancellationToken); - Console.WriteLine($"Received balance {account.Balance}"); - } - - internal class Transaction - { - public string? Id { get; set; } - - public decimal? Amount { get; set; } - } - - internal class Account - { - public string? Id { get; set; } - - public decimal? Balance { get; set; } - } -} \ No newline at end of file diff --git a/examples/Client/ServiceInvocation/InvokeServiceHttpNonDaprEndpointExample.cs b/examples/Client/ServiceInvocation/InvokeServiceHttpNonDaprEndpointExample.cs deleted file mode 100644 index 26034e846..000000000 --- a/examples/Client/ServiceInvocation/InvokeServiceHttpNonDaprEndpointExample.cs +++ /dev/null @@ -1,61 +0,0 @@ -// ------------------------------------------------------------------------ -// Copyright 2021 The Dapr Authors -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// ------------------------------------------------------------------------ - -using System; -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; -using Dapr.Client; - -namespace Samples.Client; - -public class InvokeServiceHttpNonDaprEndpointExample : Example -{ - public override string DisplayName => "Invoke a non Dapr endpoint using DaprClient"; - - public override async Task RunAsync(CancellationToken cancellationToken) - { - using var client = new DaprClientBuilder().Build(); - - // Invoke a POST method named "deposit" that takes input of type "Transaction" as defined in the RoutingSample. - Console.WriteLine("Invoking deposit using non Dapr endpoint."); - var data = new { id = "17", amount = 99m }; - var account = await client.InvokeMethodAsync("http://localhost:5000", "deposit", data, cancellationToken); - Console.WriteLine("Returned: id:{0} | Balance:{1}", account.Id, account.Balance); - - // Invokes a POST method named "Withdraw" that takes input of type "Transaction" as defined in the RoutingSample. - Console.WriteLine("Invoking withdraw using non Dapr endpoint."); - data = new { id = "17", amount = 10m, }; - await client.InvokeMethodAsync("http://localhost:5000", "withdraw", data, cancellationToken); - Console.WriteLine("Completed"); - - // Invokes a GET method named "hello" that takes input of type "MyData" and returns a string. - Console.WriteLine("Invoking balance using non Dapr endpoint."); - account = await client.InvokeMethodAsync(HttpMethod.Get, "http://localhost:5000", "17", cancellationToken); - Console.WriteLine($"Received balance {account.Balance}"); - } - - internal class Transaction - { - public string? Id { get; set; } - - public decimal Amount { get; set; } - } - - internal class Account - { - public string? Id { get; set; } - - public decimal Balance { get; set; } - } -} diff --git a/examples/Client/ServiceInvocation/Program.cs b/examples/Client/ServiceInvocation/Program.cs deleted file mode 100644 index 6d371337d..000000000 --- a/examples/Client/ServiceInvocation/Program.cs +++ /dev/null @@ -1,48 +0,0 @@ -// ------------------------------------------------------------------------ -// Copyright 2021 The Dapr Authors -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// ------------------------------------------------------------------------ - -using System; -using System.Threading; -using System.Threading.Tasks; - -namespace Samples.Client; - -class Program -{ - private static readonly Example[] Examples = new Example[] - { - new InvokeServiceGrpcExample(), - new InvokeServiceHttpExample(), - new InvokeServiceHttpClientExample(), - }; - - static async Task Main(string[] args) - { - if (args.Length > 0 && int.TryParse(args[0], out var index) && index >= 0 && index < Examples.Length) - { - var cts = new CancellationTokenSource(); - Console.CancelKeyPress += (object? sender, ConsoleCancelEventArgs e) => cts.Cancel(); - - await Examples[index].RunAsync(cts.Token); - return 0; - } - - Console.WriteLine("Hello, please choose a sample to run:"); - for (var i = 0; i < Examples.Length; i++) - { - Console.WriteLine($"{i}: {Examples[i].DisplayName}"); - } - Console.WriteLine(); - return 1; - } -} \ No newline at end of file diff --git a/examples/Client/ServiceInvocation/README.md b/examples/Client/ServiceInvocation/README.md deleted file mode 100644 index 60d7ca13d..000000000 --- a/examples/Client/ServiceInvocation/README.md +++ /dev/null @@ -1,53 +0,0 @@ -# Dapr .NET SDK service invocation example - -## Prerequisites - -- [.NET 8+](https://dotnet.microsoft.com/download) installed -- [Dapr CLI](https://docs.dapr.io/getting-started/install-dapr-cli/) -- [Initialized Dapr environment](https://docs.dapr.io/getting-started/install-dapr-selfhost/) -- [Dapr .NET SDK](https://docs.dapr.io/developing-applications/sdks/dotnet/) - -## Running the example - -To run the sample locally run this command in the DaprClient directory: - -```sh -dapr run --app-id DaprClient -- dotnet run -``` - -Running the following command will output a list of the samples included: - -```sh -dapr run --app-id DaprClient -- dotnet run -``` - -Press Ctrl+C to exit, and then run the command again and provide a sample number to run the samples. - -For example run this command to run the 0th sample from the list produced earlier. - -```sh -dapr run --app-id DaprClient -- dotnet run 0 -``` - -## HTTP client - -Make sure to first run the [Routing Service](../../AspNetCore/RoutingSample) to have a service to invoke. - -See [InvokeServiceHttpClientExample.cs](./InvokeServiceHttpClientExample.cs) for an example of using `HttpClient` to invoke another service through Dapr. - -## Dapr HTTP client -Make sure to first run the [Routing Service](../../AspNetCore/RoutingSample) to have a service to invoke. - -See [InvokeServiceHttpExample.cs](./InvokeServiceHttpExample.cs) for an example using the `DaprClient` to invoke another service through Dapr. - -## Dapr gRPC client - -Make sure to first run the [GrpcService](../../AspNetCore/GrpcServiceSample) to have a service to invoke. - -See [InvokeServiceGrpcExample.cs](./InvokeServiceGrpcExample.cs) for an example using the `DaprClient` to invoke a service using gRPC through Dapr. - -## Dapr Non-Dapr endpoint - -Make sure to first run the [Routing Service](../../AspNetCore/RoutingSample) to have a service to invoke. - -See [InvokeServiceHttpNonDaprEndpointExample](./InvokeServiceHttpNonDaprEndpointExample.cs) for an example using the `DaprClient` to invoke a non-Dapr endpoint through Dapr. diff --git a/examples/Client/ServiceInvocation/ServiceInvocation.csproj b/examples/Client/ServiceInvocation/ServiceInvocation.csproj deleted file mode 100644 index 78d045a2b..000000000 --- a/examples/Client/ServiceInvocation/ServiceInvocation.csproj +++ /dev/null @@ -1,23 +0,0 @@ - - - - Exe - Samples.Client - enable - - - - - - - - - - - - - - - - - diff --git a/src/Dapr.Client/DaprClient.cs b/src/Dapr.Client/DaprClient.cs index 8929d2786..240f229f1 100644 --- a/src/Dapr.Client/DaprClient.cs +++ b/src/Dapr.Client/DaprClient.cs @@ -256,7 +256,6 @@ public abstract Task PublishByteEventAsync( /// A collection of metadata key-value pairs that will be provided to the binding. The valid metadata keys and values are determined by the type of binding used. /// A that can be used to cancel the operation. /// A that will complete when the operation has completed. - [Obsolete("Recommended guidance is to use a native HTTP or gRPC client for service invocation")] public abstract Task InvokeBindingAsync( string bindingName, string operation, @@ -275,7 +274,6 @@ public abstract Task InvokeBindingAsync( /// A collection of metadata key-value pairs that will be provided to the binding. The valid metadata keys and values are determined by the type of binding used. /// A that can be used to cancel the operation. /// A that will complete when the operation has completed. - [Obsolete("Recommended guidance is to use a native HTTP or gRPC client for service invocation")] public abstract Task InvokeBindingAsync( string bindingName, string operation, @@ -290,7 +288,6 @@ public abstract Task InvokeBindingAsync( /// The to send. /// A that can be used to cancel the operation. /// A that will complete when the operation has completed. - [Obsolete("Recommended guidance is to use a native HTTP or gRPC client for service invocation")] public abstract Task InvokeBindingAsync( BindingRequest request, CancellationToken cancellationToken = default); @@ -448,6 +445,7 @@ public HttpRequestMessage CreateInvokeMethodRequest(string appId, stri /// /// A that can be used to cancel the operation. /// A that will return the value when the operation has completed. + [Obsolete("Recommended guidance is to use a native HTTP or gRPC client for service invocation")] public abstract Task InvokeMethodWithResponseAsync(HttpRequestMessage request, CancellationToken cancellationToken = default); /// @@ -482,6 +480,7 @@ public HttpRequestMessage CreateInvokeMethodRequest(string appId, stri /// /// A that can be used to cancel the operation. /// A that will return when the operation has completed. + [Obsolete("Recommended guidance is to use a native HTTP or gRPC client for service invocation")] public abstract Task InvokeMethodAsync(HttpRequestMessage request, CancellationToken cancellationToken = default); /// @@ -496,6 +495,7 @@ public HttpRequestMessage CreateInvokeMethodRequest(string appId, stri /// /// A that can be used to cancel the operation. /// A that will return the value when the operation has completed. + [Obsolete("Recommended guidance is to use a native HTTP or gRPC client for service invocation")] public abstract Task InvokeMethodAsync(HttpRequestMessage request, CancellationToken cancellationToken = default); /// @@ -507,6 +507,7 @@ public HttpRequestMessage CreateInvokeMethodRequest(string appId, stri /// The name of the method to invoke. /// A that can be used to cancel the operation. /// A that will return when the operation has completed. + [Obsolete("Recommended guidance is to use a native HTTP or gRPC client for service invocation")] public Task InvokeMethodAsync( string appId, string methodName, @@ -526,6 +527,7 @@ public Task InvokeMethodAsync( /// The name of the method to invoke. /// A that can be used to cancel the operation. /// A that will return when the operation has completed. + [Obsolete("Recommended guidance is to use a native HTTP or gRPC client for service invocation")] public Task InvokeMethodAsync( HttpMethod httpMethod, string appId, @@ -548,6 +550,7 @@ public Task InvokeMethodAsync( /// The data that will be JSON serialized and provided as the request body. /// A that can be used to cancel the operation. /// A that will return when the operation has completed. + [Obsolete("Recommended guidance is to use a native HTTP or gRPC client for service invocation")] public Task InvokeMethodAsync( string appId, string methodName, @@ -571,6 +574,7 @@ public Task InvokeMethodAsync( /// The data that will be JSON serialized and provided as the request body. /// A that can be used to cancel the operation. /// A that will return when the operation has completed. + [Obsolete("Recommended guidance is to use a native HTTP or gRPC client for service invocation")] public Task InvokeMethodAsync( HttpMethod httpMethod, string appId, @@ -594,6 +598,7 @@ public Task InvokeMethodAsync( /// The name of the method to invoke. /// A that can be used to cancel the operation. /// A that will return the value when the operation has completed. + [Obsolete("Recommended guidance is to use a native HTTP or gRPC client for service invocation")] public Task InvokeMethodAsync( string appId, string methodName, @@ -616,6 +621,7 @@ public Task InvokeMethodAsync( /// The name of the method to invoke. /// A that can be used to cancel the operation. /// A that will return the value when the operation has completed. + [Obsolete("Recommended guidance is to use a native HTTP or gRPC client for service invocation")] public Task InvokeMethodAsync( HttpMethod httpMethod, string appId, @@ -640,6 +646,7 @@ public Task InvokeMethodAsync( /// The data that will be JSON serialized and provided as the request body. /// A that can be used to cancel the operation. /// A that will return the value when the operation has completed. + [Obsolete("Recommended guidance is to use a native HTTP or gRPC client for service invocation")] public Task InvokeMethodAsync( string appId, string methodName, @@ -665,6 +672,7 @@ public Task InvokeMethodAsync( /// The data that will be JSON serialized and provided as the request body. /// A that can be used to cancel the operation. /// A that will return the value when the operation has completed. + [Obsolete("Recommended guidance is to use a native HTTP or gRPC client for service invocation")] public Task InvokeMethodAsync( HttpMethod httpMethod, string appId, @@ -685,6 +693,7 @@ public Task InvokeMethodAsync( /// The name of the method to invoke. /// A that can be used to cancel the operation. /// A that will return when the operation has completed. + [Obsolete("Recommended guidance is to use a native HTTP or gRPC client for service invocation")] public abstract Task InvokeMethodGrpcAsync( string appId, string methodName, @@ -701,6 +710,7 @@ public abstract Task InvokeMethodGrpcAsync( /// The data that will be Protobuf serialized and provided as the request body. /// A that can be used to cancel the operation. /// A that will return when the operation has completed. + [Obsolete("Recommended guidance is to use a native HTTP or gRPC client for service invocation")] public abstract Task InvokeMethodGrpcAsync( string appId, string methodName, @@ -719,6 +729,7 @@ public abstract Task InvokeMethodGrpcAsync( /// The name of the method to invoke. /// A that can be used to cancel the operation. /// A that will return the value when the operation has completed. + [Obsolete("Recommended guidance is to use a native HTTP or gRPC client for service invocation")] public abstract Task InvokeMethodGrpcAsync( string appId, string methodName, @@ -738,6 +749,7 @@ public abstract Task InvokeMethodGrpcAsync( /// The data that will be Protobuf serialized and provided as the request body. /// A that can be used to cancel the operation. /// A that will return the value when the operation has completed. + [Obsolete("Recommended guidance is to use a native HTTP or gRPC client for service invocation")] public abstract Task InvokeMethodGrpcAsync( string appId, string methodName, diff --git a/src/Dapr.Client/DaprClientGrpc.cs b/src/Dapr.Client/DaprClientGrpc.cs index 0cc5f796b..95d1b3bdb 100644 --- a/src/Dapr.Client/DaprClientGrpc.cs +++ b/src/Dapr.Client/DaprClientGrpc.cs @@ -273,7 +273,6 @@ private async Task> MakeBulkPublishRequest( #region InvokeBinding Apis /// - [Obsolete("Recommended guidance is to use a native HTTP or gRPC client for service invocation")] public override async Task InvokeBindingAsync( string bindingName, string operation, @@ -289,7 +288,6 @@ public override async Task InvokeBindingAsync( } /// - [Obsolete("Recommended guidance is to use a native HTTP or gRPC client for service invocation")] public override async Task InvokeBindingAsync( string bindingName, string operation, @@ -315,7 +313,6 @@ public override async Task InvokeBindingAsync( } } - [Obsolete("Recommended guidance is to use a native HTTP or gRPC client for service invocation")] public override async Task InvokeBindingAsync(BindingRequest request, CancellationToken cancellationToken = default) { @@ -439,6 +436,7 @@ public override HttpRequestMessage CreateInvokeMethodRequest(HttpMetho return request; } + [Obsolete("Recommended guidance is to use a native HTTP or gRPC client for service invocation")] public override async Task InvokeMethodWithResponseAsync(HttpRequestMessage request, CancellationToken cancellationToken = default) { @@ -494,7 +492,8 @@ public override async Task InvokeMethodWithResponseAsync(Ht public override HttpClient CreateInvokableHttpClient(string? appId = null) => DaprClient.CreateInvokeHttpClient(appId, this.httpEndpoint?.AbsoluteUri, this.apiTokenHeader?.Value); #nullable disable - + + [Obsolete("Recommended guidance is to use a native HTTP or gRPC client for service invocation")] public async override Task InvokeMethodAsync(HttpRequestMessage request, CancellationToken cancellationToken = default) { @@ -519,7 +518,8 @@ public async override Task InvokeMethodAsync(HttpRequestMessage request, response: response); } } - + + [Obsolete("Recommended guidance is to use a native HTTP or gRPC client for service invocation")] public async override Task InvokeMethodAsync(HttpRequestMessage request, CancellationToken cancellationToken = default) { @@ -573,7 +573,8 @@ public async override Task InvokeMethodAsync(HttpRequestMe response: response); } } - + + [Obsolete("Recommended guidance is to use a native HTTP or gRPC client for service invocation")] public override async Task InvokeMethodGrpcAsync(string appId, string methodName, CancellationToken cancellationToken = default) { @@ -597,6 +598,7 @@ public override async Task InvokeMethodGrpcAsync(string appId, string methodName } } + [Obsolete("Recommended guidance is to use a native HTTP or gRPC client for service invocation")] public override async Task InvokeMethodGrpcAsync(string appId, string methodName, TRequest data, CancellationToken cancellationToken = default) { @@ -625,6 +627,7 @@ public override async Task InvokeMethodGrpcAsync(string appId, string } } + [Obsolete("Recommended guidance is to use a native HTTP or gRPC client for service invocation")] public override async Task InvokeMethodGrpcAsync(string appId, string methodName, CancellationToken cancellationToken = default) { @@ -649,6 +652,7 @@ public override async Task InvokeMethodGrpcAsync(string ap } } + [Obsolete("Recommended guidance is to use a native HTTP or gRPC client for service invocation")] public override async Task InvokeMethodGrpcAsync(string appId, string methodName, TRequest data, CancellationToken cancellationToken = default) { diff --git a/test/Dapr.Client.Test/DaprClientTest.InvokeMethodAsync.cs b/test/Dapr.Client.Test/DaprClientTest.InvokeMethodAsync.cs index 89f93aa5b..1c0e40288 100644 --- a/test/Dapr.Client.Test/DaprClientTest.InvokeMethodAsync.cs +++ b/test/Dapr.Client.Test/DaprClientTest.InvokeMethodAsync.cs @@ -44,6 +44,7 @@ public partial class DaprClientTest }; [Fact] + [Obsolete] public async Task InvokeMethodAsync_VoidVoidNoHttpMethod_Success() { await using var client = TestClient.CreateForDaprClient(c => @@ -65,6 +66,7 @@ public async Task InvokeMethodAsync_VoidVoidNoHttpMethod_Success() } [Fact] + [Obsolete] public async Task InvokeMethodAsync_VoidVoidWithHttpMethod_Success() { await using var client = TestClient.CreateForDaprClient(c => @@ -86,6 +88,7 @@ public async Task InvokeMethodAsync_VoidVoidWithHttpMethod_Success() } [Fact] + [Obsolete] public async Task InvokeMethodAsync_VoidResponseNoHttpMethod_Success() { await using var client = TestClient.CreateForDaprClient(c => @@ -113,6 +116,7 @@ public async Task InvokeMethodAsync_VoidResponseNoHttpMethod_Success() } [Fact] + [Obsolete] public async Task InvokeMethodAsync_VoidResponseWithHttpMethod_Success() { await using var client = TestClient.CreateForDaprClient(c => @@ -139,6 +143,7 @@ public async Task InvokeMethodAsync_VoidResponseWithHttpMethod_Success() } [Fact] + [Obsolete] public async Task InvokeMethodAsync_RequestVoidNoHttpMethod_Success() { await using var client = TestClient.CreateForDaprClient(c => @@ -168,6 +173,7 @@ public async Task InvokeMethodAsync_RequestVoidNoHttpMethod_Success() } [Fact] + [Obsolete] public async Task InvokeMethodAsync_RequestVoidWithHttpMethod_Success() { await using var client = TestClient.CreateForDaprClient(c => @@ -197,6 +203,7 @@ public async Task InvokeMethodAsync_RequestVoidWithHttpMethod_Success() } [Fact] + [Obsolete] public async Task InvokeMethodAsync_RequestResponseNoHttpMethod_Success() { await using var client = TestClient.CreateForDaprClient(c => @@ -227,6 +234,7 @@ public async Task InvokeMethodAsync_RequestResponseNoHttpMethod_Success() } [Fact] + [Obsolete] public async Task InvokeMethodAsync_RequestResponseWithHttpMethod_Success() { await using var client = TestClient.CreateForDaprClient(c => @@ -386,6 +394,7 @@ public async Task WaitForSidecarAsync_NotSuccessWhenSidecarNotHealthy() } [Fact] + [Obsolete] public async Task InvokeMethodAsync_WrapsHttpRequestException() { await using var client = TestClient.CreateForDaprClient(c => @@ -408,6 +417,7 @@ public async Task InvokeMethodAsync_WrapsHttpRequestException() } [Fact] + [Obsolete] public async Task InvokeMethodAsync_WrapsHttpRequestException_FromEnsureSuccessStatus() { await using var client = TestClient.CreateForDaprClient(c => @@ -430,6 +440,7 @@ public async Task InvokeMethodAsync_WrapsHttpRequestException_FromEnsureSuccessS } [Fact] + [Obsolete] public async Task InvokeMethodAsync_WithBody_WrapsHttpRequestException() { await using var client = TestClient.CreateForDaprClient(c => @@ -452,6 +463,7 @@ public async Task InvokeMethodAsync_WithBody_WrapsHttpRequestException() } [Fact] + [Obsolete] public async Task InvokeMethodAsync_WithBody_WrapsHttpRequestException_FromEnsureSuccessStatus() { await using var client = TestClient.CreateForDaprClient(c => @@ -476,6 +488,7 @@ public async Task InvokeMethodAsync_WithBody_WrapsHttpRequestException_FromEnsur } [Fact] + [Obsolete] public async Task InvokeMethodAsync_WrapsHttpRequestException_FromSerialization() { await using var client = TestClient.CreateForDaprClient(c => @@ -658,6 +671,7 @@ public async Task CreateInvokeMethodRequest_WithData_CreatesJsonContentWithQuery } [Fact] + [Obsolete] public async Task InvokeMethodWithoutResponse_WithExtraneousHeaders() { await using var client = TestClient.CreateForDaprClient(c => @@ -686,6 +700,7 @@ public async Task InvokeMethodWithoutResponse_WithExtraneousHeaders() } [Fact] + [Obsolete] public async Task InvokeMethodWithResponseAsync_ReturnsMessageWithoutCheckingStatus() { await using var client = TestClient.CreateForDaprClient(c => @@ -704,6 +719,7 @@ public async Task InvokeMethodWithResponseAsync_ReturnsMessageWithoutCheckingSta } [Fact] + [Obsolete] public async Task InvokeMethodWithResponseAsync_WrapsHttpRequestException() { await using var client = TestClient.CreateForDaprClient(c => @@ -726,6 +742,7 @@ public async Task InvokeMethodWithResponseAsync_WrapsHttpRequestException() } [Fact] + [Obsolete] public async Task InvokeMethodWithResponseAsync_PreventsNonDaprRequest() { await using var client = TestClient.CreateForDaprClient(c => @@ -746,4 +763,4 @@ private class Widget { public string Color { get; set; } } -} \ No newline at end of file +} diff --git a/test/Dapr.Client.Test/DaprClientTest.InvokeMethodGrpcAsync.cs b/test/Dapr.Client.Test/DaprClientTest.InvokeMethodGrpcAsync.cs index dba99a720..2a12f0bb6 100644 --- a/test/Dapr.Client.Test/DaprClientTest.InvokeMethodGrpcAsync.cs +++ b/test/Dapr.Client.Test/DaprClientTest.InvokeMethodGrpcAsync.cs @@ -31,6 +31,7 @@ namespace Dapr.Client.Test; public partial class DaprClientTest { [Fact] + [Obsolete] public async Task InvokeMethodGrpcAsync_WithCancelledToken() { await using var client = TestClient.CreateForDaprClient(c => @@ -48,6 +49,7 @@ await Assert.ThrowsAsync(async () => } [Fact] + [Obsolete] public async Task InvokeMethodGrpcAsync_CanInvokeMethodWithReturnTypeAndData() { await using var client = TestClient.CreateForDaprClient(c => @@ -79,6 +81,7 @@ public async Task InvokeMethodGrpcAsync_CanInvokeMethodWithReturnTypeAndData() } [Fact] + [Obsolete] public async Task InvokeMethodGrpcAsync_CanInvokeMethodWithReturnTypeAndData_ThrowsExceptionForNonSuccess() { var client = new MockClient(); @@ -112,6 +115,7 @@ await client.Call() } [Fact] + [Obsolete] public async Task InvokeMethodGrpcAsync_CanInvokeMethodWithReturnTypeNoData() { await using var client = TestClient.CreateForDaprClient(c => @@ -143,6 +147,7 @@ public async Task InvokeMethodGrpcAsync_CanInvokeMethodWithReturnTypeNoData() } [Fact] + [Obsolete] public async Task InvokeMethodGrpcAsync_CanInvokeMethodWithReturnTypeNoData_ThrowsExceptionNonSuccess() { var client = new MockClient(); @@ -176,6 +181,7 @@ await client.Call() } [Fact] + [Obsolete] public async Task InvokeMethodGrpcAsync_CanInvokeMethodWithNoReturnTypeAndData() { var request = new Request() { RequestParameter = "Hello " }; @@ -199,6 +205,7 @@ public async Task InvokeMethodGrpcAsync_CanInvokeMethodWithNoReturnTypeAndData() } [Fact] + [Obsolete] public async Task InvokeMethodGrpcAsync_CanInvokeMethodWithNoReturnTypeAndData_ThrowsErrorNonSuccess() { var client = new MockClient(); @@ -233,6 +240,7 @@ await client.Call() } [Fact] + [Obsolete] public async Task InvokeMethodGrpcAsync_WithNoReturnTypeAndData() { await using var client = TestClient.CreateForDaprClient(c => @@ -259,6 +267,7 @@ public async Task InvokeMethodGrpcAsync_WithNoReturnTypeAndData() } [Fact] + [Obsolete] public async Task InvokeMethodGrpcAsync_WithReturnTypeAndData() { await using var client = TestClient.CreateForDaprClient(c => @@ -295,6 +304,7 @@ public async Task InvokeMethodGrpcAsync_WithReturnTypeAndData() } [Fact] + [Obsolete] public async Task InvokeMethodGrpcAsync_AppCallback_SayHello() { // Configure Client @@ -312,6 +322,7 @@ public async Task InvokeMethodGrpcAsync_AppCallback_SayHello() } [Fact] + [Obsolete] public async Task InvokeMethodGrpcAsync_AppCallback_RepeatedField() { // Configure Client @@ -335,6 +346,7 @@ public async Task InvokeMethodGrpcAsync_AppCallback_RepeatedField() } [Fact] + [Obsolete] public async Task InvokeMethodGrpcAsync_AppCallback_UnexpectedMethod() { // Configure Client @@ -488,4 +500,4 @@ private Task TestRun(InvokeRequest request) }); } } -} \ No newline at end of file +} diff --git a/test/Dapr.E2E.Test/ServiceInvocation/E2ETests.ServiceInvocationTests.cs b/test/Dapr.E2E.Test/ServiceInvocation/E2ETests.ServiceInvocationTests.cs index af94981cb..9dfbc464b 100644 --- a/test/Dapr.E2E.Test/ServiceInvocation/E2ETests.ServiceInvocationTests.cs +++ b/test/Dapr.E2E.Test/ServiceInvocation/E2ETests.ServiceInvocationTests.cs @@ -60,24 +60,25 @@ public async Task TestServiceInvocationRequiresApiToken() Assert.Equal(150, account.Balance); } - [Fact] - public async Task TestHttpServiceInvocationWithTimeout() - { - using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(20)); - using var client = new DaprClientBuilder() - .UseHttpEndpoint(this.HttpEndpoint) - .UseTimeout(TimeSpan.FromSeconds(1)) - .Build(); - - await Assert.ThrowsAsync(async () => - { - await client.InvokeMethodAsync( - appId: this.AppId, - methodName: "DelayedResponse", - httpMethod: new HttpMethod("GET"), - cancellationToken: cts.Token); - }); - } + // [Fact] + // [Obsolete] + // public async Task TestHttpServiceInvocationWithTimeout() + // { + // using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(20)); + // using var client = new DaprClientBuilder() + // .UseHttpEndpoint(this.HttpEndpoint) + // .UseTimeout(TimeSpan.FromSeconds(1)) + // .Build(); + // + // await Assert.ThrowsAsync(async () => + // { + // await client.InvokeMethodAsync( + // appId: this.AppId, + // methodName: "DelayedResponse", + // httpMethod: new HttpMethod("GET"), + // cancellationToken: cts.Token); + // }); + // } } internal class Transaction @@ -90,4 +91,4 @@ internal class Account { public string Id { get; set; } public decimal Balance { get; set; } -} \ No newline at end of file +}