Programming the Web

Download Report

Transcript Programming the Web

Introduction to the Web
and .NET
Mark Sapossnek
CS 594
Computer Science Department
Metropolitan College
Boston University
Prerequisites
 Basic computer skills
 Experience using the World Wide Web
 Experience developing object-oriented software
Learning Objectives
 Overview of Web and Internet technologies
 Review of existing Web programming
technologies
 Introduction to the .NET development platform
Agenda




Internet Technologies
Programming Languages and Paradigms
Programming the Web
.NET Overview
Internet Technologies
The World Wide Web
 A way to access and share information





Technical papers, marketing materials, recipes, ...
A huge network of computers: the Internet
Graphical, not just textual
Information is linked to other information
Application development platform



Shop from home
Provide self-help applications for customers and
partners
...
Internet Technologies
WWW Architecture
PC/Mac/Unix
+ Browser
Client
Request:
http://www.msn.com/default.asp
Network
TCP/IP
Response:
<html>…</html>
Server
Web Server
Internet Technologies
WWW Architecture
 Client/Server, Request/Response architecture

You request a Web page



The Web server responds with data in the form of a Web page



e.g. http://www.msn.com/default.asp
HTTP request
HTTP 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=Leon
Internet Technologies
Web 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 Technologies
Web Design Principles
 Interoperability: Web languages and protocols
must be compatible with one another
independent of hardware and software.
 Evolution: The Web must be able to
accommodate future technologies. Encourages
simplicity, modularity and extensibility.
 Decentralization: Facilitates scalability and
robustness.
Internet Technologies
Hypertext 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 browser
 Can contain links to images, documents,
and other pages
 Not extensible
 Derived from Standard Generalized Markup
Language (SGML)
 HTML 3.2, 4.01, XHTML 1.0
Internet Technologies
HTML 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 Technologies
Hypertext 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, HEAD, …
HTTP 1.0: simple
HTTP 1.1: more complex
Internet Technologies
HTTP Request
Method
File
HTTP version
Headers
GET /default.asp HTTP/1.0
Accept: image/gif, image/x-bitmap, image/jpeg, */*
Accept-Language: en
User-Agent: Mozilla/1.22 (compatible; MSIE 2.0; Windows 95)
Connection: Keep-Alive
If-Modified-Since: Sunday, 17-Apr-96 04:32:58 GMT
Blank line
Data – none for GET
Internet Technologies
HTTP Response
HTTP version
Status code
Reason phrase
Headers
HTTP/1.0 200 OK
Date: Sun, 21 Apr 1996 02:20:42 GMT
Server: Microsoft-Internet-Information-Server/5.0
Connection: keep-alive
Content-Type: text/html
Last-Modified: Thu, 18 Apr 1996 17:39:05 GMT
Content-Length: 2543
<HTML> Some data... blah, blah, blah </HTML>
Data
Internet Technologies
HTTP Server Status Codes
Code
Description
200
OK
201
Created
301
Moved Permanently
302
Moved Temporarily
400
Bad Request – not understood
401
Unauthorized
403
Forbidden – not authorized
404
Not Found
500
Internal Server Error
Internet Technologies
HTTP
 HTTP is a stateless protocol
 Each HTTP request is independent of previous
and subsequent requests
 HTTP 1.1 introduced keep-alive for efficiency
 Statelessness has a big impact on how scalable
applications are designed
Internet Technologies
Cookies
 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 Technologies
HTTPS
 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 Technologies
URIs, 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 Technologies
Multipurpose Internet Mail Extensions (MIME)
 Defines types of data/documents








text/plain
text/html
image/gif
image/jpeg
audio/x-pn-realaudio
audio/x-ms-wma
video/x-ms-asf
application/octet-stream
Internet Technologies
MIME
 Specifies character sets, e.g. ASCII
 Supports multi-part messages
 Originally designed for email, but also used in
other places, such as HTTP
Internet Technologies
Browsers
 Client-side application
 Requests HTML from Web server and renders it
 Popular browsers:




Netscape
Internet Explorer
Opera
others
 Also known as a User Agent
Internet Technologies
Clients & Servers
 Client and Server computers both have:



CPU
Memory
I/O





Disks
Network
Bus
Multi-tasking operating system
Applications
Internet Technologies
Clients & Servers
 Clients



Generally supports a single user
Optimized for responsiveness to user
User interface, graphics
 Servers




Supports multiple users
Optimized for throughput
More: CPUs (SMP), memory, disks (SANs), I/O
Provide services (e.g. Web, file, print, database,
e-mail, fax, transaction, telnet, directory)
Internet Technologies
Proxy Servers & Firewalls
 Proxy Server



A server that sits between a client (running a browser)
and the Internet
Improves performance by caching commonly used
Web pages
Can filter requests to prevent users from accessing
certain Web sites
 Firewall

A server that sits between a network and the Internet
to prevent unauthorized access to the network from
the Internet
Internet Technologies
Networks
 Network = an interconnected collection of
independent computers
 Why have networks?




Resource sharing
Reliability
Cost savings
Communication
 Web technologies add:



New business models: e-commerce, advertising
Entertainment
Applications without a client-side install
Internet Technologies
Networks
 Network scope




internet: a collection of connected networks
Internet: a specific world-wide network based on
TCP/IP, used to connect companies, universities,
governments, organizations and individuals.
Originated as ARPANET, funded by the US DoD.
intranet: a network based on Internet technologies
that is internal to a company or organization
extranet: a network based on Internet technologies
that connects one company or organization to another
Internet Technologies
Networks
 Network technology is largely determined
by scale:


Local Area Network (LAN): Span up to a few
kilometers. Bus vs. ring topologies
Wide Area Networks (WAN): Can span a country or
continent. WANs use routers as intermediate nodes
to connect transmission lines
Internet Technologies
Networks
 Network technology

Broadcasting



Point-to-point


Packets of data are sent from one machine and received by
all computers on the network
Multicast: packets are received by a subset of the machines
on a network
Packets have to be routed from one machine to another;
there many be many paths
In general, geographically localized networks use
broadcasting, while disperse networks use
point-to-point
Internet Technologies
Networks
OSI Model
Layers
Application
Layer
Presentation
Layer
Session
Layer
Transport
Layer
Network
Layer
Data Link
Layer
Physical
Layer
TCP/IP
Protocol
Architecture
Layers
Application
Layer
TCP/IP
Protocol Suite
Telnet
FTP
Host-to-Host
Transport
Layer
SMTP
DNS
RIP
TCP
Internet
Layer
ARP
Network
Interface
Layer
Ethernet
SNMP
HTTP
UDP
IGMP
IP
Token
Ring
Frame
Relay
ICMP
ATM
Internet Technologies
Network Protocol Stack
HTTP
HTTP
TCP
TCP
IP
IP
Ethernet
Ethernet
Internet Technologies
Networks - Internet Layer
 Internet Protocol (IP)
 Responsible for getting packets from source to
destination across multiple hops
 Not reliable
 IP address: 32 bit value usually written in dotted
decimal notation as four 8-bit numbers
(0 to 255); e.g. 130.50.12.4
Internet Technologies
Networks - Transport Layer
 Provides efficient, reliable and
cost-effective service
 Uses the Sockets programming model
 Ports identify application

Well-known ports identify standard services
(e.g. HTTP uses port 80, SMTP uses port 25)
 Transmission Control Protocol (TCP)

Provides reliable, connection-oriented byte stream
 UDP

Connectionless, unreliable
Internet Technologies
Networks - 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 Technologies
Networks - Domain Name System (DNS)
 Provides user-friendly domain names,
e.g. www.msn.com
 Hierarchical name space with limited root names




.com
.net
.gov
.edu




.org
.mil
.jp
.de
 DNS servers map domain names to
IP addresses
Internet Technologies
Extensible 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
Agenda




Internet Technologies
Programming Languages and Paradigms
Programming the Web
.NET Overview
Programming Languages
 Machine code
 Assembly language
 High-level languages




Fortran, LISP, Cobol
C, Pascal, Basic, Smalltalk
C++, Eiffel
Java, C#
 Scripting languages

Shell scripts, Perl, TCL, Python, JavaScript, VBScript
Programming Paradigms





Unstructured programming
Structured programming
Object-oriented programming
Component-based programming
Event-based programming
Programming Paradigms
Unstructured Programming
 See “Go To Statement Considered Harmful” at
http://www.acm.org/classics/oct95/
Programming Paradigms
Structured Programming
 Sequence
 Conditional


if then else
switch
 Looping



for i from 1 to n
do while
do until
 Functions
 Exceptions
Programming Paradigms
Object-Oriented Programming
 Objects have data and behavior


Data: members, fields, variables, slots, properties
Behavior: methods, functions, procedures
 Using objects is easy


First instantiate the type of object desired
Then call its methods and get/set its properties
 Designing new types of objects can be hard

Design goals often conflict: simplicity, functionality,
reuse, performance
Programming Paradigms
Object-Oriented Programming
 Key object-oriented concepts


Identity
Encapsulation








Data + behavior
Information hiding (abstraction)
Classes vs. instances
Polymorphism
Interfaces
Delegation, aggregation
Inheritance
Patterns
Programming Paradigms
Component-Based Programming
 Components




Independent modules of reuse and deployment
Coarser-grained than objects
(objects are language-level constructs)
Includes multiple classes
Often language-independent
 In the general case, the component writer and
the component user don’t know each other, don’t
work for the same company, and don’t use the
same language
Programming Paradigms
Component-Based Programming
 Component Object Model (COM)




Initial Microsoft standard for components
Specifies a protocol for instantiating and using
components in-process, across processes or
across machine boundaries
Basis for ActiveX, OLE, and many other technologies
Can be created in Visual Basic, C++, .NET, …
 Java Beans


Java standard for components
Not language-independent
Programming Paradigms
Event-Based Programming
 When something of interest occurs, an event is
raised and application-specific code is executed
 Events provide a way for you to hook in your
own code into the operation of another system
 Event = callback
 User interfaces are all about events

onClick, onMouseOver, onMouseMove…
 Events can also be based upon time or
interactions with the network, operating system,
other applications, etc.
Agenda




Internet Technologies
Programming Languages and Paradigms
Programming the Web
.NET Overview
Programming the Web
Client-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 server
Better performance/user experience
Create UI constructs not inherent in HTML




Drop-down and pull-out menus
Tabbed dialogs
Cool effects, e.g. animation
Data validation
Programming the Web
Client-Side Technologies
 DHTML/JavaScript
 COM







ActiveX controls
COM components
Remote Data Services (RDS)
Java
Plug-ins
Helpers
Remote Scripting
Programming the Web
Dynamic HTML (DHTML)
 Script that is embedded within an HTML page
 Usually written in JavaScript (ECMAScript,
JScript) for portability

Internet Explorer also supports VBScript and other
scripting languages
 Each HTML element becomes an object that has
associated events (e.g. onClick)
 Script provides code to respond to browser
events
Programming the Web
DHTML
 The DHTML Document Object Model (DOM)
window
event
navigator
history
document
location
screen
frames
all
location
children
forms
selection
body
links
radio
button
text
password
file
checkbox
submit
reset
textarea
select
option
Programming the Web
ActiveX
 Based on COM
 Native only to Internet Explorer

Supported in Netscape with a plug-in
 Good when you know your users (e.g. intranet)
or can specify which browser to use
 Small, efficient code
Programming the Web
Java Applets
 Based on Java bytecode
 Held great promise as a portable, pain-free way
to download client-side code:

“Write once, run anywhere”
 Fairly safe: code runs in a “sandbox”
 Compatibility and performance issues have
prevented common usage
Programming the Web
Server-Side Code
 What is server-side code?


Software that runs on the server, not the client
Receives input from






URL 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 Web
Server-Side Code
 Why server-side code?

Accessibility


Manageability



Does not require distribution of application code
Easy to change code
Security



You can reach the Internet from any browser, any device, any
time, anywhere
Source code is not exposed
Once user is authenticated, can only allow certain actions
Scalability

Web-based 3-tier architecture can scale out
Programming the Web
Server-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 Web
Active Server Pages (ASP)
 Technology to easily create server-side
applications
 ASP pages are written in a scripting language,
usually VBScript or JScript
 An ASP page contains a sequence of static
HTML interspersed with server-side code
 ASP script commonly accesses and updates
data in a database
Programming the Web
ASP
HTTP request
(form data, HTTP
header data)
HTTP response
HTML, XML
ASP page
(static HTML,
server-side logic)
Agenda




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 .NET
What 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 .NET
What is .NET?
 A vision




Web 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
Introduction to .NET
What is .NET?

A platform



The .NET Framework
Visual Studio.NET
.NET Enterprise Servers


Database, Messaging, Integration,
Commerce, Proxy, Security, Mobility,
Orchestration, Content Management
.NET Building Block Services



}
The focus of
this course
Passport
.NET My Services (“Hailstorm”)
Goal: make it incredibly easy to build powerful Web
applications and Web services
Introduction to .NET
What is .NET?

A business model



Software as a service
Subscription-based services
Application hosting, e.g. bCentral
Introduction to .NET
The .NET Platform
Clients
Applications
Web Form
Protocols: HTTP,
HTML, XML,
SOAP, UDDI
Your Internal
Web Service
Web Service
.NET Framework
Windows
.NET Foundation
Web Services
Third-Party
Web Services
Tools:
Visual Studio.NET,
Notepad
.NET Enterprise
Servers
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 standards

HTTP, XML, SOAP, UDDI, WSDL, …
Web Services
Evolution of the Web
HTML, XML
HTML
HTML
HTML, XML
Generation 1
Static HTML
Generation 2
Web Applications
Generation 3
Web Services
The .NET Framework
What Is the .NET Framework?

A set of technologies for developing and using
components to create:




Web Forms
Web Services
Windows Applications
Supports the software lifecycle




Development
Debugging
Deployment
Maintenance
The .NET Framework
The .NET Framework and Visual Studio.NET
VB
C++
C#
JScript
…
ASP.NET: Web Services
and Web Forms
Windows
Forms
ADO.NET: Data and XML
.NET Framework Base Classes
Common Language Runtime
Visual Studio.NET
Common Language Specification
The .NET Framework
.NET Framework Classes
System.Web
Services
Description
Discovery
Protocols
UI
HtmlControls
Caching
Configuration
Security
SessionState
System.Windows.Forms
Form
Button
MessageBox
ListControl
WebControls
System.Drawing
Drawing2D
Imaging
System.Data
OLEDB
Design
SQL
SQLTypes
Printing
Text
System.Xml
XSLT
XPath
Serialization
System
Collections
Configuration
Diagnostics
Globalization
IO
Net
Reflection
Resources
Security
ServiceProcess
Text
Threading
Runtime
InteropServices
Remoting
Serialization
Common Language Runtime
Goals
 Development services


Deep cross-language interoperability
Increased productivity
 Deployment services


Simple, reliable deployment
Fewer versioning problems – NO MORE ‘DLL HELL’
 Run-time services



Performance
Scalability
Availability
 Reliability
 Security
 Safety
Common Language Runtime
Compilation
Source Code
Assembly
Compiler
C++, C#, VB or any
.NET language
csc.exe or vbc.exe
DLL or EXE
Common Language Runtime
Assemblies

Assembly



Manifest


Logical unit of deployment
Contains Manifest, Metadata, MSIL and resources
Metadata about the components in an assembly
(version, types, dependencies, etc.)
Type Metadata

Completely describes all types defined in
an assembly: properties, methods, arguments,
return values, attributes, base classes, …
Common Language Runtime
Assemblies
 Microsoft Intermediate Language (MSIL, IL)


All languages compile to IL (managed code)
IL is always compiled to native code before
being executed
 Resources

E.g. .bmp, .jpg
Common Language Runtime
Execution Model
Source
code
MSIL
Ngen
Native
code
VB
C#
C++
Compiler
Compiler
Compiler
Assembly
Assembly
Assembly
Common Language Runtime JIT Compiler
Managed
Code
CLR Services
Managed
CLR
Code
Managed
Code
Operating System Services
Unmanaged
Code
Common Language Runtime
Services
 Code management
 Conversion of MSIL to
native code
 Loading and execution of
managed code
 Creation and
management of metadata
 Verification of type safety
 Insertion and execution of
security checks
 Memory management
and isolation
 Handling exceptions
across languages
 Interoperation between
.NET Framework objects
and COM objects and
Win32 DLLs
 Automation of object
layout for late binding
 Developer services
(profiling, debugging, etc.)
Common Language Runtime
Multiple Language Support

Common Type System (CTS)


Common Language Specification (CLS)


A superset of the data types used by most modern
programming languages
A subset of CTS that allows code written in different
languages to interoperate
What languages?


Microsoft: C++, Visual Basic, C#, JScript
Third-Party: Cobol, Eiffel, Smalltalk, Scheme, Oberon,
Haskell, Java, Python, Perl, …
Common Language Runtime
Applications
 An application consists of one or more assemblies
 How does one assembly bind to another?

Based upon metadata and policy


Local (preferred)
Assembly Global Cache
 Multiple versions of an assembly may exist on
the same machine


Easier software deployment, updates and removal
Multiple versions of an assembly can even be used by
the same application
Common Language Runtime
Security




Evidence-based security (authentication)
Based on user identity and code identity
Configurable policies
Imperative and declarative interfaces
Windows Forms
 Framework for building
rich clients
 Built upon .NET
Framework, languages
 Rapid Application
Development (RAD)
 Visual inheritance
 Anchoring and docking
 Rich set of controls
 Extensible controls
 Data-aware
 Easily hooked into
Web Services
 ActiveX support
 Licensing support
 Printing support
 Advanced graphics
Web Forms
 Built with ASP.NET


Logical evolution of ASP
Similar development model: edit the page and go
 Requires less code
 New programming model





Event-driven/server-side controls
Rich controls (e.g. data grid, validation)
Data binding
Controls generate browser-specific code
Simplified handling of page state
Web Forms
 Allows separation of UI and business logic
 Uses .NET languages

Not just scripting
 Easy to use components
 XCOPY/FTP deployment
 Simple configuration (XML-based)
Web Forms




Caching (pages, fragments, custom)
Scalable session state management
Tracing support
ASP.NET is extensible

No ISAPI / ASP dichotomy
 Automatic process rollover
 Forms-based authentication
ADO.NET
 Similar to ADO, but better factored
 Language-neutral data access
 Supports two styles of data access


Disconnected
Forward-only, read-only access
 Supports data binding
 DataSet: a collection of tables
 Can view and process data relationally (tables) or
hierarchically (XML)
Languages
C#
 New language created for .NET
 Safe, productive evolution of C++
 Key concepts:




Component-oriented
Everything is an object
Robust and durable code
Preserving your investment
 Submitted to ECMA for standardization
 Uses .NET Framework classes
Languages
Visual Basic.NET
 Modernizes and simplifies Visual Basic



Inheritance
Threading
Exception handling
 Support for late binding
 Uses .NET Framework classes
Conclusion




Internet Technologies
Programming Languages and Paradigms
Programming the Web
.NET Overview
More Resources
 HTTP


http://msdn.microsoft.com/library/periodic/period96/protocol.htm
HTTP Essentials, Stephen Thomas, 2001, Wiley,
ISBN 0471-39823-3
 Cookies

http://msdn.microsoft.com/library/default.asp?URL=/library/partb
ook/instantj/cookies.htm
 MIME


http://www.ufaq.org/navcom/mime_tutorial.html
http://www.irvine.com/~mime/
 Networks

http://msdn.microsoft.com/library/periodic/period99/ntp99b3.htm
More Resources
 XML



http://msdn.microsoft.com/xml/default.asp
http://www.w3.org/XML/
Essential XML, Don Box, Aaron Skonnard, John Lam, Addison
Wesley, 2000, ISBN 0-201-70914-7
 .NET




http://www.microsoft.com/net/
http://msdn.microsoft.com/net/
http://www.gotdotnet.com
msnews.microsoft.com news server

microsoft.public.dotnet.general newsgroup