services   articles   contacts  
 
base Smart Client quick start up
Introduction


The goal of this article is to demonstrate with a simple project how it's possible to create a basic Smart Client. The result could be a sort of Smart Client Starter Kit. In this project we will create a PostIt application where the data is centralized on a server. Unfortunately it's not a step by step tutorial, architecture choice will be commented but small knowledge of Smart Client are required. There is no database used in this project it could be easily added in a real server.

The complete solution will be available soon.

 

Create a Web Services


We need a server, a .Net Web Site to receive web request for our smart client. We start by creating a Web Service. To be sure that our code is encapsulated, create a new static class.This class will serve a kernel of our server.All the data access will be there.

We could also create a singleton but I prefer static methods because the call is shorter but it's not possible to use inheritance. Named the class KernelServices.cs. This class will contains all the server code required and it could reused in an other project. What will be in the Web Services? Practically nothing, it will only contains call forwards and it will authenticate and authorize requests then.the call will be forwarded to KernelServices.

The main objective is to uses the Web Services only as a middleware. That's mean that if in two year, a need a .Net Remoting server, the change will be easy. Common mistake is to execute the code directly in the Web Services.

 

Create the Business library


I really enjoy object programming, that why I always create a business library with an object model inside. In this case, we will keep it simple. We will create only a User object and a PostIt object. We will put business rule inside our object. They will be used on the server and on the client. A user and a PostIt will be identified by a GUID. Business object are for me data container. They contain data, they know how to validate them, but they don't know how to get saved. It's like a dataset,

The dataset don't know how it could be saved to a database, we need a SqlDataAdapter or class similar to save it. That the way I see business object. You will be able to support change more easily this way. That mean that an object could be in an invalid state. I prefer a method validate that return ValidationResult instead a exception raise each time an invalid property is set. Why, just because user will be able to enter data before doing a save.


Create the client application (Part 1)


We have the server, the business objects, It's now time to create the client. The first form will be the main form. This form will look like this. [Image]

It's will contains a grid with our note and the note detail will appear when we select one. A small menu and toolbar will complete the UI.

 

Finalize Server Methods


The first method on the server will be used to logon and logoff the user. This method will return a user if it's good. We need this method in the Web Services and in KernelServices [Example]

The second method will be to return all the PostIt for a the current logged user.

[Example] The third method will delete a specific PostIt ID.

Example] The last one will save or add a new PostIt. [Example]

 

Generate the Client Proxy


We now have all the piece of the puzzle, but we need to link then. The common way of doing that is to add a Web Reference. If you add a Web Reference, .Net will generate a new class for your business object and you will lose many build feature from Business.dll.

I recommend xwsdl.exe to generate the proxy. You can specified which namespace you want to import. This tools will generate a proxy exactly like Visual Studio but without the business object. When your proxy is executed, the returned objects from the server will be deserialized in your business object. All you need is to include in your reference Business.dll and use xwsdl to generate the proxy. [command line] We can now call login method and receive the current user value.

 

Session handling


By default ASP.Net handle the session in process, we must add a custom attribute to the method. [EnableSession(true)]. On the client side, we need a cookiecontainer. It will be responsible of the session ID. That way the client will be able to tell to the server which session it is and the server will retrieve the user This is how we add the cookie container : [Example] When a user will be logged, we will put the UserName in the session. That way, we will be able to check if the current user is logged if the Session is not empty. Unauthorized user will have an empty session. The problem with the session is that if the server is restarted, we lose it. That why I change the SessionStateMode in the config for the ASP.NET State Service. It's an out process that can be shared by a server farm. It's not reliable has SQL Server, but it's fast and much better than InProc. We can now add a login form to the client and verify if the user name and password is valid. The real security will be handled later.

 

Finalize Client


We can now call Login and logoff get the PostIt. We can also add code to add, delete or edit PostIt value. We have a tiny smart client with some missing features, but a workable version.

 

Http Compression


Http compression could be activated in IIS 6.0 or we can use the third party. One of the best free library is HttpCompress. It's very simple to include in your server, simply add the assembly and configure the web.config.

 

Auto update

Clickonce
Security

For a secure connection, use SSL.
Synchronize version in the build

Assembly Info Creator
Error logging

Log4Net
Copyright ©2006, Devolutions inc.




Français