Smart client (SmartClient)
Summary
This paper mainly discusses the client application model based on the enterprise environment. Since I have worked in the development of the traditional client / server two-layer structure application and the development of multi-layer structural applications based on the .NET platform, this article will focus on .NET A smart client application model on the platform, and a more complete client software framework is constructed step by step according to the needs of the general enterprise application system.
table of Contents
Introduction
Overview
definition
.NET platform WinForms application example
First, system needs
Second, the operation method
Third, create a program
Fourth, release procedure
V. Update
6. Expand application components
summary
Reference resource link
Introduction
The concept of the smart client is proposed as a characteristic of the Microsoft.Net platform. It is actually that it has already existed in the traditional application, just the .NET platform provides support from the system and language levels to make the development of intelligent clients Applications are more convenient. This article will discuss the functions and features of the intelligent client from the perspective of the enterprise application system and how to implement it on the .NET platform.
Overview
1. Comparison of current client application models
The current client application model is roughly divided into two: C / S (client / server model) and B / S (browser / server model). Software developers based on corporate environments, how to go to the browser-based thin client (Thin Client) application model, and how to go between the corresponding rich client (RICH Client), faced Difficult generation replacement.
The advantages and disadvantages of browser-based applications:
# Easy to install: You can be used in many tablets and have nothing to do with the operation platform of the client algorometer. Most computers have been installed by default (some application systems need IE, or need to install Java virtual machines, which is temporary and neglected).
# Easy to deploy and maintain: You only need to deploy and maintain work on the server side.
# Must work online: work efficiency and network delay is related.
# Do not make full use of the resources of the client computer: only the user interface can be rendered by a limited HTML language, and the calculation processing power of the client computer can not be used. You can only print the information using the browser's printing function, not applicable to the company's report printing.
# 网 网 传号:: Since the client cannot save status data, the user interface content must be transmitted between the client and the server and the required data.
#Howa is low. For the server, you can filter data through firewall software because all transfer content is based on HTTP ports. However, it is difficult to encrypt and sign the data to ensure integrity during transmission. (HTTPS does not seem to solve the problem)
# Suitable for e-commerce or not required to strictly control the client's application.
Frequently and disadvantages of rich client applications:
# You can work offline: Prerequisites the ability to have cache data locally, which involves synchronization with server data.
# Take advantage of the resources of the client computer: You can provide users with a wealth of interface elements, you can access the native disks with the native application interface (API), and the speed is faster.
# 网 网络 网络 传 量量: Just transfer data between the client and the server.
# Higher security. It can be convenient to perform encryption and decryption operations on the client and servers, and can also eliminate traditional applications such as firewalls and HTTP obstacles through Web Service.
# Installation, deployment and maintenance work is more cumbersome: there is a certain limit and requirements for client computers on operating platforms and additional software.
# Suitable for an internal application.
Currently, there is another browser-based thin client application. They are provided to users through technology and tools such as Microsoft Terminal Server, Citrix System's Independent Computing Architecture and MetaFrame products. These types of solutions allow users to use the experience of fat clients and managed by centralized software installation and maintenance, which is very cost-effective to the company. The problem with this mode is that when the application is not connected to the application server, the user cannot be used. The client does not perform real processing, processing completely relying on the application server, which causes server performance issues and consumes the CPU cycle of desktop computers. In short, relative to rich clients, browser-based models is a great model for information technology (IT) system administrators, but there are many shortcomings for developers and users.
Microsoft .NET Framework will meet the needs of these triples. Its intelligent client application model combines the powerful functionality and flexibility of rich client models, as well as easy deployment and stability based on browser-based models.
2, other features that the client application should also have
For enterprise application systems, the client application uses the interactive interface of the entire system and the user, but also needs to consider the following features:
# Security: The security here is mainly to apply security, mainly through user rights, role assignments. For client applications, a login form or login page is usually required to complete user identity. Applications with higher security requirements may also need to provide reliable security services for applications through public key infrastructure (PKI), and clients attach an encrypted signature module.
# Scalability: The client application should have the ability to include a variety of different types of application modules, while continuous increased applications in the process of use to improve the entire system. Therefore, the client application can be designed as a container, and each application module is dynamically loaded by the container as components.
# Configurability: Due to user permissions and user preferences, client-loaded application components and presentations are different from person. It is necessary to pass the application system to the client, and the user's personalized configuration information is required to interpret and present the corresponding user interface.
definition
In summary, we have a general definition of the smart client application model: an extendable desktop application that integrates different applications, and has the following features:
# None contact deployment: Install as long as you download a primary program file to the local, running directly, no need to change the registry or shared system component, other application components will be automatically downloaded at the first time.
# Auto Update: Simply publish the new version of the program on the server, automatically discover the latest version of the program and application components by the client, and download and update automatically.
# Offline Application: Allows the server to operate with the local client program and application components.
# Dynamically loaded application components: Application software developers can develop according to the public interface of the enterprise application system, and then publish the application component on the enterprise server, and the client application will automatically discover and load the application component.
# Personalize User Interface: Users can set the client application according to the preferences, and the configuration information will be saved to the server.
Here we will describe the above features as an example to be described in detail with the .NET platform WinForms application.
.NET platform WinForms application example
First, system needs
1, client software requirements
Any operating system that supports .NET Framework
.NET FRAMEWORK installed in SP1
Internet Explorer 5.0.1 or higher
2, server software requirements
Automatic release, update server: Microsoft .NET Framework, MDAC2.7, IIS II, Operation mode
The client application has two ways of operation. Different running methods will directly affect the subsequent program collection and updates, and will explain the following explanation:
1, network operation
The .NET Framework installation provides a mechanism for hooking Internet Explorer 5.01 and higher to listen to the requested .NET assembly. During the request, the executable is downloaded to the disk called an assembly download cache (Windows2000 is: c: / documents and settings / administrator / local settings / application data / assembly in a subdirectories), The assembly itself and other related assemblies it references are also downloaded to the local IE cache (Windows2000 is: C: / Documents and Settings / Administrator / local settings / temporary Internet files). Then, the process named IEEXEC starts the application in an environment with limited security settings. For example: You can enter a .NET executable (http: //smartclient/myApplication.exe) published on the web server in the address bar of IE, IE does not prompt you as much as other files, and It is directly executed.
In this way, the application runs with very limited security settings (INTERNET Rights Set), the permissions in this permissions include: Security, File dialog, print, independent storage file, user interface. Independent storage files allow your application to save some data (Windows2000 is: c: / documents and settings / administrator.tomato / local settings / application data / ISOLATEDSTINGS / Application Data / ISOLATEDSTINGS / Application Data / ISOLATEDSTINGER), the default storage space is 10MB), you You can save the data through the class in the system.io.isolatedStorage namespace without thriving.
Example:
/ / Get a separate storage area by user, domain, and assembly
IsolatedStorageFile isoStore = isolatedStorageFile.GetStore (isolatedStorageScope.user
IsolatedStorageScope.domain | IsolatedStorageScope.assembly, null, null;
//Create a directory
Isostore.createdIRectory ("Testdir");
//Create a file
IsolatedStorageFileStream isostream1 = new isolatedStorageFileStream
("TestDir // Test.txt", FileMode.create, Isostore;
// Write file
Streamwriter Writer = NULL;
Writer = new streamwriter (isostream1);
Writer.writeline ("Hello isolated");
Writer.close ();
isostream1.close ();
In order to make your intelligent application to run, you need to change some of the security settings of some clients, essentially to notify the client runtime to believe your application. One way is to add a site with your assembly to the IE to trust the Site list, and then use the Microsoft .NET Framework Configuration tool installed in your management tool directory to modify the .NET Framework security settings. Open the Framework Configuration tool, select Run Launch Security Policy, then select Adjust the security zone. For all sites specified in the trusted site, adjust the trust level to full trust. As a choice, you can also use the Framework Configurative tool to modify the security policy so that it trusts the individual assembly of your application. Right-click Run Launch Security Policy to select the level of trust in the assembly. Another optional method is to use the code group to help you improve the security settings of the application's assembly with the Framework Configuration tool. You need to make this change in desktop users using your application. To help complete this task, the Framework Configuration Tool can create a Microsoft Installer (MSI) deployment package that contains security policies. The MSI has installed the application loader to distribute the security policies and loader assembly you need for your application. Right-click Run Launch Security Policy to select Create a deployment package.
In the network run, the automatic update is done with the Cache mechanism of IE. That is, when you need to download and run an application, IE sends an HTTP request to the web server. The request will get the latest update date of the program on the server, if the date is greater than the date of the local cache or the local cache If you exist, you download it from the server, otherwise the program directly uses the local cache. Therefore, for the version mechanism of the .NET itself, it cannot be used as a version update. Only when an assembly file is referenced to another assembly, it will determine the version number according to its own version of the machine.
Precautions:
# This way of operation usually needs to set the security policy before running.
# When loading an application component, you need a complete URL address.
# If the application set needs to call the Web Service, the server address where the web service can only download the assembly server, which can construct a redirect to resolve this issue.
# Some files may not be able to complete the version update by an automatic update mechanism, such as the configuration file for .config applications.
# If there is some correlation between the versions of some application set files, in some cases (such as: Network Sudden Interrupt) may not properly load and cause an error in client applications.
# If the user clears the cache of IE, the client application will not be able to work offline.
2, local operation
As the name suggests, this runtime client application and other application components are not running in the IE cache and .NET download cache, requiring the user to download the client assembly and save it to a local directory and run. This client application and other application components have all local security privileges.
Although not involving security issues, how does the application component and the automatic update of the program are implemented? This requires a separate component to complete these tasks. With this link address, you can download a very well-supported extensive automatic update component (http://www.gotdotnet.com/team/windowsformDater.zip), which provides source code, some examples, and documentation in this package file. This update component uses HTTP-DAV technology to complete the transfer between files and clients, so there is a certain limit on the web server, IIS5.0 and new version of Apache support this feature. For details, see the contents of the documentation.
Precautions:
# Because you need yourself to implement update and download features, it will increase a certain amount of work. (That is to use third-party update components, you also need to improve it to meet your own requirements)
# Basically solve the shortcomings of network operation, but you need to re-download all files each time you update (if you use incremental updates, some versions of files are missing), increase network traffic.
# You should perform updates and downloads in the background thread, do not affect the normal operation of the user.
Third, create a program
Perform steps in the client application:
1, login system. You usually require a login form by entering the username and password or any other way. (This step requires the client application to execute online online, so you can consider providing a button that is offline on the form, and then directly uses the configuration file copy of the server when the last online login is used. This will trigger some security issues and The problem with client data and server data synchronization.)
2. After the application server verification, obtain the user's application component and its corresponding configuration information according to the user rights set by the system, and acquire the user's personalized configuration information from the database, combining these configuration information into an XML. The configuration file stream is passed to the client application. This step is usually performed by a web service call.
3. The client program parses the configuration file stream, sets the main format according to the personalized configuration information, load the corresponding assembly file according to the application component configuration information. Save the configuration file to use it when you work from the line.
4. (Local Operation Mode) Start the background update thread, the line is scheduled to search the update server has the latest version of the program, if it is automatically downloaded, and prompts the user update.
5, the user will display the user interface that the application component itself is displayed in the client main form by clicking the button or menu of the appropriate application component.
The client application basically includes a login form, a main form, and an application component loader. There is an application component set class in the loader, and some methods are provided for communication between the main program and application components and between different application components, and some application components provide data as a public component to other applications, so it should pass Unified methods to get data.
Precautions and recommendations:
1. For network operation, the program set is downloaded from the server to a local cache from the server, while the download process of the local operation mode is executed by the update component, and the client main form is executed.
Method for dynamic loading assembly in .NET:
Using system.reflection;
/ / Network operation mode, the loaded assembly path is the URL address on the server.
askMBLYFILENAME = "http://smartclient/appcomponent1.dll";
// Local running mode, loaded assembly path is local directory path
askEMBLYFILENAME = @ "c: /smartclient/appcomponent1.dll";
AskEMBLY ASM = askMBLY.LOADFROM (askMBLYFILENAME);
2. The main form of the client application acts as a container of the application component, and can display the user interface of the application component through two ways:
The first way is to design the client application as a multi-document interface (MDI) application, each application component contains a respective start-up mainfield, and the client application performs each application component, will construct and display The component is started. The "Window" menu item containing the submenu is often switched between the main window or the application is used in the MDI application.
Another way is to reserve an application interface area in the primary window interface of the client application, and each application component is added to the control array of the application interface area as a user control. Application interface area is typically a panel (PANE) control, switches between the various applications by changing the Z order of the user control (Control. Bringtofront ()). 3. When the client application loads the appropriate application components based on the configuration information, you need to create the corresponding button and menu item on the toolbar or menu of the client main form, and add events to facilitate user operation. The client application and application components should be kept independent, reducing the association to reflect the client application structure clear and simple. This can be achieved through the callback (event delegate) in .NET.
4, .NET due to caching, the following problem occurs when loading the assembly:
// First load
AskEMBLY ASM = askMBLY.LOADFROM (@ "c: /smartclient/appcomponent1.dll");
Activator.createInstanceFrom (ASM.GETTYPE ("AppComponent1.mainform");
// Load a file name in different directories in a different directory, but different assemblies
AskEMBLY ASM = askMBLY.LOADFROM (@ "c: /test/appcomponent1.dll");
Activator.createInstanceFrom (ASM.GETTYPE ("AppComponent1.mainform");
After the second load, there is no correctly constructed the form type in different directories, but use the first load in the cache.
In order to solve the above problems, these two types instance must be constructed in different application domains (Domain).
// Load a file name in different directories in a different directory, but different assemblies
Appdomain newdomain = appdomain.createdomain ("newdomain");
Newdomain.createInstanceFromandUnwrap (@ "c: /test/appcomponent1.dll", "appcomponent1.mainform");
Note When using this method, if you constructed the type instance contains a parameter constructor, these parameter objects must be an object accessed across the application domain, that is, a sequentially-sequenceable object. You can set the survival policy of the remote object by inheriting the MarshalByrefObject object or using the [Serializable] feature tag class.
Example:
Public Class Parameterclass: MarshalByrefObject: MarshalByrefObject
{
Public override Object InitializelifetimeService ()
{
/ / Define the living term lease object used by the remote processing life service
ILEASE Lease = (ilease) Base.initializelifetimeService ();
IF (Lease.currentState == LeaseState.Initial)
{
// Set the initial time of the lease. The lease will never expire, and the object associated with an infinite survival.
Lease.initialLeasetime = Timespan.zero;
}
}
}
Fourth, release procedure
1. Set a virtual directory on the publish and update server (such as: smartclient) to place all files of the application component in the appropriate directory.
Setting attributes in the virtual directory must include: read and directory browsing permissions, and execute the license as pure script.
For local mode, you need to set multiple directories based on the version number of the client application, and all files of different versions are stored. (You can also store only updated files in the new version of the directory, but you need to modify the update component. When the user updates the version, you must download the files larger than all new version of the current version to prevent some cases. A version of the file is missing questions).
In the local mode of operation, you will also need to maintain a newer list file in the root directory because it allows users to log in with an old version of the client application.
2, release a web service. The Web service mainly completes the following tasks:
# Execute the authentication of client users
# Get the list of application components that the user allowed by the entire application system, contains the location of the application component, the file name, and the configuration information required to apply the component itself. (In the local mode of operation, the list is related to the version)
# Get personalized configuration information of the user from the database, and the information obtained by the previous step is combined into an XML file stream.
# Return the configuration file stream as the return parameter to the client application.
3. Place the client application in the virtual root directory as the loader of the application component assembly, and add a link to the client application on the enterprise internal website. For network operation, a link to the Security Policy Deployment Package (MSI) file will also be provided.
User execution steps for the first time
Network operation mode:
# Download and install the Security Policy Deployment Pack
# Download and execute client applications by clicking on the link of the client application
# Add this link to your favorites or create a desktop shortcut for easy running
Local Operation:
# Don't directly click on the link to the client application, save this link to the directory of the user selection
# Perform a client application in the Explorer
# Built shortcuts for executable on the desktop for easy operation
V. Update
The update step of the network operation is simpler, and only the updated file can be overwritten directly. Its disadvantage is that the reference files included with some assessments cannot be automatically downloaded new versions, and only updates can be implemented after emptying the client's IE cache.
The update steps for local running methods are as follows:
# In the server virtual root directory, create a directory named by the new version number, incremental updates simply copy the updated file to the directory, otherwise you need to copy all files to the directory.
# Modify the file that holds all versions of the list and indicates the latest version number of the current event, and is used to compare with the client.
6. Expand application components
In order to realize the scalability of enterprise application systems, through interface definitions, application developers can make them easily add their application components to client applications by implementing them. The following describes the mainly included methods and properties in some interfaces.
1. Application Component Name Properties: An annotative text used to indicate the function of the application component.
2. Application Components In the client application, each interface element property is used: refers to the toolbar, menu bar, drop-down menu item and list box, etc., which require the application component to provide the application component. Text, pictures, icons, menus, event processing methods, etc.
3, initialization method: The method of executing when the client application loads the application component. When loading the application assembly, for the configuration information of each application component itself included by the configuration file, the client application is not parsed, but the configuration information is passed to the application component when initializing the application components. Increase flexibility.
4. Get Application Component Loader Method: After obtaining the application component loader, you can get some of the shared data required by the application by the public method included.
5, get the method of applying the application component start control: The start control can be a form or user control.
6. Turn off the method of the application component (optional): When the client application is turned off, the method is executed. The application component itself determines whether it can be turned off according to its own situation, and immediately release the system resources occupied by the component. For the MDI application, you can process in the shutdown event of the startup form without this method. The application component loader within the client application can determine whether the component meets the excuse definition by enumerating the type of component set. At the same time, multiple application components can be packaged in an application set. This process is very time consuming.
Example:
/ / Load assembly according to the assembly file name
AskEMBLY ASM = askMBLY.LOADFROM (askMBLYFILE);
TYPE [] TYPES = asm.gettypes ();
/ / Search all types in the program
FOREACH (Type T in Types)
{
/ / Indicent whether the type is encapsulated by reference, support remote processing
IF (! t.ismarshalbyref)
CONTINUE;
// Determine if the type of the assembly is in line with the type of application component interface
IF (array.indexof (t.getInterface (), plugintype) <0)
CONTINUE;
}
summary
The above is merely a simple description and demonstration of creating a smart client application, and the problem that may encounter may be, I hope to help you create more powerful, flexible, and convenient applications. .
Reference resource link
1, Security and versioning models in the Windows Forms Engine Help You Create and Deploy Smart Clients
Http://msdn.microsoft.com/msdnmag/issues/02/07/neetsmartclients/default.aspx
2, Smart Client Application Model and the .NET Framework
Http://msdn.microsoft.com/netframework/techinfo/articles/smartclient/default.asp
3, State Sanity Using Smart Clients
Http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms05202002.asp
4, Increasing Permissions for Web-Deployed Windows Forms Applications
Http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms11122002.asp
5, .NET Application Updater Component
http://www.gotdotnet.com/team/windowsforms