From n-tier to. NET detailed profiling principle (1)

Source: Internet
Author: User
Tags implement interface sql net resource thread web services access

Brief introduction

Today, N-tier applications have become the standard for building enterprise software. For most people, N-tier applications are applications that are divided into separate logical parts. The most common choices are divided into three parts: presentation, business logic, and data, and of course there may be other partitioning methods. N-tier applications were originally designed to address problems associated with traditional client/server applications, but as the Web age came, the architecture began to become the mainstream of new development projects.

Microsoft Windows? DNA technology has become a very successful foundation for N-tier applications. The Microsoft. NET Framework also provides a solid platform for building N-tier applications. However. NET makes it necessary for structural designers to reconsider some of the knowledge they have learned in the field of Windows DNA about designing N-tier applications. More importantly, the basic support for XML WEB services internally placed in the. NET framework allows developers to build new applications that break through the traditional N-tier approach. To learn how to better build the architecture of. NET applications, you need to understand what has changed in this new area and how to make the most of these changes.

These issues will be discussed in this article. First, review the key architectural knowledge learned from building N-tier applications using Windows DNA. This knowledge is then applied in the same order to the application being built using the. NET framework to test them. The last section provides some suggestions for the architecture of applications that use XML WEB services.

Windows DNA Environment

It is very uranium to have the application feared for multiple logical portions. Dividing a large software into smaller sections can be more beneficial to the construction, reuse and modification of software, as well as to adapting to different technologies or different code business organizations. At the same time, there are some comprehensive factors to consider. While modularity and reuse are effective, they can lead to winning programs that are not as safe, manageable, and fast as other methods. This section will review some of the 牸 from using Windows DNA to 豕 mushrooms? N-tier Application universal experience in the base 1 guilt Alex to the ?

Writing business logic

Windows DNA applications typically use one or more of the following three implementations to implement their business logic:

ASP page

COM group, may use other services provided by COM +

Stored procedures running in the DBMS

In general, it is not a good idea to write too many business logic in an ASP page. Because you must use a simple language, such as Microsoft Visual Basic? Script (VBScript) and interprets the code every time it executes, which can have an impact on performance. And the code in the ASP page is not maintainable, mainly because the business logic is usually mixed with the presentation code that creates the user interface.

Given this situation, it is recommended that business logic be implemented as a COM object when writing middle-tier business logic. This approach is a little more complex than writing a pure ASP application, but you can use a full-featured language to generate compiled executables, so the results are much faster. Wrapping business logic in a COM object can also separate the code from the presentation code contained in the ASP page, making the application easier to maintain.

From COM to COM +, the architecture is almost the same. However, as many Windows DNA architecture designers know, you should not use the core services that COM + provides, such as transactions, Just-in-time (JIT) activation, role-based security, and thread services, unless you really need them. COM + or similar services provided using other development platforms naturally lead to slower and more complex applications. It makes sense to use COM + only in the following situations:

Need to span distributed transactions across different resource managers, such as Microsoft SQL Server? and Oracle.

Applications can effectively take advantage of role-based security.

Can you enhance Microsoft Visual Basic? 6.0 of the thread operation.

JIT activation can improve performance, which is rare in browser clients, because ASP pages are active by JIT.

COM + 's configuration benefits greatly simplifies the deployment of applications.

The third way to write business logic is to create some code that runs as a stored procedure in the Database management system (DBMS). Although the main reason for using stored procedures is to separate the details of the database schema from the business logic to simplify code management and improve security, the proximity of code to data can also help optimize performance. Applications that must be independent of the DBMS, such as an application created by an independent software vendor, typically avoid this approach because it locks the application into a particular database system. Writing and debugging stored procedures can be harder than writing and debugging COM objects, and this approach reduces the chance of reusing code because COM objects are often easier to reuse than stored procedures. But most custom applications are still connected to the DBMS that originally created them, so the performance advantage of using stored procedures is great. In this case, Windows DNA applications that have to run as well as possible often use stored procedures for some or all of the business logic.

Building the Client

Windows DNA supports both local Windows clients written in languages such as Visual Basic and browser clients. The limitations of the browser client are large, especially when Microsoft Internet Explorer and Netscape are browsers. As a result, applications typically have both browser clients and local Windows clients. The browser client provides a limited interface, but it makes it easy to access the Internet, and Windows clients provide a fully functional interface. Use a downloadable Microsoft ActiveX? Controls can create more complex browser interfaces, but you must make sure that the browser is Internet Explorer and that users are willing to trust the creator of the application.

Managing State in Browser applications

ASP applications can use several different mechanisms to maintain information between client requests on a server. However, there is a strict rule in Windows DNA that if your application balances the load between two or more machines, you will never be able to use the ASP session object to store the state of each client. ASP's session object is locked on a single machine, so it cannot be used for load-balanced applications.

There is another restriction on ASP session objects and ASP application objects. Using any of them to store an ADO recordset can greatly reduce scalability because it limits the ability of applications to develop multithreading. Therefore, it is not a good idea to store recordsets in either of these two objects.

Distributed communication

In Windows DNA, the way to communicate with components that run on different machines is simple: DCOM is the only option. From a purely architectural perspective, DCOM is a simple extension of COM. In practice, however, DCOM has many other implications, including:

Because it is actually its own protocol, using DCOM to communicate with a remote COM + object is straightforward.

DCOM will be a very secure protocol as long as the configuration is correct. However, it is not easy to implement this configuration, so the protocol is not easy to use. However, DCOM itself still provides good distributed authentication, data integrity, and data confidentiality, especially within Windows 2000 domains.

Because DCOM needs to open any port, it is not suitable for use with firewalls. Therefore, DCOM is generally not available for applications that must communicate over the Internet.

Accessing stored data

The data access architecture built using ADO can be grouped into two categories: lightweight and heavy. The lightweight ADO client keeps the database connection as briefly as possible and writes it to the database using stored procedures. Lightweight clients retrieve data using one of the following three methods:

Fills a recordset by using a read-only, forward-only cursor;

Output parameters through stored procedures;

Use data flow (in a newer version of ADO).

Heavy clients keep the database connection for a long time. Such applications rely on open connections and stateful server-side cursors allowed by those connections to:

Make the recordset direct access to changes made by other users or applications;

Enable pessimistic locking;

Minimize the amount of data replicated to the ADO client to reduce network traffic. Unlike light clients, clients that use server-side cursors can keep the query results in the database until they are actually needed. In addition, this method copies less metadata to the recordset and keeps more data in the database.

Lightweight applications are the most scalable because they use the rare resource of database connectivity most efficiently. In contrast, heavy applications must maintain a long-term valid database connection, as this is required by stateful server-side cursors. This greatly limits the scalability of the application, especially for Internet server applications. Although it may be simpler to develop heavy applications with ADO, this is often not the best choice.

ADO is also not particularly useful for processing hierarchical data such as XML documents. The functional usage of ADO to complete this work is complex and difficult to understand. Similarly, ADO provides limited support only for XML features that access SQL Server 2000, so Windows DNA applications generally avoid using ADO to process hierarchical data.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.