Introduction to the Weband .NET
This material is based on the original slides of Dr. Mark Sapossnek, Computer Science Department, Boston University, Mosh Teitelbaum, evoch, LLC, and Joe Hummel, Lake Forest College
Outline
Internet Technologies
Programming Web & Distributed Applications
.NET Overview
Internet Technologies The World Wide Web
A way to access and share informationTechnical papers, marketing materials, recipes, ...
A huge network of computers: the InternetGraphical, not just textualInformation is linked to other informationApplication development platform
Shop from homeProvide self-help applications for customers and partners...
Internet TechnologiesWWW Architecture
Web Server
PC/Mac/Unix + Browser
Client
Server
Request:http://www.msn.com/default.asp
Response:<html>…</html>
Network TCP/IP
Internet TechnologiesWWW Architecture
Client/Server, Request/Response architectureYou request a Web page
e.g. http://www.msn.com/default.asp
HTTP request
The Web server responds with data in the form of a Web pageHTTP response
Web page is expressed as HTML
Pages are identified as a Uniform Resource Locator (URL)Protocol: http
Web server: www.msn.com
Web page: default.asp
Can also provide parameters: ?name=Keith
Internet TechnologiesWeb Standards
Internet Engineering Task Force (IETF)http://www.ietf.org/
Founded 1986
Request For Comments (RFC) at http://www.ietf.org/rfc.html
World Wide Web Consortium (W3C)http://www.w3.org
Founded 1994 by Tim Berners-Lee
Publishes technical reports and recommendations
Internet TechnologiesHypertext Markup Language (HTML)
The markup language used to represent Web pages for viewing by people
Designed to display data, not store/transfer data
Rendered and viewed in a Web browserCan contain links to images, documents, and other pagesNot extensibleDerived from Standard Generalized Markup Language (SGML)HTML 3.2, 4.01, XHTML 1.0
Internet TechnologiesHTML Forms
Enables you to create interactive user interface elements
Buttons
Text boxes
Drop down lists
Check boxes
User fills out the form and submits it
Form data is sent to the Web server via HTTP when the form is submitted
Internet TechnologiesHypertext Transport Protocol (HTTP)
The top-level protocol used to request and return data
E.g. HTML pages, GIFs, JPEGs, Microsoft Word documents, Adobe PDF documents, etc.
Request/Response protocol
Methods: GET, POST, …
HTTP 1.0: simple
HTTP 1.1: more complex
GET /default.asp HTTP/1.0Accept: image/gif, image/x-bitmap, image/jpeg, */*Accept-Language: enUser-Agent: Mozilla/1.22 (compatible; MSIE 2.0; Windows 95)Connection: Keep-AliveIf-Modified-Since: Sunday, 17-Apr-96 04:32:58 GMT
Internet TechnologiesHTTP Request
Method File HTTP version Headers
Data – none for GET
Blank line
HTTP/1.0 200 OKDate: Sun, 21 Apr 1996 02:20:42 GMTServer: Microsoft-Internet-Information-Server/5.0 Connection: keep-aliveContent-Type: text/htmlLast-Modified: Thu, 18 Apr 1996 17:39:05 GMTContent-Length: 2543
<HTML> Some data... blah, blah, blah </HTML>
Internet TechnologiesHTTP Response
HTTP version Status code Reason phrase Headers
Data
Internet TechnologiesHTTP Server Status Codes
DescriptionCode
Internal Server Error500
Not Found404
Forbidden – not authorized403
Unauthorized401
Bad Request – not understood400
Moved Temporarily302
Moved Permanently301
Created201
OK200
Internet TechnologiesHTTP
HTTP is a stateless protocol
Each HTTP request is independent of previous and subsequent requests
Statelessness has a big impact on how scalable applications are designed
Internet TechnologiesCookies
A mechanism to store a small amount of information (up to 4KB) on the client
A cookie is associated with a specific web site
Cookie is sent in HTTP header
Cookie is sent with each HTTP request
Can last for only one session (until browser is closed) or can persist across sessions
Can expire some time in the future
Internet TechnologiesHTTPS
A secure version of HTTP
Allows client and server to exchange data with confidence that the data was neither modified nor intercepted
Uses Secure Sockets Layer (SSL)/Transport Layer Security (TLS)
Internet TechnologiesURIs, URLs and URNs
Uniform Resource Identifier (URI = URL or URN)Generic term for all textual names/addresses
Uniform Resource Locator (URL)The set of URI schemes that have explicit instructions on how to access the resource over the Internet, e.g. http, ftp, gopher
Uniform Resource Name (URN) 1) A URI that has an institutional commitment to
availability, etc.2) A particular scheme intended to identify resources
e.g. urn:schemas:httpmail:subject
Internet TechnologiesMultipurpose Internet Mail Extensions (MIME)
Defines types of data/documentstext/plain
text/html
image/gif
image/jpeg
audio/x-pn-realaudio
audio/x-ms-wma
video/x-ms-asf
application/octet-stream
Internet TechnologiesMIME
Specifies character sets, e.g. ASCII
Supports multi-part messages
Originally designed for email, but also used in other places, such as HTTP
Internet TechnologiesNetworks - Application Layer
Telnet: Remote sessions
File Transfer Protocol (FTP)
Network News Transfer Protocol (NNTP)
Simple Network Management Protocol (SNMP)
Simple Mail Transfer Protocol (SMTP)
Post Office Protocol (POP3)
Interactive Mail Access Protocol (IMAP)
Internet TechnologiesExtensible Markup Language (XML)
Represents hierarchical data
A meta-language: a language for defining other languages
Extensible
Useful for data exchange and transformation
Simplified version of SGML
Outline
Internet Technologies
Programming the Web
.NET Overview
Programming the WebClient-Side Code
What is client-side code?Software that is downloaded from Web server to browser and then executes on the client
Why client-side code?Better scalability: less work done on serverBetter performance/user experienceCreate UI constructs not inherent in HTML
Drop-down and pull-out menusTabbed dialogs
Cool effects, e.g. animationData validation
DHTML• DHTML = Dynamic HTML
It allows you to build rich client interfaces and to modifythem dynamically
• There is no DHTML standardIt is not a W3C, IEEE, ISO or anything else standard
• DHTML is a collection of several standardsDHTML consists of HTML/XHTML, CSS, DOM andJavaScript (or ECMAScript)
Programming the WebServer-Side Code
What is server-side code?Software that runs on the server, not the client
Receives input fromURL parameters
HTML form data
Cookies
HTTP headers
Can access server-side databases, e-mail servers, files, mainframes, etc.
Dynamically builds a custom HTML response for a client
Programming the WebServer-Side Code
Why server-side code?Accessibility
You can reach the Internet from any browser, any device, any time, anywhere
ManageabilityDoes not require distribution of application codeEasy to change code
SecuritySource code is not exposedOnce user is authenticated, can only allow certain actions
ScalabilityWeb-based 3-tier architecture can scale out
Programming the WebServer-Side Technologies
Common Gateway Interface (CGI)
Internet Server API (ISAPI)
Netscape Server API (NSAPI)
Active Server Pages (ASP)
Java Server Pages (JSP)
Personal Home Page (PHP)
Cold Fusion (CFM)
ASP.NET
Programming the WebServer-Side Programming
HTTP request(form data, HTTP
header data)
HTTP responseHTML, XML
(static HTML, server-side logic)
Outline
Internet Technologies
Programming Languages and Paradigms
Programming the Web
.NET Overview
.NET Overview
Introduction to .NET
Web Services
The .NET Framework
Common Language Runtime
Windows Forms
Web Forms
ADO.NET
Languages
Introduction to .NETWhat is .NET?
A vision of how information technology will evolve
A platform that supports the vision
A business model of software as a service
Introduction to .NETWhat is .NET?
A visionWeb sites will be joined by Web services
New smart devices will join the PC
User interfaces will become more adaptable and customizable
Enabled by Web standards
A platformThe .NET FrameworkVisual Studio.NET.NET Enterprise Servers
Database, Messaging, Integration, Commerce, Proxy, Security, Mobility, Content Management
.NET Web Services as Building BlocksGoal: make it incredibly easy to build powerful Web applications and Web services
Introduction to .NETWhat is .NET?
A business modelSoftware as a service
Subscription-based services
Application hosting, e.g. bCentral
Introduction to .NETWhat is .NET?
Introduction to .NETThe .NET Platform
Web Form
.NET Framework
Windows
Web Service
.NET FoundationWeb Services
Your InternalWeb Service
Third-PartyWeb Services
.NET EnterpriseServers
Clients Applications
Protocols: HTTP,HTML, XML, SOAP, UDDI
Tools:Visual Studio.NET,
Notepad
Web Services
A programmable application component accessible via standard Web protocols
The center of the .NET architecture
Exposes functionality over the Web
Built on existing and emerging standardsHTTP, XML, SOAP, UDDI, WSDL, …
Web ServicesEvolution of the Web
Generation 1Static HTML
HTML
Generation 2Web Applications
HTML
HTML, XML
HTML, XML
Generation 3Web Services
A set of technologies for developing and using components to create:
Web Forms
Web Services
Windows Applications
Supports the software lifecycleDevelopment
Debugging
Deployment
Maintenance
The .NET FrameworkWhat Is the .NET Framework?
Common Language Specification
Common Language Runtime
VB C++ C#
ASP.NET: Web Servicesand Web Forms
JScript …
WindowsForms
.NET Framework Base Classes
ADO.NET: Data and XML
Visu
al Stu
dio
.NE
T
The .NET FrameworkThe .NET Framework and Visual Studio.NET
System.Data
DesignOLEDB
SQLTypesSQL
System
GlobalizationDiagnostics
ConfigurationCollections
ResourcesReflection
NetIO
ThreadingText
ServiceProcessSecurity Runtime
InteropServicesRemotingSerialization
System.Xml
XPathXSLT Serialization
System.Web
Configuration SessionStateCaching Security
ServicesDescriptionDiscoveryProtocols
UIHtmlControls
WebControlsSystem.Drawing
ImagingDrawing2D
TextPrinting
The .NET Framework.NET Framework Classes
System.Windows.FormsForm Button
MessageBox ListControl
Common Language RuntimeGoals
Development servicesDeep cross-language interoperabilityIncreased productivity
Deployment servicesSimple, reliable deploymentFewer versioning problems – NO MORE ‘DLL HELL’
Run-time servicesPerformance Scalability Availability
Reliability
Security
Safety
Source Code
C++, C#, VB or any .NET language
csc.exe or vbc.exe
Compiler
Assembly
DLL or EXE
Common Language RuntimeCompilation
AssemblyLogical unit of deployment
Contains Manifest, Metadata, MSIL and resources
ManifestMetadata about the components in an assembly (version, types, dependencies, etc.)
Type MetadataCompletely describes all types defined in an assembly: properties, methods, arguments, return values, attributes, base classes, …
Common Language RuntimeAssemblies
Common Language RuntimeAssemblies
Microsoft Intermediate Language (MSIL, IL)All languages compile to IL (managed code)
IL is always compiled to native code before being executed
ResourcesE.g. .bmp, .jpg
Common Language RuntimeExecution Model
CLR
VBSource code
Compiler
C++C#
Assembly AssemblyAssembly
Operating System Services
MSIL
Common Language Runtime JIT Compiler
Compiler Compiler
Nativecode
ManagedCode
ManagedCode
ManagedCode
UnmanagedCode
CLR Services
Ngen
Assemblies
1 assembly = 1 or more compiled classes.EXE represents an assembly with classes + Main program
.DLL represents an assembly with classes
Development Tools
assembly
code.vbcode.vb
code.cs
.EXE / .DLL
.NET development
There are currently 3 ways to develop assemblies:
1) .NET Framework SDKfree (100 MB)
complete set of command-line tools and docs
available for Windows NT, 2000, XP Pro, 2003
http://msdn.microsoft.com/net
other platforms?FreeBSD / Mac OS X via Rotor (i.e. SSCLI)
Linux via Mono project
Development options, cont'd
2) Visual Studio .NET5-6 CDs, 192 MB RAM (bare minimum)
powerful, integrated development environment (IDE)
one IDE for all: GUI, web-based, web service, DLLs, etc.
this is what 99% of the world uses
$$MSDNAA reduces cost to $800/year for unlimited access
3) free IDEs#develop, a simplified clone of VS.NET
WebMatrix, for building web-based applications
Hello World in C#
Here's the source code:
/* hello.cs */
public class Startup{
public static void Main(){
System.Console.WriteLine("Hello World!");}
}//class
hello.cs
Why System.Consoleprefix?
In .NET, all code & data must live within a module / class
Often nested within namespaces to help organize thingsa namespace is really just a named collection
Example: System.Console.WriteLine("Hello World!");
Consoleclass
WriteLinesubroutine
Systemnamespace
in FCL
Compiling and running
To compile C# with Framework SDK, use the C# compiler
open Visual Studio .NET command prompt window to set path
csc is the command-line C# compiler
use /t:exe option to specify console-based EXE as target
c:\> csc /t:exe hello.csMicrosoft (R) Visual C# .NET Compiler version 7.00.9466for Microsoft (R) .NET Framework version 1.0.3705Copyright (C) Microsoft Corporation 2001. All rights reserved.
c:\> hello.exeHello World!
Viewing an assembly with ILDasm
IL = Microsoft's Intermediate Language (i.e. generic asm)
ILDasm = IL Disassembler
c:\> ildasm hello.exe
IL?
Very similar to Java bytecodes:generic assembly language
stack-based
strictly typed
no direct memory addressing
verifiable for safe execution
Development on FreeBSD
Working on FreeBSD is exactly the same!i.e. same command-line tools as Framework SDK
produces *binary-compatible* .DLL and .EXE files!
Class-based development: Example
Here's the source code for a simple Customer class:
/* customer.cs */
public class Customer{
public string Name; // fieldspublic int ID;
public Customer(string name, int id) // constructor{this.Name = name;this.ID = id;
}
public override string ToString() // method{return "Customer: " + this.Name;
}}//class
Main class
Here's the source code for Main, using our Customer class:
/* main.cs */
public class App{
public static void Main(){
Customer c;c = new Customer("joe hummel", 94652);System.Console.WriteLine( c.ToString() );
}
}//class
Compiling and running application
Compile and run as before…/out: option specifies name of resulting EXE
in this case we are building monolithic app (single EXE, no DLLs)
c:\> csc /t:exe /out:app.exe main.cs customer.csMicrosoft (R) Visual C# .NET Compiler version 7.00.9466for Microsoft (R) .NET Framework version 1.0.3705Copyright (C) Microsoft Corporation 2001. All rights reserved.
c:\> app.exeCustomer: joe hummel
Component-based development: Example
Let's rebuild previous app based on componentsCustomer class ==> DLL
Main class ==> EXE
app.exe customer.dll+
main.cs customer.cs
Compiling a component
Use the C# compiler…with /t:library option to specify component library as target
csc produces a DLL in this case
c:\> csc /t:library customer.csMicrosoft (R) Visual C# .NET Compiler version 7.00.9466for Microsoft (R) .NET Framework version 1.0.3705Copyright (C) Microsoft Corporation 2001. All rights reserved.
c:\> dir *.dllcustomer.dll
Compiling and running application
Compile using C# compiler as before, except…reference component so compiler can locate Customer class!
reference also stored inside assembly so CLR can locate
To run, use name of assembly containing Main…CLR follows reference to locate DLL
c:\> csc /t:exe /out:app.exe main.cs /r:customer.dllMicrosoft (R) Visual C# .NET Compiler version 7.00.9466for Microsoft (R) .NET Framework version 1.0.3705Copyright (C) Microsoft Corporation 2001. All rights reserved.
c:\> app.exeCustomer: joe hummel
Where are references stored?
Within assembly as part of assembly manifest
Visible via ILDasmc:\> ildasm app.exe
mscorlib?
mscorlib = "ms-core-lib"
Core FCL assemblycontains core system classes like string
contains System.Console class for console-based I/O
Automatically referenced for us by C# compiler…
All assemblies must be present
.EXE
other FCL assemblies
CLR
JIT Compiler
obj code
OS Process
Underlying OS and HW
Core FCLassembly
.DLL.DLL
.DLL
obj codeobj code
obj code