Pinx0
Pinx0

Reputation: 1258

Three-tier architecture using WCF

I have an app structured in two tiers (presentation and business logic in the client (WPF using MVVM) and data in one SQL server), but I'm facing the problem that it uses too much RAM in the client due to the need of a large collection of objects to manipulate.

So I thought of changing into a three-tier architecture, adding a service in a server to process all the business logic and provide the clients only what they need to display using WCF in order to lower its requirements in memory.

My question is about how to properly do this. Communication between this server and the data (in SQL server) is pretty straight-forward, but what should I send from the server to the client?

For example, following a MVVM approach, should I send (from the server to the client) the models, the viewmodels, or what? If the viewmodel's properties reference the model and I only send a List of ViewModels, would the client be able to read the info?

Can you provide me with some real world examples of this?

Upvotes: 3

Views: 1433

Answers (1)

David Vogel
David Vogel

Reputation: 465

Consider adding a service layer in conjunction with business objects to carry data from the server to the client.

From Microsoft's Microsoft Application Architecture Guide:

Custom Business Objects. These are common language runtime (CLR) objects that describe entities in your system. An object/relational mapping (O/RM) technology such as the ADO.NET Entity Framework (EF) or NHibernate can be used to create these objects

Your question, "should I send (from the server to the client) the models, the viewmodels, or what" is mixing the responsibility of the UI pattern (MVVM) with sending data from the server to the client.

By adding a service layer you can avoid the memory issues and manage the burden of carrying around objects. Consider using an Object Relational Mapper for these objects like Microsoft's Entity Framework or, for improved performance, a light weight ORM like StackOverflow's own Dapper.net. Finally with careful utilization of delayed query execution with IEnumerable you should be able to solve your performance problems.

A high-level discussion is helpful at this stage as there are many directions you can take this design. For further guidance in designing such a system, refer to Microsoft's Application Architecture Guide, Chapter 5: Layered Application Guidelines. While the image below may describe more layers than you need, it is a helpful reference. The service layer can manage the business objects that are presented to the client:

enter image description here

Upvotes: 1

Related Questions