WCF CRUDS and .NET Forms

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

We have already learnt about CRUDS architecture in Introduction to CRUDS tutorial. CRUDS enable IService, IServiceAsync, IWCFService and IWCFServiceAsync communication channels and implement ICRUD, ICRUDL and ICRUDM interfaces.

Keywords: windntrees, windows, desktop, .net forms, CRUD, CRUD2CRUD, CRUDS
  • Benefits

    CRUDS architecture implementation brings following benefits:

    1. Generalized Communication CRUD2CRUD (CRUDS)
    2. One interface, no need for multiple service contract interfaces.
    3. CRUD Repositories for data persistence.
    4. Extend CRUD repositories with customized functions and integrate in CRUD controllers (CRUD Services) with one IService (or IWCFService).
    5. Invoke remote methods from clients (ServiceClients CRUDController) by specifying server side method "target" names.
    6. Support for MVVM desktop and Xamarin mobile application development. WCF CRUDS application server.
    7. Cross-process and cross-platform clients.
    8. Data communication using synchronous (IService, IWCFService) and asynchronous (IServiceAsync, IWCFServiceAsync) interface channels.
    9. Support for event driven response handling and GUI integration.
    10. Support for paging or listing based records.
    11. Reduced effort and cost of developing multiple service contracts. Think of CRUDL communication with CRUD repository for persistence.
    12. Reduced complexity and elaborated architecture (CRUDLM data communication).
    13. Distribute applications with simple interfacing programming model.

    Strategy

    To achieve tutorial objectives we'll develop:

    1. Application Server Project.
    2. Forms Application Client (.NET Framework).
    3. Shared Library Project (.NET Standard) and,
    4. Setup Database (Script Included).

    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 respositories for .NET Framework and .NET Core Framework.
    6. Create new ApplicationServer class and inherit from WindnTrees.CRUDS.Server class.
    7. Host service repositories using IWCFService channel interface in ApplicationServer.

    Windows Forms Application (.NET Framework)

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

    1. Setup Windows Forms .NET Framework application project.
    2. Install WindnTrees.ICRUDS nuget package.
    3. Add Entity Framework shared library project reference.
    4. Instantiate service clients using interface channels (IService, IServiceAsync, IWCFService, IWCFServiceAsync) with bindings and endpoints.
    5. Subscribe service client events and update GUI accordingly.
    6. Wire 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 Forms Application with Server. This project uses 9092 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 share following data contract model:

    1. Product
  • ServiceClient and Events (.NET Framework)

    WindnTrees CRUDS support 3 types of data communication and handling.

    1. Synchronous (IService, IWCFService)
    2. Asynchronous with Local Delegates (IService, IWCFService)
    3. Asynchronous with Service Side Implementation (IServiceAsync, IWCFServiceAsync)

    In this tutorial we'll implement asynchronous communication with local delegates to support responsive user interface. Subscribe following events for handling single object or list of objects:

    1. OnObject
    2. OnContentObject
    3. OnContentObjectList

    Event OnObject support primitive data type object response and is invoked by following service client method.

    1. MethodSearchObjectAsync

    Event OnContentObject support generic type (WCFServiceClient) data response and is invoked by following service client methods.

    1. CreateAsync
    2. UpdateAsync
    3. DeleteAsync

    Event OnContentObjectList support generic type (WCFServiceClient) listing (List) data response and is invoked by following service client methods.

    1. ListAsync

    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

    Windows Forms (.NET Framework) Nuget Packages

    Windows Forms depend upon following nuget packages.

    1. WindnTrees.ICRUDS

    Summary

    WindnTrees.CRUDS provide efficient means of developing cross-process, cross-platform distributed applications using CRUD2CRUD communication architecture. Download projects code here. Nuget packages are not included in download.