WPF and WCF CRUD2CRUD Communication Architecture

WPF and WCF CRUD2CRUD Communication Architecture


In this tutorial we'll learn developing distributed client server desktop applications using WPF windows 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: WCF, WPF, CRUD, WindnTrees, CRUD2CRUD, CRUDS
  • 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.


    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.


    AdapterServiceRepository have following benefits:

    1. Generalized Communication CRUD2CRUD (CRUDS)
    2. Simple methodology of converting between EntityFramework and DataContract 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 additional required functions and integrate in CRUD controllers (CRUD Services) with IService (or IWCFService) interface.
    6. Communicate data using synchronous (IService, IWCFService) and asynchronous (IServiceAsync, IWCFServiceAsync) interface channels.


    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. WPF Application Projects (.NET Framework and .NET 5.0).
    4. Shared Library Project (.NET Standard 2.0).

    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 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.

  • WPF Application (.NET 5.0)

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

    1. Setup WPF .NET 5.0 application project.
    2. Install WindnTrees.ICRUDS.Standard nuget package.
    3. Add 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)

    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
    3. WindnTrees.ICRUDS.Standard
    4. WindnTrees.CRUDS.Repository
    5. WindnTrees.CRUDS.Repository.Standard

    WPF (.NET 5.0) Nuget Packages

    WPF application depend upon following CRUD2CRUD nuget packages.

    1. WindnTrees.ICRUDS.Standard


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