GithubHelp home page GithubHelp logo

ejueldotnet / microsoft.xrm.sdk.async Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kind-serge/microsoft.xrm.sdk.async

0.0 0.0 0.0 49 KB

Adds IAsyncOrganizationService and IAsyncDiscoveryService with async versions of interface methods to the CRM Dynamics SDK.

License: MIT License

C# 100.00%

microsoft.xrm.sdk.async's Introduction

Summary

Adds IAsyncOrganizationService and IAsyncDiscoveryService with async versions of interface methods to the CRM Dynamics SDK - the Microsoft.CrmSdk.CoreAssemblies.Async.nuspec NuGet package.

Why

When you call IOrganizationService.Execute(request) for instance, it blocks the current thread until the reply is received from the Dynamics CRM server. In case when multiple such operations are running in parallel the app will use too many worker threads (because they are blocked) and will start suffer from performance degradation due to thread exhaustion. To avoid this issue, it's better not to block threads and process server responses as soon as they are available. This extension library allows you to do this using Task Parrallel Library (TPL) and asynchronous calls to Dynamics CRM server, e.g. await IAsyncOrganizationService.ExecuteAsync(request, cancellationToken).

How to use

You just need to create the asyncronous version of the client which exposes the asynchronous version of the interface.

Organization Service client creation options:

using Microsoft.Xrm.Sdk.Async;
using Microsoft.Xrm.Sdk.Client.Async;

// Create Async Proxy directly
// (implements both IOrganizationService and IAsyncOrganizationService)
var asyncService =
    new AsyncOrganizationServiceProxy(
        serviceUri,
        realmUri,
        clientCredentials,
        deviceCredentials);

// Create Async Proxy indirectly (with the extension method)
var asyncService =
    new OrganizationServiceProxy(
        serviceUri,
        realmUri,
        clientCredentials,
        deviceCredentials).ToAsyncService();

using Microsoft.Xrm.Sdk.WebServiceClient.Async;

// Create Async Web Client directly
// (implements both IOrganizationService and IAsyncOrganizationService)
var asyncClient =
    new OrganizationWebProxyAsyncClient(serviceUri, timeout, useStrongTypes)
        { HeaderToken = headerToken, SdkClientVersion = sdkClientVersion };

// Create Async Web Client indirectly (with the extension method)
var asyncClient =
    (new OrganizationWebProxyClient(serviceUri, timeout, useStrongTypes)
        { HeaderToken = headerToken, SdkClientVersion = sdkClientVersion }
    ).ToAsyncService();

Calling Organization Service asynchronously:

async Task DoFooAsync(
              IAsyncOrganizationService service,
              CancellationToken ct)
{
    OrganizationRequest request = ...;
    var response = await service.ExecuteAsync(request, ct);
    ...
}

Discovery Service client creation options:

using Microsoft.Xrm.Sdk.Discovery.Async;
using Microsoft.Xrm.Sdk.Client.Async;

// Create Async Proxy directly
// (implements both IDiscoveryService and IAsyncDiscoveryService)
var asyncService =
    new AsyncDiscoveryServiceProxy(
        serviceUri,
        realmUri,
        clientCredentials,
        deviceCredentials);

// Create Async Proxy indirectly (with the extension method)
var asyncService =
    new DiscoveryServiceProxy(
        serviceUri,
        realmUri,
        clientCredentials,
        deviceCredentials).ToAsyncService();

using Microsoft.Xrm.Sdk.WebServiceClient.Async;

// Create Async Web Client directly
// (implements both IDiscoveryService and IAsyncDiscoveryService)
var asyncClient =
    new DiscoveryWebProxyAsyncClient(serviceUri, timeout, useStrongTypes)
        { HeaderToken = headerToken, SdkClientVersion = sdkClientVersion };

// Create Async Web Client indirectly (with the extension method)
var asyncClient =
    (new DiscoveryWebProxyClient(serviceUri, timeout, useStrongTypes)
        { HeaderToken = headerToken, SdkClientVersion = sdkClientVersion }
    ).ToAsyncService();

Calling Discovery Service asynchronously:

async Task<OrganizationDetailCollection> FindOrganizationServices(
              IAsyncDiscoveryService service,
              CancellationToken ct)
{
    var request = new RetrieveOrganizationsRequest();
    var response = await service.ExecuteAsync(request, ct);
    return ((RetrieveOrganizationsResponse)response).Details;
}

References

GitHub: https://github.com/tyrotoxin/Microsoft.Xrm.Sdk.Async

NuGet.org: https://www.nuget.org/packages/Microsoft.CrmSdk.CoreAssemblies.Async

License: https://opensource.org/licenses/MIT

microsoft.xrm.sdk.async's People

Contributors

saebamini avatar tyrotoxin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.