Recently, I encountered such an application scenario. A certain enterprise has been using a system developed by PowerBuilder for many years. As the company developed, it decided to convert the old information system from C/S to the popular B/S architecture, so the problem arose: The original Some systems have a large number of data entry, precise report printing and other functions, and users are very accustomed to this kind of operation. It is hoped that the new system can retain this easy-to-use feature of the original system.
I got a headache as soon as I heard this question. PB has a lot of powerful controls. It is too difficult to move them to the browser and use web pages to simulate them.
1. Why is it difficult for B/S to provide a good user interaction experience?
There are several biggest problems here:
(1) The stateless HTTP protocol
can directly exchange information between Windows forms through memory, but as the basis of B/S architecture communication The HTTP protocol is stateless.
If the browser is regarded as a guest and the Web Server is regarded as a hotel, under the management of the HTTP protocol, this situation will occur: no matter how many times a guest visits, the Web Server will regard him as a first-time visitor. In this way, guests must bring their ID documents with them every time for hotel staff to "verify their identity."
The statelessness of the HTTP protocol leads to the "disregard" of the Web Server. Although this can increase the throughput of the Web Server, it brings trouble to the development of application systems. Because there are often many business processing processes in application systems, which are inherently information-flowing, that is, the original data enters from one end and should have undergone certain processing when it comes out from the other end. How can it be imagined that the information in the entire business process will be lost? Therefore, Sharing information between HTTP requests becomes a troublesome matter. This is the "state retention" problem of HTTP requests. Every B/S system must solve this problem. Microsoft thought of some "crooked tricks", such as making full use of the hidden fields in HTML web pages, and then doing some tricks on the Web Server, so ASP.NET has a set of technologies to maintain state between each HTTP request: Session, Cookie , ViewState, Profile, Application.
However, the problem is not completely solved. For example, in the common dialog box in C/S system that collects user input information, there is information exchange between the main form and the dialog box (it is divided into two types: modal and non-modal. The former dialog box is not closed. The main form cannot be activated). Under the B/S architecture, since each request of the browser is independent, direct information exchange similar to a modal dialog box must be implemented between two independent browser windows. I really don't know what to do.
AJAX uses the following method to "simulate" a modal form: "combine" the main form and the dialog box into one. The dialog box is a div element in HTML, which is usually hidden and displayed when needed. it. Microsoft's AJAX Control Toolkit even has a control designed for this functionality. There are countless tricks like this in B/S development.
It can be seen that many functions that can be easily implemented in C/S are very difficult to implement in B/S.
(2) Special operating environment -
the front-end operating environment of the browser B/S system is the browser, which brings many restrictions. It cannot do many things, such as directly accessing hardware (such as printers), and cannot make full use of it. Hardware resources. For example, today's new computers are all dual-core. Can you directly use JavaScript and HTML to write a multi-threaded program to make full use of these two "Pentium cores"?
The C/S system runs directly on the OS (operating system) Above, you can call all functions provided by the OS, and this limitation does not exist.
(3) The embarrassing Web client programming language - JavaScript,
a traditional C/S program, can use a large number of various development languages, especially mainstream object-oriented languages such as C++, Java, and C#, which are powerful and easy to use. , various development tools are available and are very mature.
On the contrary, JavaScript, the most commonly used programming language on the B/S front-end, is not only disliked, but even "hated" by many programmers, who regard "programming with JavaScript" as a chore.
Let’s take a look at the two major shortcomings of JavaScript.
First, there is a lack of clear and unified programming model.
Although JavaScript has Java in its name and uses similar syntax, it has nothing to do with real Java. Alas, she is an ugly duckling. She always wants to become a swan, but she doesn't expect that others don't buy her idea.
JavaScript uses many objects, but it is really unconvincing to say that it is object-oriented (the basic unit of object-oriented programming is a class). For example, it does not have the keyword class similar to mainstream object-oriented languages such as C#. It is everywhere functions one by one, which makes it difficult to clearly define all the code in the form of classes; at the same time, it is not structured (the basic unit of structured programming is a function), because the browser uses a stream when parsing HTML documents. This leads to some JavaScript code being placed outside the function and executed directly when parsing the HTML document, while the other part of the code placed in the function is mostly run in an event-driven manner, which brings about complex problems. The program execution flow is far less concise than the unified use of function calls in purely structured programming.
From this point of view, JavaScript has the characteristics of object-oriented, structured, and unstructured programming methods, but it is neither fish nor fowl. It does not have a clear and unified programming model. It is difficult to write code with a clear structure and easy maintenance. A lot of confusion came.
Secondly, another flaw of JavaScript is its browser running environment.
Due to historical reasons, different browsers, and even different versions of the same browser, have more or less different programming models. Therefore, we have to write code to detect the browser type. For example, we need to write a set of code for IE, and Wrote another set for FireFox. This is really a hassle.
The above problems are almost the "inherent" "defects" of the B/S architecture system. Innate deficiencies are supplemented by nurture, and people have come up with many tricks to solve these problems. AJAX is the star of hope that everyone is optimistic about.
2. Star of Hope - AJAX
Over the past few days, I have systematically learned about Microsoft's AJAX framework. I found that the complexity of this framework far exceeded my original estimate. Microsoft engineers who designed the AJAX framework deeply explored the potential of various Web development technologies, which to a large extent made up for the problems raised earlier.
(1) Expansion of JavaScript language:
Microsoft has enhanced the object-oriented features of JavaScript by providing encapsulated AJAX Library, which can easily implement functions such as inheritance, defining interfaces, serializing objects, triggering events, reflection types, etc., although it is smaller than the real There is still a gap between object-oriented languages (such as Java/C#), but being able to dress up "ugly" JavaScript into something visible is considered extraordinary.
(2) Significantly improve the functionality of browser-side code.
With the support of AJAX Library and the enhanced functionality of JavaScript, and with the support of the browser itself, you can write JavaScript scripts in the browser to easily make asynchronous requests to the server. , realize partial page refresh, and can directly call Web Service.
(3) Introducing the component-based development (CBD) method.
Component-based development (CBD) has long been the mainstream development method for object-oriented systems. Although SOA (service-based architecture) is currently very hyped, it needs to reach the maturity of CBD. To a certain extent, it will take time.
For JavaScript, let alone SOA, it is very difficult to implement CBD.
In order to realize CBD, Microsoft has "made major improvements" to JavaScript and enhanced many features. Based on the Microsoft AJAX Library, programmers can develop three types of reusable components: None_Visual Component (invisible component, equivalent to an object-oriented system Some of them provide public functions), Behavior (behavior, extending the functions of existing Web controls), and Control (Web controls with visual interface elements).
In particular, the dozens of controls provided in AJAX Control ToolKit basically realize the B/S simulation of most features of the C/S user interface, and are a model for the application of this new programming model.
Microsoft's enhancements to the JavaScript programming model enable software engineers to finally develop Web client code using CBD development methods. I think this is progress.
(4) Enhanced server-side capabilities
In order to enhance the capabilities of the browser-side code, it must be coordinated through the server-side. AJAX itself is based on the programming model in which Browser and Web Server support each other (Web Server provides data services, and Browser provides XMLHttpRequest objects to issue asynchronous requests to Web Server. When the data comes back, programmers can write code in JavaScript to implement dynamic partial processing of web pages. renew).
Through the AJAX Extension, Microsoft has enhanced the functionality of the server-side ASP.NET framework. And externalize commonly used functions into simple Web controls, such as AJAX's core control ScriptManager, UpdatePanel for defining updateable areas of the page, and dozens of AJAX Control Toolkit for enhancing existing ASP.NET controls. Extender control (that is, a control attached to an existing control, whose purpose is to extend new functions to the existing control).
With these controls, developing Web front-end programs is similar to designing forms in VB. Now it is not only possible to draw an interface similar to Windows Forms, but also by using AJAX's asynchronous request and partial refresh technology of the page, and with the cooperation of the Web server, the user experience can be forced into Windows Forms.
No matter how many people look down on VB, the wave of popularization of visual programming brought by VB has indeed had a far-reaching impact. Microsoft's push for JavaScript programming to this step is also the general trend. In order to improve the efficiency of Web development, this step must be taken.
However, it needs to be pointed out that no matter how much it is "replenished", after all, it is "congenitally deficient" and it is still very difficult for the B/S architecture to surpass C/S in terms of user experience.
3. The future: B/S or C/S, who is in charge?
Due to the simplicity of management and deployment, the B/S architecture has become the first choice for many information systems today. However, users pursue a good user experience. To sum up, There are the following requirements:
(1) Beautiful interface. B/S has an advantage in this regard.
(2) Convenient input. For example, many users hope to enter data without using a mouse, or to automatically fill in data through simple clicks. This is difficult to implement under a B/S architecture. AJAX can solve this problem to a certain extent.
(3) Lightning speed. For C/S, there are many ways to achieve fast response speed, but it is not easy for B/S. Due to browser limitations, the client's powerful hardware resources are almost idle. In addition, network speed is the bottleneck of the B/S architecture. Unless the bandwidth can increase rapidly, WWW will be World Wide Wait.
Although C/S has a good user experience, its problem is that it is difficult to develop a distributed system that spans the entire Internet. Moreover, since the client needs to be installed, system updates and component version management become a big problem. In addition, unlike B In the /S architecture, only server-side issues need to be considered. In the C/S architecture, due to multiple users accessing the server at the same time, the calls and dependencies between components are complex. The client must also be considered when dealing with multi-threaded access to shared resources, transaction processing, etc. With the server side, throughput is greatly limited. Therefore, C/S is mostly built in the local area network for internal use of the enterprise.
At present, B/S and C/S basically coexist. With the widespread application of B/S technologies such as AJAX, B/S continues to gain the upper hand, but it is impossible to completely "defeat C/S". ".
What’s more interesting is: How does a large company like Microsoft view the development prospects of B/S and C/S?
Ordinary developers like me don’t have the opportunity to directly talk to Microsoft executives, but we can see it from the company’s product development route. Here are some clues:
Microsoft does not seem to believe that B/S represents the future direction of technological development. On the contrary, many of its actions are moving in the direction of abandoning browsers.
First of all, Microsoft has simplified the development and deployment of C/S and launched Smart Client technology, so that the update of C/S client programs can be carried out automatically without manual intervention.
Secondly, Microsoft worked hard to bridge the gap between B/S and C/S. When designing ASP.NET, it resolutely abandoned ASP, which had achieved good results, and directly adopted a "visual control + event-driven" programming method similar to VB. Even Web pages are called "Forms" - Web Forms.
Third, Microsoft may consider AJAX to be a transitional technology.
Microsoft was slow to take action on AJAX until it saw the rapid popularity of AJAX due to the successful application of AJAX technology by Google and other companies to improve the Web user experience. Then it took action and added AJAX extensions to ASP.NET. The whole process was obviously The actions were not aggressive, and not many resources were invested. This was completely different from when Microsoft and Netscape launched a browser war. However, the fact that it has built-in AJAX Extension as a standard configuration in VS2008 and directly integrated the JavaScript debugging function into the IDE shows that Microsoft is still facing reality and recognizes that AJAX has an important position and great development potential.
In fact, I analyze that Microsoft's ambition is to "unify the world", abandon the browser, and completely unify B/S and C/S.
This is clearly seen in .NET 3.0/3.5.
First of all, Microsoft used WCF to unify DCOM, .NET Remoting and other technologies mainly used for C/S, integrating many enterprise development features originally located in COM+, together with Web Service technology mainly used for B/S architecture, to unified Abstract and encapsulate into a reusable WCF Service. It is obvious that Microsoft wants to change the information system development model from CBD to SOA (that is, future systems will assemble services instead of components).
Secondly, Microsoft abandoned the very mature Window desktop program programming model (Win32 API + message/event driver) and introduced a new WPF programming framework. One of the major innovations is the emergence of XAML (Application Markup Language) that complies with the XML specification. . XAML uses XML format plain text files to describe application interfaces.
We can easily compare XAML to XHTML. The browser parses XHTML code and generates a visual web interface, while XAML is parsed by the .NET Framework virtual machine. In Vista, since Vista directly integrates .NET Framework 3.0, Vista can be regarded as a super browser. It is responsible for reading XAML to generate the user interface and implement all its application functions.
As a result, a new programming model emerged. Whether it is a B/S or C/S system, the method is unified: read XAML code à parse à present à receive user input à process data à display. result.
In this programming model, the browser becomes a bystander and is no longer the core of the client application.
The new programming model runs on a full-featured OS rather than a browser with limited functionality. The difference is huge. How can the functions of a browser running on the OS be compared with the OS itself!
Now the operating system can be easily called through the operating system API (Application Programming Interface) organized in an object-oriented manner. various functions to make full use of the client's hardware resources (for example, you can easily develop multi-threaded programs on top of the .NET Framework to "squeeze" the working capabilities of the dual-core CPU). User interfaces are all described using XAML, which unifies the interface layer technologies of B/S and C/S.
The most suitable running environment for WPF is the Vista operating system. A subset of its functions, now called Silverlight, is implemented as a browser plug-in, allowing WPF programs to run in traditional browsers. Since both Silverlight and Vista can parse XAML themselves, you can now use XAML to write only one set of interface code, which is applicable to both B/S and C/S and obtains the same user experience.
Due to some inherent shortcomings of B/S and AJAX, if the B/S system enhanced by AJAX is compared to a dancer, then it is actually a dancer dancing with shackles, and Microsoft's idea is, Instead of constantly trying to reduce the weight of this shackle, why not simply abandon this shackle?
Microsoft's launch of WPF and WCF is such an attempt.
It should be said that Microsoft's development strategy is based on the analysis of the advantages and disadvantages of the existing B/S and C/S. It has its scientific nature and also takes into account its own business interests. . However, there are still many difficulties in realizing this strategy, because even as powerful as Microsoft, it cannot dominate the world. Microsoft's opponents are just as smart as Microsoft and their technology is advancing just as rapidly.
It can be concluded that due to the continuity of information system applications, B/S and C/S will coexist at the same time for a long period of time (maybe three to five years, maybe five to ten years). Since there are many B/S Outstanding excellent features will prevail in the competition with C/S, and this situation will not change significantly. As for AJAX, as a heavyweight weapon in the B/S system, although it is very effective, it has many flaws. I am cautiously optimistic about its future development. However, as a Web developer, you should understand and apply this technology.
What the future landscape will look like, and whether a certain technology has a future, are not decided by individuals. I think that the final pattern of the battle between B/S and C/S will be the result of the joint game between multiple factors. For individuals, they must keep pace with the times and adjust their actions and strategies in a timely manner. This is the fate of contemporary software developers.