.Net Framework

Document Sample
.Net Framework Powered By Docstoc
					What is .NET?

  The .NET Framework is an integral
  Windows component that supports building
  and running the next generation of
  applications and XML Web services.
Defining .Net( cont)

   .Net targets on some objects:
       .Net is a new platform for the development and deployment
        of modern, object-oriented, “managed” applications
       Fully function. Net can be developed using any
        programming language that targets the .Net runtime( C#,
        VB. Net, managed C++, JScripts )
       .Net provides a comprehensive framework of language-
        neutral class libraries
       .Net supports multilanguage integration, cross-language
        component reuse , and cross-language inheritance
       .Net introduces a new way to develop Web-based and
.Net Framework
   The .Net framework includes:
       Common Language Runtime (CLR):
        provides an execution environment that incorporates
        features such as :
            Code verification and complication
            Security management
            Memory management

       .Net Framework class library: is a library of
        class, interfaces, data structure and delegates
        intended to provide the foundation for .Net
        applications, components, services and controls
.Net Framework
.Net Framework- Managed code
    Software that uses the .Net Framework
    (and thus relies on the CLR) is referred to
    as managed code
   In object-oriented paradigm, these
    codes/objects are known as managed
   Objects written in any CLR-based language
    can inherit and use the library’s code
   Some managed code languages includes:
    C#, VB.NET, Jscript.NET, Managed C++
.Net Compact Framework

   The .NET Compact Framework is a smaller version
    of the .NET Framework
   It can be used with smaller devices , such as mobile
    phones, PDAs, set-top boxes.
   It takes less memory so MS eliminates some part of
    the .NET Framework class library
   It can be developed in other environments and
    language like .NET Framework
   It’s also an important piece of Microsoft’s overall
    .NET strategy
What the CLR Defines?

   The CLR defines a common set of semantics
    that is used by multiple languages such as
    common set of data types( integer, string ,
    classes, interfaces), specifications for how
    inheritance works, common set of semantics
    for language built in it
Using CLR

   The CLR supports many different language
    and targets on these features:
       Compilation and Verification
       Security
       Memory Management
Using CLR- Compilation and Verifying

       CLR is the fundamental for everything in .NET
       It supports the creation and execution of managed
       It offers the building, compiling, organizing,
        executing these managed code:
        Building Managed Code: The Common Type System
        Compiling Managed Code: MSIL and Metadata
        Organizing Managed Code: Assemblies
        Executing Managed Code : JIT compilation
Building Managed Code: Common Type System (CTS)
   The Common Type System
    defines core semantics but not
   The CTS defines reference and
    value types. Both inherit directly
    (reference type) or indirectly
    (value type) from a type called
    Object( System. Object)
   All value types inherit from
    ValueType, different from Object
    , value types cannot act as a
    parent type for inheritance. In
    CLR, value types are said to be
   The Common Language
    Specification (CLS) defines a
    (large) subset of the CTS that a
    language must obey if it wishes
    o interoperate with other CLS-
    compliant languages
Using CLR- Compilation and Verifying

    Building Managed Code: The Common Type
     System (CTS)
    Compiling Managed Code: MSIL and Metadata
    Organizing Managed Code: Assemblies
    Executing Managed Code : JIT compilation
Compiling Managed Code: MSIL and Metadata

   When a managed code is
    compiled , two things are
     Code in Microsoft
       Intermediate Language
     Metadata, information
       about those instructions
       and the data they
   Both the MSIL and the
    metadata are stored in a
    standard Window portable
    (PE) file. This file can be
    either a DLL or an EXE, and
    generally called module.
Compiling Managed Code: MSIL

   MSIL is a CPU-independent set of
    instructions that can be efficiently converted
    to native code
   MSIL is full, stack-based language that you
    can use to implement .NET components
   MSIL is not an object-oriented language.
Compiling Managed Code: MSIL

MISL instructions and what they’re used for
   Add: adds the top two values on the stack and pushes the result
     back onto the stack
   Box: Converts a value type to a reference type; that is , it boxes
     the value.
   Br: Transfers control (branches) to a specified location in memory

   Call: calls a specified method.

   Idfld: Load a specified field of an object onto the stack.

   Idobj: Copies the value of a specified value type onto the stack

   Newobj: Creates a new object or a new instances of a value type

   stfld: stores a value from the stack into a specified field of an
   Stobj: Stores a value on the stack into a specified value type

   Unbox: Converts a boxed value type back to its ordinary form
Compiling Managed Code: MSIL
// A C# example

      interface IMath{
                  int Factorial(int f);
                  double SquareRoot( double s);

      class Compute : IMath
                public int Factorial(int f)
                                    int i;
                                    int result=1;
                                    for (i=2;i<=f;i++)
                                      return result;
                  public double SquareRoot( double s)
                                   return System.Math.Sqrt(s);

      class DisplayValues
                 static void Main()
                                      Compute c= new Compute();
                                      int v;
                                                     "{0} factorial: {1}",
                                                     "Square root of {0}: {1:f4}",
Compiling Managed Code: MSIL
 .method public hidebysig static void Main(string[] argv) cil managed
   .custom instance void
 [mscorlib]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 )
   // Code size       25 (0x19)
   .maxstack 1
   .locals init (class [vshostutil]VSHostUtil.HostProc V_0)
   IL_0000: call        class [vshostutil]VSHostUtil.HostProc
   IL_0005: stloc.0
   IL_0006: ldloc.0
   IL_0007: callvirt instance void [vshostutil]VSHostUtil.HostProc::SetVSEvent()
   IL_000c: ldloc.0
   IL_000d: callvirt instance class [mscorlib]System.Threading.AutoResetEvent
   IL_0012: callvirt instance bool [mscorlib]System.Threading.WaitHandle::WaitOne()
   IL_0017: pop
   IL_0018: ret
 } // end of method EntryPoint::Main
Compiling Managed Code: Metadata
   Compiling managed code always
    produces MSIL and metadata.
    Metadata is information about the
    types defined in the managed code . It
    is stored in the same file as the MSIL.
   This information is loaded into memory
    when the file itself is loaded, making
    the metadata accessible at the
   Metadata can also be read directly
    from the file that contains it, making
    information available even when code
    isn’t loaded into memory
   The process of reading metadata is
    know as reflection
   What metadata contains:
       The type’s name
       The type’s vibility, which can be
        public pr assembly
       What type this type inherits from
       Any interfaces the type implements
       …
Using CLR- Compilation and Verifying

    Building Managed Code: The Common Type
     System (CTS)
    Compiling Managed Code: MSIL and Metadata
    Organizing Managed Code: Assemblies
    Executing Managed Code : JIT compilation
Organizing Managed Code: Assemblies
   An assembly is one or more files that
    comprise a logical unit.
   Metadata for Assemblies: Manifests.
   An assembly’s manifest contains the
    assembly’s name, its version number,
    list of other assemblies it depends on
    and all types and resources exposed
    by the assembly..
   An assembly can be built from a single
    file or a group of files ( modules). With
    a single-file assembly, the manifest
    stored in the file itself. With a multifile
    assembly, the manifest is stored in
    one of the files in the assembly, while
    the metadata in each module defines
    the types in that module
   The assembly is responsible for
    declaring the security it requires.
    Request for permissions fall into one
    of three categories: required, optional,
    denied. The identity information may
    be used as evidence for determine
    whether or not to approve the security
Using CLR- Compilation and Verifying

    Building Managed Code: The Common Type
     System (CTS)
    Compiling Managed Code: MSIL and Metadata
    Organizing Managed Code: Assemblies
    Executing Managed Code : JIT compilation
Executing Managed Code:
    Executing Managed Code
   Loading Assemblies:
       When an application is executed , the assemblies that make up
        that application must be found and loaded into memory.
       Founding the application:
           CLR determines what version of a particular assembly it’s looking for (
            in the manifest)
            CLR checks whether the desired assembly is already loaded. If it is,
            the search is over, this loaded version will be used. If the desired
            assembly is not already loaded, the CLR will begin searching in
            various places to find it:
               Global assembly cache (GAC), a special directory intended to hold
                assemblies that are used by more than one application
               The CLR can next look in the location referenced by a codebase element.
               If no codebase element exists , the CLR searches in other places: URL,
                directory, …
       Assemblies are loaded into memory only when needed
Executing Managed Code

   Compiling MSIL:There is two option exist for
    doing this:
       MSIL code can be compiled one method at a
        runtime during execution: JIT compilation
       MSIL code can be compiled into native code all at
        once before an assembly is executed: NGEN
        (Native Image Generator)
Executing Managed Code:
   JIT Compilation
       CLR load an assembly and then compile each method at the first time that
        method is invoked, this process is called just-in-time compilation
       When a method is JIT compiled, it’s also check for type safety, This process,
        called verification, The CLR’s built in security features depends on this
       Only those methods that get called will be compiled. If a method in an
        assembly is loaded but never used, it will stay in its MSIL form. Compiled
        code is no saved on disk, JIT compilation is carried out each tine an
        assembly is loaded.
   Creating a Native Image (NGEN):
       An assembly MSIL code can be traslated into native code for a particular
        processor all at once using the NGEN.
       The assembly will now be loaded as native code
       Using NGEN doesn’t make the overall speed of the application.
   Note: .NET Framework does not include an interpreter for MSIL.
    Executed code is either JIT compiled or compiled all at once.
Executing Managed Code:
Using CLR: Security
   When compiling MSIL to native code, code must pass a
    verification process.
   Verification examines MSIL and metadata to find out whether the
    code is type safe.
   Type safety provides assurance that security restrictions on code
    can be reliably enforced.
   The runtime relies on the fact that the following statements are
    true for code that is verifiably type safe:
     A reference to a type is strictly compatible with the type being
     Only appropriately defined operations are invoked on an object.

     Identities are what they claim to be.
Using CRL- Security

   The CLR implements two different types of
    security for assemblies: code access and
    role-based security
   Role-based security:
       Role-based security gives way to control what an
        assembly is allowed to do based on the identity
        (indicated by an identity object) of the user on
        whose behalf the assembly is running
       The foundation for role-based security is a
        principal object.
Using CLR: Security-                    Code Access Security

    Code access security can limit what running
     code is allowed to do
    CLR determines what an assembly is allowed
     to do and an assembly’s permissions are
     checked at runtime
    CLR-based code is allowed to do depends on
     the intersection of two things
        What permissions that code requests
        What permissions are granted to that code by the security policy.
Using CLR: Management Memory
   Garbage collection
       Every instance of a reference type is
        allocated on the heap. As the
        application runs, the memory allotted
        to the heap fills up. Before new
        instances can be created, more
        space must be made available. The
        process of doing this is called
        garbage collector
       When CRL notices that the heap is
        full, it will automatically run the
        garbage collector
       Garbage objects can appear
        anywhere in the heap
       Garbage collection can reposition the
        contents of the heap
       The garbage collection view objects
        in generations
.NET Framework Class Library

   The .Net framework class library can
    be used from any CLR-based
   The .Net framework class library is
    organized as a tree of namespaces.
    Each namespace can contain types,
    such as classes and interfaces, and
    other namespaces.
   The root namespace is System
   The System namespaces contains
    many different types:
       The core types defined by the CLR ’s
       Console
       Math
       Environment
       GC (garbage collector)
       Random
    .Net Framework Class Library
   System.Data: The types implement ADO.NET, the standard approach to accessing data for .NET
    framework applications
   System.Diagnotics: contains a large set of classes, interfaces, structures, and other types that help with
    debugging .NET framework applications
   System.EnterpricesServices: contains types for accessing the services provided by COM+, including
    support for distributed transaction, role-based authorization, and object pooling
   System.IO: provides a large set of types for reading and writing files, directories, and in-memory streams
   System.Net provides types for accessing several common protocols, including HTTP and Domain Name
    System (DNS)
   System.Security: contains classes, interfaces, enumerations, and subordinate namespaces that provide
    various security-related functions. Some subordinate namespace:
       System.Security.Cryptography: contains types for using secret and public key cryptography services
        System.Security.Permissions: contains types such as a class representing each of the possible
        permissions for code access security
       System.Security.Policy: defines classes such as Site, URL, Publisher, Zone, and others used in
        defining security policy
       Sytem.Security.Principal: contains types for working with security principals. These classes are used
        by the CLR in implementing role-based security
   System.Web, the most important namespaces. It implements ASP.NET. The most two important children
    of System.Web are:
       System.Web.UI: contains types for building browser-accessible applications
       System.Web.Services: contains types for creating applications that exposed Web Services
   System.Windows.Forms: contains types used to construct local Windows GUIS
   System.XML: contains types useful for working with XML documents.
Accessing Data: ADO.NET
   ADO.NET lets applications access
    stored data
   ADO.NET clients rely on a .NET data
    provider to access a DMS. .NET data
    providers built from managed code
   A .NET data provider allows clients to
    access data either directly as rows or
    through a DataSet:
       Direct Access to Data (by rows):
       Accessing Data with DataSets:
           A DataSet is an in memory
            cache that can store data from
            various sources
           DataSets allow much more
            flexible access to data than is
            possible with a DataReader
           A DataSet contains DataTables
           DataSets can also be used
            with XML-defined data and we
            can translate between
            DataSets and XML Documents
Building Web Applications: ASP.NET
   Implemented in the
    System.Web namespace,
    ASP.NET is a major piece of
    the .NET Framework
   ASP.NET allows the creation
    of two types of applications:
       Traditional browser
        applications accessible via
        HTTP and HTML and execute
        in files with extension .aspx
        (VB.NET is the default
        language for .aspx pages)
       Web Services applications
        accessible via SOAP and
        execute in files with extension
Web Services
   Allowing software running on other systems to invoke operations
    over the Web directly would allow Web applications to provide
    richer services to more diverse clients
   Web services rely on four fundamental technologies:
        Describing information sent over the network: Invoking a remote
         operation commonly involves passing in parameters and getting
         back some kind of result. With Web services, this information is
         described using Extensible Markup Language (XML)
        Defining Web services capabilities: specify the technical details of
         exactly what services are offered. For Web Services, this can be
         done using the Web Services Description Language (WSDL).
         Each WSDL-defined interface contains one or more operations,
         and WSDL itself is defined using XML.
        Accessing Web services: Simple Object Access Protocol (SOAP)
         provides a way to identify which operation to invoke. SOAP itself
         defines only simple envelope for conveying this information
        Finding Web Services: Universal Description, Discovery, and
         Integration (UDDI)- standard registry fir storing and accessing this
         kind of information. UDDI allows clients to learn what services
         each provider offers and letting creators of clients software learn
         what they need to know to build those clients
   Applying Web services:
        Allowing programmatic access to applications accessed via the
        Business-to-business (B2B) integration, allowing applications from
         different organization to communicate across the Internet
        Applcation-to-application(A2A), allowing applications within a
         single organization to communicate across an intranet
.NET My services
   .Net My services is a set of Internet-
    accessible Web services provided
    by Microsoft
   .NET My services includes an
    authentication service
   Some services provided by .NET My
       .NET Alerts
       .NET Calendar
       .NET Contacts
       .NET Inbox
       .NET Documents
       .NET Lists
       .NET Wallet
       .NET Profile
       .NET Presence
   .NET My Services raises many
    security and privacy issues
The .NET Framework vs the Java Environment
   Mainstream software development
    today split into two camps:
       Microsoft, promoting the .NET
       Sun , promoting the Java
   They are similar in some points:
       Support the same classes of
           JavaServer Pages , JDBC,
            Swing, Enterprise JavaBeans
            for Java Environment
           ASP.NET, ADO.NET, Windows
            Forms, Enterprise Services for
            .NET Framework
       C# and VB.NET are quite similar to
   But they are also different in some
       Java runs on diverse operating
        .NET framework focuses on
A .NET example
   Step1: User contacts
    Passport authentication
    part of .NET My Services to
    obtain a way to identify
    herself reliably
   Step2: Use browser to
    access ordering application
   Step3: Order application
    access .NET My Services
    to acquire information
    about the customer
   Step4: Ordering Application
    communicates with
    shipping application
    (building in BizTalk Server)
   Step5: Ordering application
    uses SOAP to access
    billing application

Shared By: