A Roadmap to.NET Ajdan Jumerefendi COMPSCI 109 September 19, 2003
Agenda Overview of.NET Data Access using ADO.NET ASP.NET Web Forms Web Services Web Applications Development Tools
.Introduction From Microsoft.NET Microsoft software for connecting information, people, systems, and devices..NET provides XML-based interoperability and is being incorporated across Microsoft's clients, servers, services, and tools. For example, products like Microsoft Windows® and Microsoft Office will use.NET to connect with other systems and applications. For developers,.NET is manifested in the programming model delivered in the Microsoft.NET Framework. Microsoft.NET Framework An integral Windows component that enables building and running the next generation of software applications and Web services. It includes technologies for Web services and Web applications (ASP.NET), data access (ADO.NET), smart client applications (Windows Forms), and many others.
.NET Blueprint Open Internet Protocols SOAP, SCL, DISCO HTTP, SMTP, XML, WAP, XSD HTTP, SMTP, XML, WAP, XSD Your Application and Web Service.NET Framework Windows CE, ME, 2000,.NET Operations End-User Clients Other Applications Using Your Service Orchestration Your Internal Services.NET Enterprise Servers.NET MyServices Public Web Services Visual Studio.NET
Inside the.NET Framework Common Language Runtime Base Framework Data and XML Web ServicesUser Interface VBC++C# ASP.NET PerlEiffelCobol Active Server Pages.NET High-productivity environment for building and running Web services Secure, integrated class libraries Unifies programming models across languages Enables cross-language integration Factored for extensibility Designed for tools Common Language Runtime Executes code, maintains security, handles component “plumbing” and dependencies
An Alphabet Soup CLR – Common Language Runtime CTS – Common Type System (C)IL – (Common) Intermediate Language also known as: MIL – Microsoft Intermediate Language CLS – Common Language Specification GC – Garbage Collector
Common Language Runtime Frameworks Class loader and layout IL to native code compilers GC, stack walk, code manager Security Execution Support Base Classes Dramatically simplify application devel opment Provide a robust and secure execution environment Support multiple programming lan guages Simplify deployment and management
Common Type System Static (compile time) typed Object-Oriented fields, methods, nested types, properties, etc. Object Based – everything is an object Independent of the underlying physical platform Key feature when addressing program platform independence
Managed and Unmanaged Code Managed Code – code compiled to IL Safe Type-checked Bound-checked No need to worry about memory management – Garbage collection. No more pointers and segmentation faults (Actually, everything is a pointer but a safe one) Platform Independent Unmanaged Code – native code .Net makes it possible to integrate both.
.NET Languages The.NET Platform is Language Neutral All.NET languages perform the same You can leverage your existing skills Microsoft provides: VB, C++, C#, JScript Third-parties are building APL, COBOL, Pascal, Eiffel, Haskell, ML, Oberon, Perl, Python, Scheme, Smalltalk
Base Classes Hierarchically organized into namespaces Namespace is just a unit of logical/physical organization Base namespace : System .NET comes with a large set of base classes implementing IO, Graphics, Networking, Data Access, Security, etc. A very rich set of classes that can support projects of significant complexity
Other Interesting Topics Assemblies Metadata Execution Model Interoperability Common Language Specification
Agenda Overview of.NET Data Access using ADO.NET ASP.NET Web Forms Web Services Web Applications Development Tools
Why do we Need to Access Data Data access is the heart of any real-world application Services are dynamic Require large amounts of data to be filtered and processed Generate data during its process of execution Provide various functionalities based on the accumulated data
Data Access Architecture A Data Source (DS) stores, organizes and manages data Client (C) establishes a connection with the DS C accesses DS using SQL DS processes request and returns result On the Windows Platform, the preferred and most often used DS is Microsoft SQL Server. Its current version is Data Source Client SELECT * FROM PRODUCTS WHERE PRD_ID =
Basic Classes .Net framework provides ready classes for accessing a variety of data sources Namespaces: System.Data (general data access classes) System.Data.SqlClient (MSSQL specific classes) Most important classes: SqlConnection SqlCommand SqlDataReader SqlDataAdapter DataSet DataTable
Establishing and Terminating a Connection Create an instance of the SqlConnection object Call its Open method. Execute a request Close the connection when done Topics not covered: Connection String, Connection Pooling SqlConnection myConnection = new SqlConnection("server=(local)\NetSDK;database=pubs;Trusted_Connection=yes"); myConnection.Open(); …. Do Something … myConnection.Close();
Issuing Commands Create an instance of SqlCommand, specifying the SQL command text and the connection to be used Execute the command and store the result Many other possible ways to execute a command Parameters Different result types SqlConnection myConnection = new SqlConnection("server=(local)\NetSDK;database=pubs;Trusted_Connection=yes"); SqlCommand myCommand = new SqlCommand("select * from Authors", myConnection); myConnection.Open(); DataSet ds = new DataSet(); myCommand.Fill(ds, "Authors"); myConnection.Close();
Storing Retrieved Data Different ways to retrieve and store data Depend on data type and application needs Most versatile class: DataSet Other useful classes: SqlDataReader SqlDataAdapter
Recommended Practice Stored Procedures SQL code stored directly in the database server Compiled, optimized, faster Elegant encapsulation and isolation of code Example: Creating the Stored Procedure CREATE Procedure GetAuthors AS SELECT * FROM Authors
Invoking a Stored Procedure // create the command command = new SqlCommand(); // attach the stored procedure name command.CommandText = “GetAuthors”; // set the type to: StoredProcedure command.CommandType = CommandType.StoredProcedure; // attach the connection command.Connection = myConnection; // open the connection myConnection.Open(); // create a DataSet object DataSet ds = new DataSet(); // Execute the command and fill the DataSet myCommand.Fill(ds, "Authors"); // Close the connection myConnection.Close();
Agenda Overview of.NET Data Access using ADO.NET ASP.NET Web Forms Web Service Web Applications Web Services
What is it All About? A programming framework built on the common language runtime that can be used on a server to build powerful Web applications Enhanced Performance Powerful Simple Secure Provides for rapid development Manageable Makes web programming “REAL” programming. Supports different types of clients
Today’s Environment
The Ingredients of ASP.NET Web Forms Server Controls Web Services Web Applications
Request and Response Objects Request Object – provides access to the client’s request: Request parameters Type of browser, operating system, ip, etc., Cookies string name = (string)Request.QueryString[“name”]; Response Object – used to generate the response for the client: Response.Write(“Hello World”)
Agenda Overview of.NET Data Access using ADO.NET ASP.NET Web Forms Web Service Web Applications Development Tools
Web Forms A scalable common language runtime programming model that can be used on the server to dynamically generate Web pages Automate the management of a page’s state across different round trips to the server. Simple, fast, and elegant mechanism to generate dynamic content
A Basic Form Name: Category: psychology business popular_comp
Beginning Scripting Name: Category: psychology business popular_comp "> Welcome to ASP.NET
Server Controls While we can do all just by using, by using this method we: Have no clean programming style Have to manually manage state across requests Can use Server controls instead: Just like regular HTML tags with a small difference: runat=“server”
ASP.NET Web Form Name: Category: psychology business popular_comp
Event Handling Source Code Source Code End Result End Result
Lists, Data and Data Binding Data Binding – associating a data source with a control Intoduction and Examples Intoduction and Examples DataGrid DataList Repeater
Server Controls ASP.NET comes with a set of 45 standard server controls. Cover most HTML elements and operations ASP.NET makes it possible to develop custom controls, known also as user controls Introduction to User Controls Introduction to User Controls
Code-Behind Web Forms ASP.NET supports two methods of authoring dynamic pages. page code is physically declared within the originating.aspx file. An alternative approach--known as the code-behind method--enables the page code to be more cleanly separated from the HTML content into an entirely separate file. Example: Code ResultCodeResult
Agenda Overview of.NET Data Access using ADO.NET ASP.NET Web Forms Web Services Web Applications Development Tools
Introduction WWW is evolving very quickly Static Pages Somewhat Dynamic Pages Latest: Programmable Web Sites Provide programming access to different functionalities exported by the web sites Turn the web site into a service – an entitity perfoming something on demand XML Web Services – define mechanisms, standards and protocols to expose and access functionality Services specify what they offer Clients find this information and execute requests Based on XML – powerful and extensible mechanism to define and organize data Curent Web Services Protocols and Languages: WSDL – Web Service Definition Language SOAP – Simple Object Access Protocol
Basic Constructs The.NET framework provides a namespace System.Web.Services with classes to be used for the construction of xml web services Most important class: System.Web.Services.WebService To create a web service – inherit the above class, write some methods to be exposed and prefix them with [WebMethod]. Tell your clients where they can find the service.
A Simple Web Service using System; using System.Web.Services; public class HelloWorld : WebService { [WebMethod] public String SayHelloWorld() { return "Hello World"; }
Another Example Simple Calculator Service Simple Calculator Service Consuming the Service Consuming the Service
Agenda Overview of.NET Data Access using ADO.NET ASP.NET Web Forms Web Services Web Applications Development Tools
Overview ASP.NET Framework applications consist of everything under one virtual directory of the Web server Application is created by simply adding a file to the virtual directory Can define custom handling of various events: Init Start End
Managing State Two ways: Using the application Using the Session object Application Data that is infrequently modified but read often (global data) Session Data specific to a user session or request
Agenda Overview of.NET Data Access using ADO.NET ASP.NET Web Forms Web Services Web Applications Development Tools
Visual Studio.NET All-in-One Integrated Development Environment Write Code, Debug, Execute Access Databases, Remote servers Rich, Detailed Help System.
Resources ASP.NET Quickstart Tutorials .NET Howto-s ASP.NET official community web site Microsoft official.NET web site C# Resources MSDN us/dnanchor/html/netdevanchor.asp?frame=true us/dnanchor/html/netdevanchor.asp?frame=true