AdapterService and .NET Core 3.1 Asynchronous Forms

Abstract

In this tutorial we'll learn developing distributed client server desktop application using windows forms and CRUD2CRUD (CRUDS) communication architecture with AdapterServiceRepository.

AdapterServiceRepository enables WCF complex types (or KnownType) class objects communication using IService, IServiceAsync, IWCFService and IWCFServiceAsync communication channels.

Keywords: WindnTrees, CRUD, CRUD2CRUD, CRUDS, .NET Core 3.1, .NET 5.0, AdapterServiceRepository
  • Communication and Persistence Requirements of Data Models in CRUD2CRUD

    Besides simple types communication, applications often exchange complex types and that might require different meta data objects than are required for data storage repositories.

    Remember,

    1. WCF framework allows both simple and complex types communication, CRUDS implement simple types communication via ServiceRepository, and
    2. AdapterServiceRepository is used to communicate complex types decorated with KnowType attributes across its interface channels.
    3. EntityFramework uses DbSet repositories to save complex types and that have no compliance with WCF requirements of data contract or KnownType attribute.

    AdapterServices (or AdapterServiceRepositories) enable such conversion between EntityFramework and WCF compliant data contracts while providing similar interfaces as of ServiceRepository.

    Benefits

    AdapterServiceRepository have following benefits:

    1. Generalized Communication CRUD2CRUD (CRUDS)
    2. Simple methodology of converting between EntityFramework and DataContract objects with KnownType attributes.
    3. One interface, no need for multiple service contract interfaces.
    4. EntityFramework CRUD Repositories for data persistence.
    5. Extend CRUD repositories with customized functions and integrate in CRUD controllers (CRUD Services) with only IService (or IWCFService) interface.
    6. Communicate data using synchronous (IService, IWCFService) and asynchronous (IServiceAsync, IWCFServiceAsync) interface channels.

    Strategy

    To achieve tutorial objectives we'll develop or setup following:

    1. Setup Database (Script Included, Updated with ProductFeature table).
    2. Application Server Project (.NET Framework).
    3. Forms Application Client (.NET Core 3.1).
    4. Shared Library Project (.NET Standard).

    Database Setup

    Install or run "tutorials" database script in MS-SQL Server 2017 or latest edition that includes related tables and data.

    Application Server Project

    Application server enables distributed clients with operational logic with same database, repositories and standard data models.

    1. Setup new windows .NET Framework console application project.
    2. Install WindnTrees.CRUDS and dependent latest nuget packages.
    3. Create Entity Framework Entity Model (.edmx) that includes database application context and POCO models.
    4. Configure Entity Model with Shared Library project for distributing standard data models (POCO classes) across different projects.
    5. Write IWCFService service repositories for .NET and .NET Core Framework.
    6. Create new ApplicationServer class and inherit from WindnTrees.CRUDS.Server class.
    7. Host simple and adapter service repositories using IWCFService channel interface in ApplicationServer.

  • Windows Forms Application (.NET Core)

    Windows Forms enable desktop user operational logic and are setup as mentioned below:

    1. Setup Windows Forms .NET Core application project.
    2. Install WindnTrees.ICRUDS.Standard nuget package.
    3. Add Entity Framework shared library project reference.
    4. Instantiate service clients using interface channels (IServiceAsync or IWCFServiceAsync) with bindings and endpoints for simple and adapter services.
    5. Integrate application logic and continue developing distributed clients using CRUDS architecture with one interface and many repositories.

    Make sure IP and port configurations are same when using .NET Core Forms Application with Server. This project uses 9096 port for net.tcp protocol implementation.

    Shared Library

    Shares common data model or data contract definitions required to communicate data across or within different components of a sub-system. In this application we'll use following data contract model:

    1. Product (EntityFramework)
    2. ProductFeature (EntityFramework)
    3. Product (Adapter Communication Object)
    4. ProductFeature (Adapter Communication Object)

    ServiceClient and Events

    WindnTrees CRUDS support 3 types of data communication and handling.

    1. Synchronous (IService, IWCFService)
    2. Asynchronous with Local Delegates (Not supported in .NET Core)
    3. Asynchronous with Service Side Implementation (IServiceAsync, IWCFServiceAsync)

    In this tutorial we'll implement CRUDS asynchronous communication interface channel IWCFServiceAsync.

    Invoke following CRUDS service client method to get primitive data type object response using callback function.

    1. BeginMethodSearchObject

    Receive response in MethodSearchObjectCallback function and update total number of records and calculate number of lists.

    Invoke following CRUDS service client methods to get generic type (WCFServiceClient) data response in callback functions.

    1. BeginCreate
    2. BeginUpdate
    3. BeginDelete

    Invoke following CRUDS service client method to get generic type (WCFServiceClient) listing (List) data response in callback function.

    1. BeginList

    All asynchronous methods that are invoked with Begin can also be completed with related End functions without callbacks.

    Visit windntrees to learn about ServiceClient and WCFServiceClient APIs.

  • Application Server Nuget Packages

    WCF CRUDS Server (CRUD2CRUD) depend upon following nuget packages.

    1. WindnTrees.CRUDS
    2. WindnTrees.ICRUDS.Standard
    3. WindnTrees.CRUDS.Repository

    Repository for .NET standard interfacing channel is part of WindnTrees.CRUDS nuget package.

    Windows Forms (.NET Core) Nuget Packages

    Windows Forms depend upon following CRUD2CRUD nuget packages.

    1. WindnTrees.ICRUDS.Standard

    Summary

    Adapter service repositories provide efficient means of exchanging complex types with known type attributes. Download project code here.

    .NET 5.0 WPF application example source code can be downloaded from here.