Download presentation
Presentation is loading. Please wait.
Published byFrederick Hardy Modified over 9 years ago
1
Web Applications Enterprise Application Architectures Dr. Mohammad Iqbal Thanks to Yingcai Xiao
2
Main Issues for Developing Enterprise Applications User Interface, Data Storage, Security, Business Logic, Networking. To deal with those issues effectively, modern enterprise applications are usually designed as multi-tier applications.
3
Client Server Interconnection Network A Two-tier Application (Client-Server) Multi-tier Application: an application consists of multiple programs each may reside on a different system. Multi-tier Applications
4
Client Database Server Application Server Interconnection Network A Three-tier Application In a three-tier application, a Database Server is an independent program deployed as a part of the application to store data. Multi-tier Applications
5
A Four-tier Application Multi-tier Applications Client Database Server Application Server Internet Web Server A Web Server is added. It uses the standard protocols (HTML/HTTP) to communicate with the client. The client is thin: a standard web browser.
6
Client: interface to the user. It should be as thin as possible. Thin-client: no software to install on the client site except a standard web browser. Thin-client makes applications easy to deploy, easy to maintain and easy to upgrade. Web Server: communicates with the user interface. Application Server: business logic implemented here with tools from ASP.NET, J2EE, WebLogic (BEAS), WebSphere (IBM). Most application servers have separate modules to dynamically generate user interfaces to be sent to the client by the web server. Database Server: persistent data stored for the application. All three server could reside in the same server hardware. Multi-tier Applications
7
web applications Applications delivered over the web! Many server side components –N-tier architecture Very wide range of functionality –web mail –online retail sales and auction sites –wikis, discussion boards, weblogs –multi-player online role-playing games, etc…
8
software components of a web app web server –configuration files general processor components –e.g. PHP, ASP processor, XSLT processor application-specific software –servelets –scripts
9
data components of a web app databases –possibly distributed or mirrored session information –stateful servers retain session information –may persist in a database global information –shared by all or many web app processes –e.g. number of hits on the site, user profiles
10
file components of a web app web pages –html files, stylesheets –script files, applets –images dynamically generated pages –templates, e.g. PHP, ASP pages –xml files web app architecture –structure definition and global data files
11
design problems construction and testing –how do we build a web application? –what technology should we choose? re-use –can we use standard components? scalability –how will our web application cope with large numbers of requests? large volumes of data exchanged?
12
design problems security –how do we protect against attack? viruses malicious data access denial of service –different data views user types individual accounts data protection
13
design patterns a design pattern is a general solution to a common software design problem provides a development template OO design patterns: –relationships and interactions between objects not a finished design –the pattern must be adapted to the application –cannot simply translate into code
14
design patterns originally developed for architecture –Christopher Alexander ideas were adapted to OO Design –Beck and Cunningham, 1987 –Design Patterns: elements of Re-useable Object-oriented software, 1994 Reprinted and analysed many times now widely-used in software engineering
15
The Model-View-Controller Pattern very widely used pattern allows separation of development effort model –contains data and system state view –presents data and system state controller –handles events affecting model or view
16
model-view-controller model knows little about the view –simply signals changes (alerts listeners) view understands the model interface –uses model methods to get update data controller knows model and view interfaces –updates model in response to events –updates view in response to events or changes in the model
17
model-view-controller model viewcontroller event event is passed to the controller controller updates model and/or view view queries model model signals changes
18
developing a M-V-C app build the model –public methods become the interface for views and controller –build simple views to test the model build the view(s) –use simple controllers to test view and model build the controller –implement handling of all events maintain –model remains fairly stable, views and controller may become more elaborate
19
M-V-C for web applications
20
Model for Web Applications model consists of data and system state database tables –persistent data session information –current system state data business logic (eCommerce) –rules governing the transaction
21
View for web applications view gives a presentation of the model client-side presentation in a browser window –(D)HTML –CSS stylesheets –server-side templates administrative information –server output logs
22
Controller for web applications controller handles events user-generated events –client-side scripting –http request processing –redirection –preprocessing system maintenance –web application management
23
M-V-C Example PHP /CGI Web Server Web Browser presentationrequest processingprogram logic controllerviewmodel two-tier client-server architecture
24
M-V-C Example JSP /ASP /CF Web Server Web Browser entity database view controller view/ controller model multi-tier client server architecture
25
J2EE Web Application Structures
26
J2EE Java 2 Enterprise Edition (http://java.sun.com/j2ee) a platform for developing multi-tier enterprise applications with standardized modular Java components provides a complete set of services to handle many details automatically takes advantage of many features of the Java 2 Platform, Standard Edition (J2SE)
27
J2EE Application Architecture Thin Client Application Server (BL) DB Server J2EE-Enabled Web Server Application Server (UI)
28
Architecture of a Three-Tier Application DBMS / Database Server Database User Interface Database Engine Supporting Software Application Server Database API Application Logic App User Interface CLIENTCLIENT Architecture of a Three-Tier Application
29
ASP.NET Web Application Structures
30
.NET Web Applications are applications built for the Web using the.NET framework. The applications use Web forms to provide user interface, per-user data stores to hold shopping carts, caching services to boost performance, and security services to identify users and prevent unauthorized accesses..NET Web Applications are actually Application Servers in the four-tier architecture. Other programs (client, web server, database server) need to be there to make the applications work. The those programs can be shared with other applications..NET Web Applications
31
DBMS / Database ServerApplication Server WEB S E R V E R WEB C L I E N T Database User Interface Database Engine Supporting Software Database API Application Logic App User Interface Architecture of a Four-Tier Application
32
Structure of an ASP.NET Web Application An ASP.NET application. The Web.config File To support XCOPY installs— to install applications by copying them to a directory and uninstall them by deleting the files and directories.
33
Structure of an ASP.NET Web Application An ASP.NET (web) application (server) consists of all the files in a virtual directory and its subdirectories on the HW server. ASPX files containing Web forms (unlimited) ASCX files containing user controls (unlimited) Web.config files containing configuration settings (one per directory) A Global.asax file containing global application elements (only one for the entire application) DLLs containing custom types employed by the application (unlimited, must be in the bin directory under the root of the virtual directory)
34
Create a Web Application in IIS * You need to be an administrator to use IIS winserv1 -> Sites -> Default Web Site Right-click->Add Application (not Virtual Directory) Alias: xiaotestLander Application pool: defualtAppPool Physical path: C:\inetpub\wwwroot\xiaotest\Lander http://winserv1.cs.uakron.edu/xiaotestLander/Lander.aspx Existing directories can be converted to Web Applications winserv1 -> Sites -> Default Web Site->xiaotest Right-click on Lander Convert to Application Application pool: defualtAppPool http://winserv1.cs.uakron.edu/xiaotest/Lander/Lander.aspx
35
Extensible Markup Language A markup language for documents containing structured information. The XML specification defines a standard way to add markups to documents to identify structures in a document. Both the tag semantics and the tag set are user definable. A meta-language for describing (defining) markup languages. Commonly used to describe data transmitted over the Internet. http://www.xml.com/ XML
36
Web.config Web.config is the XML file in which ASP.NET applications store configuration data. Not in the registry anymore. Case sensitive. Inherited, can be overridden by subdirectories. Machine.config is at the root. Under Windows\Microsoft.NET\Framework\vn.n.nnnn\Config
37
Web.config Use system.web in.config to set system-wide configurations. ‘customErrors mode="Off”’ means “systemErrors mode” on.
38
Debugging Each web application needs its own application directory. For a web form application, the application directory containing the web form is treated as the root of the web “application”. e.g. Copy files from “Examples/c9/Debug” to a A.D. Edit calc.aspx in it. Change op1 in “OnAdd” to op11 Better view it with I.E. http://winserv1.cs.uakron.edu/Examples/c9/Debug/calc.aspx Show Detailed Compiler Output
39
Debugging
40
Web.config Three custom errors modes 1.On: displays custom errorMessage.html locally and remotely 2.Off (default): displays debugging information locally and remotely. (Dangerous!) 3.RemoteOnly: displays debugging information locally and errorMessage.html remotely
41
Debugging http://winserv1.cs.uakron.edu/Examples/c9/Debug/calc.aspx Custom error mode “On”, but no defaultRedirect
42
Web.config Default custom error mode is Off: very Dangerous! Displays (code) debugging information locally and remotely.
43
Web.config Strings defined in the.config file can be retrieved in the program at run time: string conn = ConfigurationSettings.AppSettings ["MyConnectionString"]; <add key="MyConnectionString" value="server=db1; database=pubs; uid=sa; pwd=" /> <add key="connectString" value="Integrated Security=true;Initial Catalog=pubs; Data Source=XIAO-T23-01" />
44
text file application-level only one for each application directives event handlers declarations Global Directives: The Global.asax File
45
Global Event Handlers For events that aren’t specific to a particular page but that apply to the application as a whole: Application_Start, Application_End, Session_Start, Session_End, Application_Error. An application consists of multiple pages (static structure). An application can support multiple sessions at runtime, one for each client (dynamic structure). Global Object Tags Session["MyShoppingCart"] = new ShoppingCart (); To use in an application: <object id="MyShoppingCart" class="ShoppingCart" scope="session" runat="server" />
46
to improve application performance data stored in memory as dictionaries of key/value pairs string keys available to all parts of an application (global) Application Cache is replacing Application State. Application State & Application Cache
47
The Application Cache A per-application, in-memory data store. System.Web.Caching.Cache Pages: Page.Cache Global.asax: HttpApplication.Context.Cache Insert Cache.Insert ("AMZN", 12.00);// or Cache["AMZN"] = 10.00; // replace existing entry Remove Cache.Remove ("AMZN"); Usage decimal amzn = (decimal) Cache["AMZN"];
48
The Application Cache Locking System.Threading.ReaderWriterLock rwlock.AcquireWriterLock (Timeout.Infinite); Expiration (new) Absolute: Context.Cache.Insert ("Stocks", stocks, null, DateTime.Now.AddMinutes(5), Cache.NoSlidingExpiration(); Sliding (expires only if not accessed): Cache.NoAbsoluteExpiration (); Cleaning Callbacks Context.Cache.Insert (…, new CacheItemRemovedCallback (RefreshDataSet));
49
Session State: per-user store to support shopping cart (equivalent to global variables) Challenge: the Web is stateless. Client side store: cookies (users may disable cookies) Server side store - in memory (down with IIS, no Web farms (clusters of Web servers act as one)) ASP.NET session store: Cookies: client side store Cookieless: server side store – in memory, in another process, on another machine, in a database When Calc.aspx is accessed by a client
50
Session State Process Models ModelDescription In-proc Stores session state in-process to ASP.NET (that is, in Aspnet_wp.exe) (default) State Server Stores session state in an external “state server” process on the Web server or on a remote machine (slower) SQL Server Stores session state in a Microsoft SQL Server database on the Web server or on a remote machine (slowest, scalable and reliable, for e-commerce)
51
Change session state type in Web.config <sessionState mode="StateServer" stateConnectionString="tcpip=192.168.1.2:42424" /> <sessionState mode="SQLServer" sqlConnectionString="server=localhost;uid=sa;pwd=" />
52
Using Session State Page access: System.Web.UI.Page.Session property Global.asax access: System.Web.HttpApplication.Session property Both map to an instance of System.Web.SessionState.HttpSessionState Add an item: Session.Add ("10012552", "Quantity=1"); Session["10012552"] = "Quantity=1"; Retrieving an item: string value = Session["10012552"];
53
Using Session State Retrieving all items: NameObjectCollectionBase.KeysCollection keys = Session.Keys; foreach (string key in keys) {…} Remove, RemoveAt, and RemoveAll. Session timeout: Close session: Session.Abandon (); Session Identification: using GUIDs (globally unique identifiers) Automatic lock and unlock
54
<% if (Session.IsNewSession || Session["Count"] == null) { Session["Count"] = 1; Response.Write ("Welcome! Because this is your first visit to this site, a new session has been created for you. Your session ID is " + Session.SessionID + "."); } else { Session["Count"] = (int) Session["Count"] + 1; Response.Write ("You have visited this site " + Session["Count"] + " times. Your session ID is still " + Session.SessionID + "."); } %> Using Session State http://winserv1.cs.uakron.edu/examples/c9/sessionSpy/sessionSpy.aspx
55
A session is created for each client process and stored on the server. NS and IE are on different processes. Using Session State BrowserCtrl NStart->Programs IENew Thread Old Session New Process New Session (old IE) Old Session (newer IE) NSNew Thread Old Session New Thread Old Session To make your program work deterministically, your application needs to identify the user through the login authentication and respond accordingly (next chapter).
56
State Server or SQL Server session state models require types stored in session state to be serializable. [Serializable] public class ShoppingCart {... } ShoppingCart cart = new ShoppingCart (); Session["MyShoppingCart"] = cart;
57
A mini enterprise application Congo (C9) Congo: A virtual storefront for an online bookseller. Related to: database => data grid => shopping cart Forms: Database supported, web based security. Deployment: http://www.cs.uakron.edu/~xiao/windows/Web-App-Deployment.html T:\Xiao\Windows Programming\Examples\C9\Congo-MySQL http://winserv1.cs.uakron.edu//xiaotest/Congo-MySQL/Congo.aspx Output format in C# http://blog.stevex.net/string-formatting-in-csharp/
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.