Web API Parallel Operations with TPL Dataflow components Sample (C#)
This .NET 6.0 sample demonstrates how to perform parallel data operations using the Dataverse Web API with Task Parallel Library (TPL) Dataflow components. More information: Dataflow (Task Parallel Library).
This sample uses the common helper code in the WebAPIService class library (C#).
The following is required to build and run this sample:
- Microsoft Visual Studio 2022.
- Access to Dataverse with privileges to perform data operations.
How to run this sample
Clone or download the PowerApps-Samples repository.
Locate the /dataverse/webapi/C#-NETx/TPLDataFlowParallelOperations/ folder.
TPLDataFlowParallelOperations.slnfile using Visual Studio 2022
appsettings.jsonfile to set the following property values:
The Url for your environment. Replace the placeholder
https://yourorg.api.crm.dynamics.comvalue with the value for your environment. See View developer resources to find this.
Replace the placeholder
firstname.lastname@example.org with the UPN value you use to access the environment.
Replace the placeholder
yourPasswordvalue with the password you use.
Press F5 to run the sample.
The code for this sample is here: PowerApps-Samples/dataverse/webapi/C#-NETx/TPLDataFlowParallelOperations/Program.cs
This sample includes settings you can apply to optimize your connection.
This sample first sends a request simply to access the value of the
x-ms-dop-hint response header to determine the recommended degrees of parallelism for this environment. When the maximum degree of parallelism is set equal to the value of the
x-ms-dop-hint response header you should achieve a steady state where throughput is optimized with a minimum of
429 TooManyRequests service protection limit errors returned.
To encounter service protection limits with this sample you should raise the
numberOfRecords variable to over 10,000 or whatever is needed for the sample to run for more than 5 minutes. You should also change the code to set the
maxDegreeOfParallelism to be significantly greater than
x-ms-dop-hint response header value. Then, using Fiddler you should be able to observe how WebAPIService retries the requests that return this error.
This sample simply creates a configurable number of account records, which it will in turn delete. This sample uses dataflow components to process the records and transform the results of the create operation into the next phase that deletes these records. Because of the nature of this data flow, delete operations for previously created records will start before all the records to create are finished.
You may want to compare this sample to the Web API CDSWebApiService Parallel Operations Sample (C#).
By default this sample will delete all the records created in it. If you want to view created records after the sample is completed, change the
deleteCreatedRecords variable to
false and you will be prompted to decide if you want to delete the records.
Use the Dataverse Web API
WebAPIService class library (C#)
Create a table row using the Web API
Update and delete table rows using the Web API
Service protection API limits
Web API Samples
Web API Basic Operations Sample (C#)
Web API Query Data sample (C#)
Web API Conditional Operations sample (C#)
Web API Functions and Actions Sample (C#)
Web API Metadata Operations Sample (C#)
Web API WebApiService Parallel Operations Sample (C#)
다음에 대한 사용자 의견 제출 및 보기