Click here to Skip to main content
Licence CPOL
First Posted 28 Jun 2010
Views 110,539
Bookmarked 257 times

WCF by Example - Introduction

Patterns and best practices for the desing and development of rich client enterprise applications using WPF, WCF and NHibernate

1

2

3
10 votes, 19.6%
4
41 votes, 80.4%
5
4.85/5 - 51 votes
μ 4.84, σa 0.94 [?]
Next
Chapter I

Latest modifications 

The last article added to the series is WCF by Example - Chapter XIV - Validation & Exception Management, this article was added early Jan 2011 and discusses how to implement the IDataErrorInfo interface in combination with Validation attributes. This approach provides a comprehensive validation mechanism that works both in the client and server side. The article also discusses exception and warning management.

Recently, a re-factor of the client services components have taken place reducing the number of required artifacts in the client side when a new contract is created or methods are added or amended. The code is already on Codeplex on the trunk branch. Existing articles will need revision as result of these changes, code at the branches will also require changes.

In Dec 2010, the server side of the application was deployed to Azure, a ready-to-run client is available on codeplex. The WPF client can invoke methods to a WebRole deployed in Azure. This source code can be found at CodePlex at eDirectory.WPFClient.Azure.zip

You may want to follow series/code updates at: @enriquealbert/wcfbyexample

Introduction

This article is the first of a series that discusses how to design and develop a WPF client using WCF for communication and NHibernate for persistence purposes.

Designing enterprise applications requires a comprehensive set of skills. In small and medium projects allocation of time and resources could be not feasible to the extent that is in larger projects, it is at this time where a source for best practices and patterns can become very beneficial. There are plenty articles, books and other materials covering specific aspects but it is almost impossible to find a single place where all the technologies and patterns are used in conjunction providing a comprehensive discussion of the why and how.

The intention of these articles is to provide an example of how a full enterprise application is developed from the early stages to a full functional stage. The articles build on top of each other where new aspects are covered or/and existing functionality is enhanced as a result of aligning the architect to the business non-functional requirements.

It is assumed in the series that Agile practices are followed so the solution's architect focuses in providing flexible mechanisms for RAD, DDD and TDD methodologies. One key aspect of the architect is the requirement to be able to deploy a full-functional client for business exploration purposes that requires a minimum infrastructure footprint; avoiding databases, deployment to IIS and so on. 

Background 

The architect requirements are as follow: 

  • Rich client using WPF  
  • Client connects to server using WCF services  
  • NHibernate is used for persistence purposes  
  • Client application can be run against in-memory repositories (Exploration Client)
  • Deployment of the exploration client must be kept simple  
  • The application must be easily testable, tests can be run against in-memory or NHibernate repositories  

Other assumptions: 

  • We have full control over the client and server components
  • We are creating the database from scratch, we are not using some legacy database
  • We are deploying the server components using IIS7 and WAS; we will use TCP/IP
  • We have full design control over the PK in the database tables, we will using unique long fields for all our entities in this project

The eDirectory solution

We are going to start using a very simple business scenario in our series, the focus on the series is the architecture not the business domain. We may extend our domain in the future if we find that we want to explore some more complex architect concepts. 

The business domain is based in a simple list of contacts, it is currently so simple that one single entity is only required: Customer. The solution name is eDirectory. 

The source code can be found at codeplex: WCF by Example  

The latest version can be found at the trunk branch, each chapter is located at its own tag branch. You may want to use the browse function within Codeplex to navigate among the branches. 

Architect Overview 

The eDirectory application defines three well differentiated application components: the database, server and client. 

architecture_highlevel.gif

Within the client and server the application is structured into layers, in most cases the layers are stacked one beside each other, continuous layers are provided with decoupled mechanisms so different implementations can be used. Some services are available across multiple layers.

As we earlier mentioned, we have full control of the clients and server. So we will not relay on late service discovery, instead the service contracts are available at both sides of the application. This is also true for the DTOs and some common business validation. As a result, a Common assembly is defined that contains components shared by the server and client applications.  

common_components.gif

In the server side we find the core components, the business domain declares the business entities and their behavior (action methods). Then services are declared that exposes our domain action methods. The services for persistence and serialisation constraints only expose DTOs between the client and server. As a result, the transformation of entities to DTOs needs to be addressed in a comprehensive manner.  

In order to decouple our business domain from the database, the repository components are responsible for the persistence of our entities. We will define a generic interface between these two layers. Two concrete implementations of the repositories are available: in-memory and NHibernate. 

The transaction manager is our "unit of work" implementation. It is responsible for our business transactions and the handling of business messages (warnings and exceptions).

server_components.gif

Finally, but not the least, we have the client components. The client is a WPF application designed using the MVVM pattern. This pattern provides a neat view XAML component with none or very little code behind, the binding capabilities of XAML in conjunction with the ViewModel class leverages how the client renders the DTOs provided by the services layers.

The client decouples the service layers into two main components. The adapter is responsible for the managing of business messages retrieved during the execution of services. The WCF Proxy layer is responsible for the management of WCF services, the design is neat and is a nice way of decoupling the client from the WCF service.

client_components.gif

Available articles in Codeproject

Date Article
28-June-2010 WCF by Example - Chapter I - Baseline
05-July-2010 WCF by Example - Chapter II - Repository Locator
10-July-2010 WCF by Example - Chapter III - Response
16-July-2010 WCF by Example - Chapter IV - Transaction Manager
23-July-2010 WCF by Example - Chapter V - Contexts
31-August-2010 WCF by Example - Chapter VI - Baseline MVVM
04-September-2010 WCF by Example - Chapter VII - Contract Locator
15-September-2010 WCF by Example - Chapter VIII - Relay Command
19-September-2010 WCF by Example - Chapter IX - Notify Property Change
16-October-2010 WCF by Example - Chapter X - DI with Spring.Net
04-November-2010 WCF by Example - Chapter XI - NHibernate Implementation
24-November-2010 WCF by Example - Chapter XII - WCF Implementation
19-December-2010 WCF by Example - Chapter XIII - Business Domain Extension
07-January-2011 WCF by Example - Chapter XIV - Validation & Exception Management

Available chapters (source code) in Codeplex

Date Chapter
14-June-2010 Chapter I - Baseline
14-June-2010 Chapter II - Response
14-June-2010 Chapter III - Response
14-June-2010 Chapter IV - Transaction Manager
14-June-2010 Chapter V - Service Locator
14-June-2010 Chapter VI - Baseline MVVM
14-June-2010 Chapter VII - Contract Locator
29-July-2010 Chapter VIII - RelayCommand
29-July-2010 Chapter IX - Notify Property Changed Pattern
29-July-2010 Chapter X - Dependency Injection
12-September-2010 Chapter XI - NHibernate Implementation
07-October-2010 Chapter XII - WCF Implementation
14-November-2010 Chapter XIII - Business Domain Extension
12-December-2010 Azure Solution - In-memory mode WebRole
07-January-2011 Chapter XIV - Validation & Exception Management
07-October-2011 Client re-factor: ServiceAdapter & CommandDispatcher pattern

Future chapters

Chapter State
Azure Deployment - In-memory WebRole Source code is available
Azure Deployment - NHibernate WebRole Pending
Existing chapters revision as a result of client re-factor Pending

History

14 June 2010 - Introduction article was created.
28 June 2010 - Chapter I is done and series are published.
05 July 2010 - Chapter II was added to the series
10 July 2010 - Chapter III was added to the series
16 July 2010 - Chapter IV was added to the series
23 July 2010 - Chapter V was added to the series
31 August 2010 - Chapter VI was added to the series
04 September 2010 - Chapter VII was added to the series
15 September 2010 - Chapter VIII was added to the series
19 September 2010 - Chapter IX was added to the series
07 October 2010 - Source code for Chapter XII is available at CodePlex
16 October 2010 - Chapter X was added to the series
04 November 2010 - Chapter XI was added to the series
24 November 2010 - Chapter XII was added to the series
12 December 2010 - In-memory WebRole is deployed to MS Azure
19 December 2010 - Chapter XIII was added to the series
07 January 2011 - Chapter XIV was added to the series
09 February 2011 - Chapter XIV section 2 was added to the series
07 October 2011 - Client re-factor was made available on Codeplex

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Enrique Albert



Ireland Ireland

Member

Follow on Twitter Follow on Twitter


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionNHibernate concurrency PinmemberMember 835644223:00 2 Feb '12  
AnswerRe: NHibernate concurrency PinmemberEnrique Albert6:45 3 Feb '12  
GeneralMy vote of 4 Pinmemberivix4u20:30 2 Feb '12  
GeneralWCF Introduction PingroupAnkitaaguggi21:36 11 Nov '11  
QuestionWhat about sequrity? PinmemberWebGrave5:19 9 Nov '11  
AnswerRe: What about sequrity? PinmemberEnrique Albert3:51 10 Nov '11  
GeneralMy vote of 5 PinmemberDasiths16:16 24 Oct '11  
QuestionLook forwarding for silverlight Pinmembercaosnight2:19 21 Oct '11  
Questionwhy in your viewmodels you have a reference from its view? Pinmembermtaboy10:34 7 Oct '11  
AnswerRe: why in your viewmodels you have a reference from its view? PinmemberEnrique Albert17:35 7 Oct '11  
GeneralRe: why in your viewmodels you have a reference from its view? Pinmembermtaboy22:46 7 Oct '11  
GeneralRe: why in your viewmodels you have a reference from its view? PinmemberEnrique Albert4:00 8 Oct '11  
GeneralMy vote of 5 PinmemberWooters6:36 7 Oct '11  
QuestionBroken Link! PinmemberRoland Ebner0:22 24 Aug '11  
AnswerRe: Broken Link! PinmemberEnrique Albert3:04 24 Aug '11  
GeneralMy vote of 5 PinmemberSathishkumar_P1:56 14 Feb '11  
GeneralMy vote of 5 PinmemberVivek Johari5:02 9 Jan '11  
Generalnice one - have 5 PinmemberPranay Rana11:28 7 Jan '11  
GeneralOne Suggestion Pinmemberprasad024:46 22 Dec '10  
GeneralMy vote of 5 Pinmemberprasad024:45 22 Dec '10  
GeneralRe: My vote of 5 PinmemberEnrique Albert17:14 22 Dec '10  
Questionwcf datacontracts PinmemberWebGrave1:52 21 Dec '10  
AnswerRe: wcf datacontracts PinmemberEnrique Albert4:09 21 Dec '10  
AnswerRe: wcf datacontracts PinmemberWebGrave4:31 21 Dec '10  
QuestionWhat are the requirements to run this project ? Can I run this on VS2008 ? What other add-ons are required ? Pinmemberrajesh_chan2:06 12 Nov '10  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120206.1 | Last Updated 10 Oct 2011
Article Copyright 2010 by Enrique Albert
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid