<<

.NET Technology and Demo

Dr. Ranjan K Sen Academic Developer Evangelist Corporation

Why .NET

• Software to be built using components from various sources – Software no longer created by single expert in isolation – Applications not built from scratch on a single machine • Standard Intermediate infrastructure for combining components • Software components need to be network aware – Adapt to changing network conditions – Reliable even when components are untrusted, run in diverse OS platforms and processors

1 Web Service

• Loosely coupled distributed application • Can change implementation at either end of a connection and the application continue working • Message based asynchronous technology • Web protocols such as HTTP, SMTP, XML etc • Optional look up service and a public interface for client to invoke service – UDDI, WSDL, SOAP, XML-RPC

WS Summary

• Benefits of WS – Interoperability • Share data and service across different platforms – Integration • Expose functionality and data of existing application – Efficiency of Implementation • Can reuse existing resource • Legacy code to provide service to external customers – Code Recycling – Modularity • .NET and J2EE – J2EE limited to

2 Application Architecture for .NET

• Virtual Execution Environment – Combining components from many sources to work correctly and reliably – Control of execution and verification of code at run time – Do not expose physical resources or processor or operating system • Managed components – Software parts that can be developed and deployed independently, yet safely coexist within applications

Common Language Infrastructure (CLI) • Standardized specification for a virtual execution environment – Describes data-driven architecture in which language-agnostic blobs of data are brought to life as a self-assembling, type-safe software system – Meta-data drives this process • Used to describe the behavior of software as well as its in-memory characteristics • CLI execution engine uses to enable managed components from many sources to be loaded together safely – Control and flexibility – Enables types from many people, places and platforms to coexist peacefully, while remaining independent

3 Execution engine

• Hosts components by interpreting the metadata that describes them at run time – Execution engine is a privileged code that loads, isolate and schedule; provides resources such as memory and IO to • Code that runs in this way is managed code – Managed code can be produced by tools and programming languages that can produce CLI compatible executables • CLI specification covers how unmanaged code can co-exist

CLI fundamentals • Expose all programmatic entities using a unified type system • Package types as self describing, portable units • Load types in a way that can be isolated form one another, but share resources • Resolve intertype dependencies at runtime, considering version, culture, admin policies • Type behavior info available to check for type safety • Defer processor specific tasks until at the last moment, do not penalize tools that does this earlier • Execute code under engine that provide accountability and enforce runtime policies • Run time services based on extensible metadata that can accommodate future changes corresponding to new inventions

4 Execution of managed code

• Chain of events load metadata from packaging units called assemblies • Convert metadata into executables codes appropriate for machine’s processor and OS – Resembles traditional tool-chain of , linker, and loader, as it performs in-memory layout, compilation, symbol resolution – By default the CLI loads types only as they are needed; linkages are evaluated, resolved, and compiled on demand

Common Type System (CTS)

• Processor-agnostic intermediate language for describing programs • that provides the basic data types for the intermediate language • Common Intermediate language (CIL) – Not tied to any hardware architecture – Drives abstract stack machine

5 Assemblies

• Portable packages for types – Within CLI packaged as assemblies which can be dynamically loaded into execution engine on demand either from local disk, network or even created on the fly under program control – Defines component model – Types cannot reside outside assemblies – Made up of one or more modules plus a – Assemblies are signed using a cryptographic key pair and a hash of the entire • Signature respected by execution engine and ensures that assemblies are not tampered with and damaged assemblies are not loaded

Application domains

• Achieves isolation – Protected address space per component • Assemblies are always loaded within the context of an • Types wish to communicate across domains must use special channels and behave according to specific rules • Remoting used for communicating between application domains running on different physical computers and running different OS – Components can be serializable and passed from domain to domain

6 Naming

• Version-flexible loading • Assembly names are formed from a standard set of elements • Assembly base name, version number, culture, hash of the public key (distributor) • Binding policy can enforce policy for compilation dependencies • Versioning information on dependent assemblies • (GAC) or a URL search path for assembly

JIT compilation and type safety

• Compiling high level type description separated from processor specific code generation – Easily adopt code to new OS and processor – Independently version components from many different sources • To amortize cost of transforming CIL into native code layout and code generation is deferred out • JIT compilation allows maintenance of control at runtime and run code efficiently • CIL is verifiably type safe – Type safety can be verified before a new type is loaded and allowed to run – Security policies can be checked and applied at the time CIL is transformed into native code

7 CLI Implementation

• .NET Framework – Windows 2003 server • Compact Framework – Small devices • Non-MS – Ximiam () and DotGNU (Portable .NET)

• C# a CLI language – Exploits most of CLI features

Building .NET components: Demo C# Command Line

• Creates Exe application by default – Has switches to change default – Default reference to mscorelib.dll – /r: for explicit reference – Using for namespace reference • Multiple source files • Utilities – ILDasm.exe, sk.exe, gacutil.exe

8 Building .NET components: Demo Visual Studio.NET IDE • Common IDE for all Microsoft languages – Regardless of the type of project you create • ATL, MFC, C#, Visual Basic.NET, raw C++ etc. • Class View gives an Object Oriented view of project • Server explorer can integrate multiple machines resources; Database manipulation • XML Editing tools • Other features – Properties Window provides detailed characteristics of selected item – Code blocks may be collapsed for abstracting logic – Referencing external assemblies – IntelliSense – Integrated debugger

Compiling into Assemblies

• Metadata describes all types within a given module – .NET runtime use this to locate and create objects • Manifest enumerates set of all internal and external files required by the binary – ILDasm.exe to examine assembly • Cross language inheritance – Any language targeting the run time is able to create (and extend) the types described within a given assembly – Demo • Global Assembly Cache (GAC) – For shared assemblies;Version check by .NET runtime – Default policy to allow binding if version major and minor fields match • Application configuration file – Contains XML tags to control binding of launching application – Tells run time locations from where to get binaries to bind – Specify custom version policy

9 AppDomain

• Number of related assemblies – System.AppDomain • A process can host one or more AppDomains • AppDomains are insulated from one another • Can communicate using .NET remoting protocol – Assemblies can be loaded, executed, unloaded in AppDomain

Demo

• C# component for List class • VB component for SortList class – Inherits from C# List class – How references to components are set – How references are put in GAC for sharing by other clients • Console application using SortList • WinForm application using SortList

10