Title: Microsoft 'NET Framework
1Microsoft .NET Framework
2The .NET Framework
- What is Microsoft .NET?
- A programming model CLR Classes
- XML Web services
- Server and Client software and tools
3Framework in context
4Common Language Runtime (CLR)
- Its a VM (Java-like) on which any (supported)
language can run. - Why a VM?
- Memory Protection
- Cross-language
- Support for strong-typing across languages
- Thread support
- Compactness
- Flexibility (Reflection, Meta-programming)
- JIT compilation in the VM
- Stack-based
- 3 generation garbage collector
5Languages in CLR
- Language of choice is C (C-sharp) a Java-like
language - No inner classes
- Better type checking
- Other languages will run on CLR, but only within
the CLR constraints - Visual Basic, JScript are full fledged CLR
languages - For example, only C that is VM-safe will run
- That subset looks much like C
- Under CLR, all languages get object features
- Inheritance used extensively
- Every language gets constructors
6Supported Languages
- Languages targeted to CLR
- APL C
C COBOL - Component Pascal Curriculum Eiffel
Fortran - Haskell Java Language
Microsoft JScript Mercury - Mondrian Oberon Oz
Pascal - Perl Python
RPG Scheme - SmallTalk Standard ML
Microsoft Visual Basic
Languages interoperate seamlessly. Can write
part of app in scheme, part in C and part in
Smalltalk!
7Languages compile to MSIL
- Languages compile to MSIL (Microsoft Intermediate
Language) - Can you say bytecodes?
- MSIL is shipped in portable executable (PE) units
- Can you say .class files or applets?
- Includes meta-data about types
- An application is made up of assemblies
8Reuse
- Tries to get maximum reuse of components/assemblie
s (like Smalltalk)
We get this in the .NET world via assemblies.
9Assemblies
- In general, a static assembly can consist of four
elements - The assembly manifest, which contains assembly
metadata (required). - Type metadata.
- Microsoft intermediate language (MSIL) code that
implements the types. - A set of resources.
10Assemblies can be spread across .NET
11Assemblies are the security unit
- Each assembly has a set of corresponding grants
- Each grant allows certain permissions
- DnsPermission, Environment, FileDialog, FileIO,
IsolatedStorage, Reflection, Registry, Security,
UI, WebPermission, SocketPermission - The set of grants establishes a security policy
- Grants are determined by CLR managed code
security policy system.
12Assemblies
- They are also the basic unit for
- Versioning
- Types
- Reference Scope Boundary
- Deployment
- Side-by-side execution
- Can be shared via the Global Assembly Cache (like
a Squeak Image).
13Application Domains
- Processes provide nice separation of applications
with separate address, security and run control.
But Causes problems with IPC. - Application Domains allow multiple applications
to run in same box, share memory and security
rights, but also have isolation and individual
security and run control if desired. So a
process can run multiple applications!
14MS .Net
15Class Library
- Data classes support persistent data management
and include SQL classes. - XML classes enable XML data manipulation and XML
searching and translations. - Windows Forms support development of Windows GUI
applications across CLR - Web Forms include classes that enable you to
rapidly develop web GUI applications.
16Forms
17C System.Object
- Public methods
- Equals
- GetHashCode
- GetType
- ToString
- Overriding inherited behaviors is common
18C Code and Manifest
using System class MainApp public static
void Main() Console.WriteLine
("Hello World using C!")
.assembly extern mscorlib .publickeytoken
(B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 1024110 .assembly Hello // ---
The following custom attribute is added
automatically do not uncomment. ------- //
.custom instance void mscorlibSystem.Diagnostics
.DebuggableAttribute.ctor(bool, // bool)
( 01 00 00 01 00 00 ) .hash algorithm
0x00008004 .ver 0000 .module Hello.exe
// MVID 58AD9DFD-63A6-462A-8AD5-42CBC95AA147
.subsystem 0x00000003 .file alignment 512
.corflags 0x00000001 // Image base
0x03330000
19Web, Windows, Whatever
- Part of the idea is to smooth transitions between
Windows and Web - Web interfaces become easier for Windows
developers - Windows apps become .NET Web-based apps
20MS .Net
21Data lt-gt XML, Everywhere
- All CLR data can be serialized to XML
- All XML can be expanded into CLR data
- Thus, anything can be shipped around on the Web
- Typing through XML Schema
- Pluggable Architecture
22XML Schema
- ltxsdcomplexType name"Person"gt
- ltxsdsequencegt
- ltxsdchoicegt
- ltxsdelement name"name"
type"xsdstring" - xsinillable"true" /gt
- ltxsdelement name"id"
type"xsdstring" /gt - lt/xsdchoicegt
- ltxsdany processContents"lax"/gt
- lt/xsdsequencegt
- lt/xsdcomplexTypegt
- ltxsdcomplexType name"AgedPerson"gt
- ltxsdcomplexContent mixed"false"gt
- ltxsdextension base"targetPerson"gt
- ltxsdchoicegt
- ltxsdelement name"age"
type"xsddouble" /gt - ltxsdelement name"timeOnEarth"
type"xsddouble" /gt - lt/xsdchoicegt
- lt/xsdextensiongt
- lt/xsdcomplexContentgt
23Example Instance
- ltnsdon
- xmlnsns"uuid048b2fa1-d557-473f-ba4c-
- acee78fe3f7d"
- gt
- ltnamegtDon Boxlt/namegt
- ltniceStuffForDon/gt
- lt/nsdongt
24Second Example Instance
- ltnsdon
- xmlnsns"uuid048b2fa1-d557-473f-ba4c-acee78f
e3f7d" - xmlnsxsi"http//www.w3.org/2001/XMLSchema-in
stance" - xsitype"nsAgedPerson"
- gt
- ltnamegtDon Boxlt/namegt
- ltniceStuffForDon/gt
- ltagegt26lt/agegt
- lt/nsdongt
25A Simpler Schema
- ltelement name"Book"gt
- ltcomplexTypegt
- ltelement name"author" type"xsdstring"/gt
- ltelement name"preface" type"xsdstring"/gt
- ltelement name"intro" type"xsdstring"/gt
- lt/complexTypegt
- lt/eBookgt
26Another Example Instance
- lteBookgt
- ltauthorgtHenry Fordlt/authorgt
- ltprefacegtPrefatory textlt/prefacegt
- ltintrogtThis is a book.lt/introgt
- lt/eBookgt
27XML Schema Defined Types
28Class Library Type Hierarchy
29Reading in XML Data
- XmlReader reader
- new XmlTextReader("http//foo.com/don.
xsd") - XmlSchema schema XmlSchema.Load(reader, null)
- schema.Compile(null) // turn xml into objects
- reader.Close()
30Serialized Classes
public class OrderForm public DateTime
OrderDate private int foo
ltOrderFormgt ltOrderDategt12/12/01lt/OrderDategt
lt/OrderFormgt
Note Only public instance data and properties
are serialized with XML.
31ALL Interprocess Communication via SOAP
- ALL Interprocess communication (across network or
on same machine) is through SOAP - Simple Object Access Protocol
- Its a way of exchanging data and even calling
other methods/threads, all via XML and plain old
HTTP requests
32SOAP 1.2
- SOAP is a lightweight protocol intended for
exchanging structured information in a
decentralized, distributed environment. SOAP uses
XML technologies to define an extensible
messaging framework, which provides a message
construct that can be exchanged over a variety of
underlying protocols. The framework has been
designed to be independent of any particular
programming model and other implementation
specific semantics.
33Example SOAP Request
- ltsoapEnvelope xmlnssoap"http//schemas.xmlsoap.
org/soap/envelope/"gt - ltsoapBodygt
- ltxTransferFunds xmlnsx"urnexamples-orgban
king"gt - ltfromgt22-342439lt/fromgt
- lttogt98-283843lt/togt
- ltamountgt100.00lt/amountgt
- lt/xTransferFundsgt
- lt/soapBodygt
- lt/soapEnvelopegt
34Example SOAP Response
ltsoapEnvelope xmlnssoap"http//schemas.xmlsoap.
org/soap/envelope/"gt ltsoapBodygt
ltxTransferFundsResponse xmlnsx"urnexamples-org
banking"gt ltbalancesgt
ltaccountgt ltidgt22-342439lt/idgt
ltbalancegt33.45lt/balancegt
lt/accountgt ltaccountgt
ltidgt98-283843lt/idgt
ltbalancegt932.73lt/balancegt
lt/accountgt lt/balancesgt
lt/xTransferFundsResponsegt lt/soapBodygt
lt/soapEnvelopegt
35Example SOAP Fault
ltsoapEnvelope xmlnssoap"http//schemas.xmlsoap.
org/soap/envelope/"gt ltsoapBodygt
ltsoapFaultgt ltfaultcodegtsoapServerlt/fau
ltcodegt ltfaultstringgtInsufficient
fundslt/faultstringgt ltdetailgt
ltxTransferError xmlnsx"urnexamples-orgbank
ing"gt ltsourceAccountgt22-34243
9lt/sourceAccountgt
lttransferAmountgt100.00lt/transferAmountgt
ltcurrentBalancegt89.23lt/currentBalancegt
lt/xTransferErrorgt
lt/detailgt lt/xTransferFundsgt
lt/soapBodygt lt/soapEnvelopegt
36Soap Request with Security
ltsoapEnvelope xmlnssoap"http//schemas.xmlsoap.
org/soap/envelope/"gt ltsoapBodygt
ltxTransferFunds xmlnsx"urnexamples-orgbanking
"gt ltfromgt22-342439lt/fromgt
lttogt98-283843lt/togt ltamountgt100.00lt/amountgt
lt!-- security credentials --gt
ltcredentialsgt ltusernamegtdavelt/usernamegt
ltpasswordgtevadlt/passwordgt
lt/credentialsgt lt/xTransferFundsgt
lt/soapBodygt lt/soapEnvelopegt
37MS .Net
38ASP.NET
- ASP gt Active Server Pages
- Put most of the computation in the server
- Very simple model to use
- ADO.NET is the database connection part
39Calling Web Services
- Any class can be converted into an XML Web
Service with just a few lines of code, and can be
called by any SOAP client.
40Take-away lessons
- VMs are important
- Even Microsoft thinks so
- Distributed apps are important, but to do so
requires standard protocols - Ways of serializing data (XML)
- Ways of doing RPC (SOAP)
- Design Decisions Good and Bad
41Limitations of the .NET Framework
- What if youre not on the network?
- Maybe thats not an issue?
- Mapping between XML and any object is hard
- Any object is controlled by compiler. XML can
be written by anybody with a text editor. - Theres a whole bunch of class support for
modified serializers and compilers