1 / 39

MSIS 5133 Advanced MIS - E-Commerce Spring 2003 Lecture 4: The DotNET Framework – Part 1

MSIS 5133 Advanced MIS - E-Commerce Spring 2003 Lecture 4: The DotNET Framework – Part 1. Dr. Rathindra Sarathy. Contents. Part 1 Server-side programming – Microsoft Scripting Model Server-side programming – Java Model Disadvantages of Server-side Scripting The DotNet Framework.

haru
Download Presentation

MSIS 5133 Advanced MIS - E-Commerce Spring 2003 Lecture 4: The DotNET Framework – Part 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MSIS 5133 Advanced MIS - E-CommerceSpring 2003Lecture 4: The DotNET Framework – Part 1 Dr. Rathindra Sarathy

  2. Contents Part 1 • Server-side programming – Microsoft Scripting Model • Server-side programming – Java Model • Disadvantages of Server-side Scripting • The DotNet Framework

  3. Browser with Script Engine HTML Client-side Scripts ActiveX Controls XML http requests http responses Internet http requests http responses Webserver (IIS) = http server + ASP Script Engine HTML XML Server-side Scripts COM+ 2.0 COM Objects & Transaction Management Win 2000 Server SQL Server Database Server-Side Programing – Microsoft Scripting Model • Needed to activate components on the server • Used to interact with databases • Important middle-tier technology • Used to maintain application and session state. • Used to pass results back to client-tier

  4. Active Server Pages (ASP) • Contains server-side script but may also contain HTML and client-side script • Only the server-side scripts are executed on the server • Web server sends files with .asp extension to the ASP engine (asp.dll)

  5. ASP - Example • Form Collection – for forms using POST method (Example2.asp) <% option explicit %> <% response.buffer = "true" %> <html><head><title>Student Login Form</title></head> <body bgColor = "#C0C0C0" text = "#009011"><h1 align = "center">Student Login Form</h1> <% if request.form("txtName") <> "Student" or request.form("txtPass") <> "qwerty" then %> <form method="post" name="frmC" action="Example2.asp"> <input type="text" name="txtName" size="20">Your Name<br><br> <input type="password" name="txtPass" size="20">Your Password<br><br> <input type="submit" value="Login" name="btnSubmit"> <input type="reset" value="Clear" name="btnReset"> </form> <% else %> <% dim strName, strPassword, strForm strName = request.form("txtName") strPassword = request.form("txtPass") strForm = request.form %> <h3 align="center">Hi There <% = strName %> !</h3> <br><% = strForm %> <% end if %> </body></html>

  6. Request: Used by Web Server to retrieve information sent by client browser (such as from a form) • Response: Used by Web Server to send information to client browser. • Sessionbegins when browser makes first request for an ASP page. Session object can store data (like visitor name, address etc.) & share information between a single client and Web Server during the session. Session ends when session timeout is reached or user closes browser. • Application = sequence of Web pages. The Application object allows information to be shared among all users of an ASP application. • Server: Used to access the Web server’s properties and methods and instantiate objects (including 3rd party objects) on the server • ASPError: Used to obtain information about last error that occurred using GetLastError method of ASPError object. ASP Objects From Kalata Book – Page 251

  7. Components • Piece of compiled, executable code that defines objects properties, methods & encapsulates entire code • Improves reusability - only need to know interfaces • COM (Component Object Model) is a Microsoft standard for interface specification • Allows independent components written by third parties to interface and work with each other • Original code could have been in any language including C++, VB, etc. – compiled into an executable component • ASP can handle both built-in and third-party components. You could write your own component and often had to for e-commerce applications. From Kalata Book – Page 365 ASP Built-in COM components

  8. Server-Side programming – Java Model Browser User Interface Applets & Javabeans with Script & HTML Unlike VB, Java code can run directly in the browser (or server), under JVM. Therefore, it provides more options, including Common Gateway Interface (CGI) type program Internet Webserver TomCat Business Logic Servlets & EJB (Enterprise JavaBeans) with JSP Database

  9. Java Servlets • Java programs that run on the server – they are not contained in web pages, like applets are. • It is like a CGI (Common Gateway Interface) program, but is not compiled to machine language code • Portability is an advantage • Runs in the JVM (Java Virtual Machine) of web server, and so needs to be loaded only once. Available for subsequent many accesses. • Can be specified to be pre-loaded into web server when it starts up.

  10. SERVLET - Example import java.io.*; import java.util.Date; import javax.servlet.*; import javax.servlet.http.*; public class TodayServlet extends HttpServlet { public void doGet( HttpServletRequest request, HttpServletResponse response ) throws IOException, ServletException { response.setContentType( "text/HTML" ); response.setHeader( "Pragma", "no cache" ); response.setHeader( "Cache-Control", "no cache" ); response.setHeader( "Expires", "0" ); PrintWriter out = response.getWriter(); out.println( "<HTML>" ); out.println( "<head>" ); out.println( "<title>Today</title>" ); out.println( "</head>" ); out.println( "<body>" ); out.println("<h1>The current date and Time is:</h1>" ); Date today = new Date(); out.println( "<p>" + today + "</p>" ); out.flush(); out.println( "</body>" ); out.println( "</HTML>" ); } }

  11. Java Servlets (continued) 2 Other Servers http://../servlet/.. 1 3 4 6 Servlet Engine Browser DBMS 5 Web Server • Client issues http request • Web server sends request to servlet engine • Servlet engine can call other objects • Servlet engine can also connect to DBMS and/or other servers • Servlet engine runs Java program and generates (HTML) output • Web server redirects output to browser

  12. JSP – Java Server Pages • A JSP is (like an ASP) an HTML document with embedded Java Code • Easier to write HTML code (with several standard editors) than Java Servlet code to write the output to browser • Separation of HTML and Java code allows specialists to work on each • Separates presentation (HTML) from processing logic (Java) <html> <head> <META NAME="Pragma" CONTENT="no-cache"> <META NAME="Cache-Control" CONTENT="no-cache"> <META NAME="Expires" CONTENT="0"> <title>Today</title> </head> <%@ page import="java.util.*" %> <body > <H1> The current date and time is:</h1> <p> <%= new Date( ) %> </p> </body> </html>

  13. JSP - continued 2 http://../servlet/.. 4 Redirect 1 HTML / JSP pages 3 Page Compile Servlet Engine Browser 5 6 Web Server • Browser brings up URL • GET or POST method is part of HTTP Request • Input from form is processed, along with database and other requests • All this information from Form (http request) is Redirected to JSP page • The Page compile process converts the JSP into a servlet. Servlet is run by JSP engine • Web Server redirects the HTML page output generated by JSP-generated servlet to browser

  14. JavaBeans & Enterprise JavaBeans (EJB) • The Bean concept is similar to the COM concept and EJB to DCM • A Java Bean is a reusable software component that can be visually manipulated in builder tools. • Beans can be purchased for Java from 3rd parties. • Primary purpose of beans is to enable the visual construction of Java applications. • EJB are server-side software components in distributed environments within containers

  15. Characteristics & Disadvantages of Server-side Scripting ASP • Very basic development process • HTML and Server-side script • No compiling — it is interpreted • Easy exception handling — On Error ResumeNext • Simple languages - VBScript or Jscript(ECMA JavaScript)) • Fairly sophisticated capabilities • Supports/Rewards use of COM objects • Transactioining possible Bad points • ASP functionality is limited (lightweight object model) • Script and content unavoidably intermixed • Session(user) state problematic at best • No sophisticated error handling • Configuration and deployment is difficult

  16. A “Compiled ASP” = ASP.NET Figure 1-3 Compiling the ASP.NET page and the code behind the page into the Page class

  17. Why DotNet? • Changes to counteract Java and provide same features: • Platform Independence (CLR and MSIL vs. JRE and Java bytecode) • Improved Resuability through Base Classes (New Base Classes) • Changes to improve VB in relation to Java (VB.NET) • Consistent Object Orientation • Changes to accommodate Multiple Languages • C#, VB.NET, etc. • Changes to improve functionality and performance • ASP.NET (Compilation and Caching) • Changes to address weaknesses in development, debugging and deployment • XCOPY • Visual Studio.NET • Changes to accommodate XML throughout • ADO.NET • Web Services

  18. The .NET Framework Figure 1-10 The .NET Framework

  19. The .NET Framework • ASP.NET is used to develop dynamic Web applications within the .NET Framework • The .NET Framework consists of: • A Common Language Runtime (CLR) • A hierarchical set of Base Class Libraries (BCL) • The .NET Framework is the architectural model for creating programs that interface with the operating system and the base class libraries

  20. Changes to counteract Java and provide same features • Java has the Java Virtual Machine which can run bytecode and is therefore (hardware/software) platform independent (.NET’s answer is CLR). CLR will be able to convert multiple languages (C#, VB.NET, C++, Java, even COBOL!) into and (interpreted) Microsoft Intermediate Language (MSIL) similar to bytecode, which can then be JIT compiled into native code of the machine. The compiler calls CLR routines directly to do this. JVM can JIT compile Java bytecode into native code.Java uses JRE (Java Runtime Environment) to convert bytecode to machine code. In the case of DotNET, multiple runtime hosts can use CLR such as ASP.NET, IE, Windows Shell, VBA and WinForms designer • The transition from C and C++ to Java is relatively straightforward – (the .NET platform includes support for C# called “Csharp” to encourage C++ users to use .NET) • The transition from regular Java programs to applets and servlets is relatively smooth, whereas the transition from VB to COM and ActiveX is not. Also, involves the problems of needing access to server for registering and the “DLL Hell” problem – (.NET answer is to introduce VB.NET with true object-oriented features such as inheritance, overloading and polymorphism) • Does not have a set of standard class libraries that Java has – (.NET classes are being standardized)

  21. The Base Class Libraries • The base class libraries are commonly used code providing general functions that can be accessed from any application • Libraries contain fundamental code structures and methods that allow you to communicate with the operating system software and other applications • By storing commonly used code in libraries, the code can be reused across applications • The actual library of code is located in one or more dynamic link library files • For example, the code for accessing a database object is stored in the Database class library, located in the file called System.Data.dll

  22. Namespace • The base class libraries are organized into logical groupings of code called namespaces • A namespace is a hierarchical way to identify resources in .NET • The System object is at the top of the namespace hierarchy, and all objects inherit from it • ASP.NET: System.Web namespace • WebForms: System.Web.UI namespace • HTML Server Controls: System.Web.UI.Control.HTMLControl • ASP.NET Server Controls: System.Web.UI.Control.WebControl

  23. Namespace Description Example Classes System Contains all the basic types used by every app. Object, Buffer, Byte, Char, Array, Int32, Exception, GC, String System Collections Contains types for managing collections of objects ArrayList, BitArray, Dictionary, Hashtable, Queue, SortedList, Stack System Data Contains basic database management types DataBinding, DataRelation, DataRow, DataSet, DataTable,DataSource System Globalization Contains types for National Language Support (NLS), String compares, and Calendars Calendar, CultureInfo, JulianCalendar, NumberFormatInfo, NumberStyles, RegionInfo System IO Contains types that allow synchronous and asynchronous reading and writing to data streams ByteStream, File, FileStream, MemoryStream, Path, StreamReader, StreamWriter .NET Base Class Library

  24. System.Net Contains types that allow for network comm WebRequest, WebResponse, TcpClient, TcpListener, UdpClient, Sockets System Reflection Contains types that allow the inspection of metadata Assembly, ConstructorInfo, FieldInfo, MemberInfo, MethodInfo, Module, ParameterInfo System Runtime.Remoting Contains types that allow for managed remote objects ChannelServices, RemotingServices, IMessage, IMessageSink System Security Contains types that enable security features Permissions, Policy, Principal, Util, Cryptography System Web.UI.WebControls Contains types that enable rich user interface controls for Web-based applications AdRotator, BorderStyle, DataGrid, HyperLink, ListBox, Panel, RadioButton, Table System WinForms Contains types that enable rich user interface controls for desktop applications Button, CheckBox, DataGrid, FileDialog, Form, ListBox, MainMenu, MonthCalendar, NewFontDialog, RichEdit, ToolBarTreeView .NET Base Classes (continued)

  25. Importing Namespaces • Visual Studio .NET adds references to your projects’ commonly used namespaces by default • You can import the namespaces into your page using the @Import directive • The following is the syntax for importing a .NET namespace <%@ Import NamespaceName %> • Below is a sample of how you would import the ASP.NET Page class <%@ Imports System.Web.UI.Page %>

  26. The .NET Framework Framework Services VB C++ C# JScript … Visual Studio.NET Common Type Specification 4.ASP.NET: Web Services and Web Forms WindowsForms 3. ADO.NET: Data and XML 2. Base Class Library 1. Common Language Runtime

  27. Common Language Runtime • Visual Studio .NET and the Common Language Runtime are language independent • Language independence is achieved via the use of the Common Language Runtime (CLR) • The CLR supports new features such as a Common Type System (CTS), Garbage Collection (GC), and an Intermediate Language (IL) • The Common Type System (CTS) requires that all applications built within .NET, including ASP.NET applications, support the same basic data types • Examples of data types are strings and integers • These common data types are derived from the System namespace

  28. Common Language Runtime • The compiled code is transformed into an intermediate language called the Microsoft Intermediate Language (MSIL or IL) • An integer in Visual Basic .NET or an int in C# are converted to the same .NET data type, which is Int32 • The IL that is created is the same for all languages • The assembly is the compiled .NET program • The assembly contains the IL along with additional information called metadata • Metadata contains information about the assembly • Use the IL Disassembler (ildasm.exe) to view the IL within an assembly

  29. Changes to accommodate Multiple LanguagesCommon Language RuntimeExecution Model Source code VB C# C++ Unmanaged Component Compiler Compiler Compiler Managed code Assembly MSIL Code Assembly MSIL Code Assembly MSIL Code Common Language Runtime JIT Compiler Native Code Operating System Services

  30. ParcelTracker.DLL Metadata MSIL (Intermediate Lang.) Managed code Resources Compiler csc.exe or vbc.exe only convert to MSIL Common Language RuntimeCompilation Assembly DLL or EXE C++, C#, VB or any .NET language Source Code An assembly is a group of resources and types, along with metadata about those resources and types, that is deployed as a unit. The Programmable Web Web Services Provides Building Blocks for the Microsoft .NET Framework

  31. Metadata in an Assembly • Type Information • Automatically bound into assembly • Inseparable • Stored in binary format • Describes every class type • Used by VS.NET IntelliSense™ Type Descriptions Classes Base classes Implemented interfaces Data members Methods Assembly Description Name Version Culture Other assemblies Security Permissions Exported Types

  32. Viewing the Assembly • Create a simple class, compile the class into an assembly, then view the class using the IL Disassembler • Open Notepad and type the code shown: ' hello.vb - displays hello world ' Created 06/01/2002 Imports System Public Module Hello Sub Main() Dim s1 As String = "1 - Hello World" Console.WriteLine(s1) End Sub End Module ' Run this at the command line ' vbc hello.vb

  33. Using the ILDASM to View the Assembly and Classes Figure 1-13 Using the ILDASM to view the assembly and classes

  34. Compiling a Program • Save the file as "hello.vb" in your c:\Inetpub\wwwroot directory • Open the .NET Command Prompt • Change to your c:\Inetpub\wwwroot using the cd c:\Inetpub\wwwroot command • Type vbc hello.vb and press Enter key. This compiles your program into an executable file named hello.exe in the same folder • Type hello at the command prompt and hit the Enter Key. The program runs and displays the hello world string • Type ILDASM hello.exe. View the compiled assembly using the IL Disassembler

  35. Garbage Collection • Programs that don’t release references to objects cause memory leaks • Memory leaks occur when memory is no longer being used by the application, but cannot be reassigned to another object • In .NET, the Common Language Runtime uses the garbage collector to manage memory • The Garbage Collection (GC) process is the process of allocating and managing the reserved memory • Because of the garbage collection process, .NET applications have fewer problems with memory leaks and circular references than current Windows applications

  36. Common Language Runtime - Goals • Cross-language integration, - Enable deep multi-language integration - Code written in one language can now inherit implementation from classes written in another language; • Self-describing components – Metadata packed with executable (called assemblies) means that different applications may use different versions of an assembly • Easier software updates • Easier software removal • Simple Deployment and Versioning - Because assemblies are self-describing, no explicit registration with the operating system is required. Application deployment can be as simple as copying files to a directory tree. • Removal on registration dependency • Safety – fewer versioning problems • THE END of ‘DLL Hell’ • Integrated security services - Since the runtime is used to load code, create objects, and make method calls, the runtime can perform security checks and enforce security policy as managed code is loaded and executed • code access security, developers can specify the required permissions their code needs to accomplish work e.g., permission to write a file or access environment variables. Information stored in assembly level, along identity of the code • Role-based security - permissions based on user identity - runtime determines what roles the user is a member of and then grants permissions based on those roles.

  37. Caching Support • ASP.NET provides built-in caching support that enables re-use of work • Cache Engine: Extensible Cache API • Enables arbitrary objects to be cached • Full Page Caching • Vary by params, language, user-agent (browser) • Partial Page Caching • Enables portions of pages to be cached • Web Service Caching • Vary by parameters and methods

  38. Changes to address weaknesses debugging and deployment - Debugging using TRACE • Page and Application tracing • Easy to include “debug” statements • Add trace directive at top of page - <%@ Page Trace=“True” %> • Add trace calls throughout page • Trace.Write(“MyApp”, “Button Clicked”) • Trace.Warn(“MyApp”, “Value: “ + value) • Collect request details • Server control tree • Server variables, headers, cookies • Form/Querystring parameters • Access page from browser • Access tracing URL within app • http://localhost/approot/Trace.axd

  39. Changes to address weaknesses debugging and deployment - Deployment using XCOPY • ASP.NET enables a web app to be deployed simply by copying its bits to the server - \bin directory registration • Deployment for components: • xcopy/ftp to an application’s “\bin” dir • No registration required (no more regsvr32) • Web apps are isolated from each other • Components can be private to application • Other apps cannot load private components • Other apps can use different component versions • Uninstall ?— just delete directory • No-nonsense architecture • No local server access required • No web server restarts required • Works for all web app resources • Web Pages/ Web Services • Compiled Components • Configuration Metadata

More Related