Notes
Slide Show
Outline
1
Features, Strength and Weakness
of Microsoft .NET
2
"Full permission to copy and..."
  • Full permission to copy and distribute this material is granted to any one, provided the original contents of this document is distributed in full and the source and ownership of the document is acknowledged.


  • This document was produced at and belongs to DuraSoft, Inc. (http://www.durasoftcorp.com)


  • Pages with a          have detailed examples
3
"Abstract:Microsoft’s .NET technology is..."
  • Abstract:Microsoft’s .NET technology is gaining a lot of momentum. It has brought the next wave of excitement in the software development community and is challenging the state of the current practices. A number of technologies that have been developed in the recent past have made significantly contribution in the .NET technology. What are the main features and goals of the .NET environment? The Common Type System, the managed code and the Common Language Runtime makes the programming language almost a non-issue in .NET. It truly provides great language interoperability. The common class library/framework makes developing graphical and multithreaded applications a breeze in both VB.NET and C# and any of the other supported languages for that matter. What about the distributed object computing? XML technology serves as the marshaling wire protocol in .NET, making web services truly platform independent. In this presentation, we will look at the goals and features of .NET, we will discuss some of the strengths of this framework and take a look at some of the weaknesses as well. Code examples will be presented to illustrate the concepts.


  • Targeted Audience: Software developers, programmers and managers who are involved in day to day technical activities of software development will  benefit from this presentation. This session is mainly intended for programmers or people with fairly good programming experience.


  • About the Speaker: Dr. Venkat Subramaniam, president and co-founder of DuraSoft, is a trainer and mentor of software developers in the area of object- and web-based technologies. He is experienced in developing large scale object-oriented applications for engineering companies. He is also an adjunct professor in the Department of Computer Science at the University of Houston, where he teaches and works with graduate students on their research projects. Venkat is the instructor for the Professional Software Development Series at Rice Technology Education Center. Over the past 10 years he has trained over 2500 software professionals in the Houston area and around the world. He can be reached at venkats@durasoftcorp.com.
4
Overview of the Presentation
  • What is .NET?
  • .NET Architecture
  • CLR
  • Languages of .NET
  • ASP.NET
  • WinForms
  • Web Services
  • Strengths and Weakness
  • Conclusion
5
Technologies of the Past
  • Software Systems


  • Client-Server Computing


  • Object-Oriented Programming


  • Distributed Object Computing


  • Web-based technology
6
Distributed Object Computing
  • Component based software development


  • A Server or Component provides some service
    • Objects define behavior on services

  • Clients want to access these services


  • CORBA, DCOM technologies allow these


  • Power and limitations?
7
Web based technology
  • The world full of clients


  • Any platform, any where


  • Browser based


  • Power and limitations?


  • How much can you do with a browser front end?
8
What is needed?
  • How about a framework where
    • a software component is available on any server


    • any client can access it irrespective of platform


    • the client may be just about any thing
      • thin, fat
      • any language of your choice

  • The Software simply becomes a service
9
.NET
10
What is in .NET Framework
  • Common Language Runtime (Virtual Machine)
  • Class Libraries
  • Multi language development environment
11
.NET Framework Components
12
Overview of the Presentation
  • What is .NET?
  • .NET Architecture
  • CLR
  • Languages of .NET
  • ASP.NET
  • WinForms
  • Web Services
  • Strengths and Weakness
  • Conclusion
13
Application and Assembly
14
Assemblies
15
Manifest
  • Describes details about the assembly
    • version
    • security
    • scope
    • resources
    • classes
    • types
    • dependencies
  • Stored either
    • as a Portable Executable (PE) file along with MISL
    • or as stand along PE file with only the manifest info
16
Manifest Info
  • Provides enumeration of all files in assembly
  • This makes the assembly self-describing
  • Maps references to types, resources & files with their declarations/implementations
  •  Provides details of assemblies that containing assembly depends on
17
Metadata
  • These are the entries that go in a manifest
    • Assembly name
    • Version information
    • File list
    • Type information
    • References / dependencies
    • Custom meta data


  • Stored in a portable executable file (PE file)
18
Assembly Types
  • Private Assemblies
    • the default
    • only intended for use by one application
    • if several applications use, each will have a copy
      • (not the intent)


  • Shared Assemblies
    • this is intended for use by multiple applications
    • name must be unique so it does not collide
    • place in the global assembly cache


19
Building and Deploying Assembly
  • Creating a Library Project
    • Make sure your class implements IComponent or derives from System.ComponentModel.Component
  • Introspect the assembly using ildasm (covered next)
  • Generating shared names from keys
    • a public-private key pair is generated for the assembly
      • sn –k myKeyFile.snk
    • a hash value is created for names and contents of files
    • the hash is then signed using the private key
    • public key is then placed into the name of the assembly
  • Signing the assembly
    • modify an entry in the AssemblyInfo to indicate the key file
    • [assembly:AssemblyKeyFile(“myKeyFile.snk”)]
    • you may also replace the key at a later time by running sn with –R option
  • Placing the assembly in cache using the Al tool
    • gacutil /i:MyComponent.dll

20
Introspecting the assembly
  • MISL Disassembler allows module introspection
    • Execute ildasm yourModuleName
21
Probing
  • Probing is the heuristics and the process used by runtime to locate an assembly
    • unsuccessful probing information is logged
    • you may use Assembly Binding Log Viewer Fuslogvw.exe to view it
  • Assembly name, version, culture & public key used
  • Process of locating:
    • determine the proper version of assembly from config
    • use assembly if already loaded
    • use assembly from global cache if present
    • Go though a probing process if still not found
      • Check for location hints
      • If code base found in config, load it from that location
      • If code base not found, further probing happens
        • First checks in applications base, top level directory from which application executes
        • Then checks for a directory under app base whose name matches the culture specified
        • Then checks for a directory whose name matches the name of the assembly
        • Finally checks for in a user defined list of directories
22
Assembly Versioning
  • An assembly user generally binds to a specific version of an assembly it uses
  • Runtime performs checks to identify assembly:
    • checks original assembly for version to bind to
    • checks configuration files to determine version
    • looks in Global Assembly Cache or local dir for that version
  • This deals with only Assembly Version Number
  • Informational Version
    • another number for information may be provided
    • not used by the run time, though
23
Configuration Files
  • Configuration files are used to specify various information for run time to use


  • API’s can be used to read (not alter) these files


  • This makes it possible to make variations without having to change and recompile code


  • You may use .NET Framework Configuration Tool (Mscorcfg.msc)
24
Configuration Files…
  • Machine Configuration Files
    • machine wide settings in
    • %runtime install path%\Config\Machine.config
  • Application Configuration Files
    • For executable-hosted apps, appname.config in app dir
  • Security Configuration Files
    • May use Caspol.exe to configure to edit appropriate
      • Enterprise policy (%runtime install path%\Config\Enterprisesec.config)
      • Machine policy (%runtime install path%\Config\Security.config)
      • User policy (%USERPROFILE%\Application data\Microsoft\CLR security config\vxx.xx\Security.config)
25
Quiz Time
  • What is a common limitation of COM & CORBA?


  • What technologies are part of .NET framework?


  • What is a unit of deployment in .NET?


  • What are the two types of assemblies in .NET?


  • Contents, dependencies of assembly are described in?


  • Identity of an assembly is defined by?


  • Process of locating an assembly is called?


  • CLR look for private assembly in ___________________?


  • To be placed in GAC, an assembly must have?


  • CLR to look for different assembly version, what’s modified?
26
Overview of the Presentation
  • What is .NET?
  • .NET Architecture
  • CLR
  • Languages of .NET
  • ASP.NET
  • WinForms
  • Web Services
  • Strengths and Weakness
  • Conclusion
27
CLR
  • Common Language Runtime
  • Language is not an issue
    • it is your choice
  • Provides essential services
    • Memory management, GC, runtime
  • Common set of functionalities in place
    • no need for you to install things like XML parsers
  • Strong integration with tools
  • High Scalability
    • common infrastructure implemented efficiently
28
What is CLR?
  • CLR is the execution environment of .NET
    • Kind of like the VM of .NET
  • CLR does not interpret the code however
    • it compiles to native code, caches and executes
  • Code built to depend on CLR is managed code
  • CLR provides
    • memory management
    • garbage collection
    • tightened security
    • ease of deployment and maintenance
    • effective debugging facilities
    • multi language integration

29
Memory Management and GC
  • CLR administers area of Heap - Managed Heap
  • Takes full control of object space allocation
  • As objects created, memory allocated linearly
    • this allows for fast allocation
    • results in fragmentation though
  • GC takes care of this
    • invoked automatically when needed
    • explicitly called by GC.Collect();
30
GC Strategy Generation Count
  • May be expensive to De-fragment and compact
  • GC is usually performed on a small area of managed heap
    • rather than on the entire managed heap
  • Each object has a generation count or age
    • number of times it has survived GC sweep
  • This value
    • starts with 0
    • does not exceed 2
  • GC regroups objects
    • by generation count
31
GC Strategy Aggressive Collection
  • Based on “newer objects are short lived; if an object has lived for a while, it may live longer”


  • GC may decide to sweep only certain generation


  • GC checks for life time of an object aggressively
32
GC Strategy Aggressive Collection...
33
Managed vs. Unmanaged Code
  • Objects in the heap moved around as needed


  • CLR updates references to these objects


  • What if you pass a reference to unmanaged code?
      • code that takes memory management into its own hands
    • You first ask CLR to pin the object in memory
      • then pass the reference to unmanaged code
34
Unsafe vs. Unmanaged Code
  • Unmanaged Code:
    • this is not executed under the tight supervision of CLR
      • no garbage collection
      • limited debugging capabilities
    • Useful to call Platform Specific functions


  • Unsafe Code:
    • this is managed code!
    • it simply uses some constructs (like pointer usage) that C# does not encourage
35
Unsafe Code
  • CLR manages memory
  • Java does not allow pointer manipulation
  • C# derived from C++, wants to allow it, however with caution
  • Code that manipulates pointers may lead to memory leaks, etc.
  • C# declares the section of code that manipulates pointers as unsafe!
    • your take care of memory management when within this block of code – allows you to use pointers
  • To prevent GC use the fixed keyword to pin
36
Usage of unsafe
37
Quiz Time
  • What does CLR provide?


  • Generation count is the number of?


  • What’s called on an object when Garbage Collected?


  • What is the source code compiled into in .NET?


  • Code executed in CLR is called _________________?


  • To use pointers in C#, you mark the code as ________?


  • Before assigning a pointer to an object, you first __________?


  • You will not pin objects that are on the ___________?


  • Why do you have to pin the objects?


  • Is unsafe code classified as unmanaged code as well?
38
Overview of the Presentation
  • What is .NET?
  • .NET Architecture
  • CLR
  • Languages of .NET
  • ASP.NET
  • WinForms
  • Web Services
  • Strengths and Weakness
  • Conclusion
39
Common Type System
  • Each language has its own set of types
  • Type conversion in inter language communication is a pain
  • Errors usually goes unnoticed during compilation
    • Results in runtime errors
  • CTS addresses this
  • One set of types for all .NET languages
  • System.Object is the base type
    • Offers common set of methods for all types
40
Primitive Types
  • Boolean
  • Byte
  • Char - unicode
  • DateTime
  • Decimal – signed 28 significant digits
  • Double – 64 bit double precision
  • GUID
  • Int16, Int32, Int64
  • Sbyte – 8 bit signed integer
  • Single – 4 byte single precision
  • TimeSpan
41
Value Type vs. Reference Type
  • Value type instances created on stack
  • Reference types instances created on heap
  • These are very similar to the concept in Java
  • Evaluation of Equals
    • on value types compares value
    • on reference types compares identity

  • Reference types are initialized to null
  • Unboxed value types initialized to a default value
42
Value Type vs. Reference Type
  • Let X be reference type


43
Custom Types
  • User defined types may be created
    • may be of value types
    • may also be of reference type

  • Available to all .NET languages!
44
Value type: Boxing and Unboxing
  • Boxing is the conversion or copying of a value type to a reference type
    • The value types is wrapped into a reference intance

  • Unboxing is the conversion or copying of a boxed reference to a value type
45
C++, Java, VB and C#
46
C++, Java, VB and C#…
  • C# made to be simpler than C++
    • eliminates a number of troublesome constructs
    • you still have the power to use C++ with in C#!
      • mark the code as unsafe

  • VB.NET has evolved to features offered by C#


  • Java and C# have similarities
    • reflection, no global functions
    • However, C# carries features of C++ that Java does not
      • operator overloading, enumeration
47
Quiz Time
  • Types used by .NET languages are from?


  • What types of objects are created on stack?


  • What keyword is used to make it a value type?


  • What keyword is used to make it reference type?


  • Conversion of value type to reference type is called  ________?


  • What executes the MSIL code in .NET ________?


  • What are the int types in CTS __________________?


  • What languages does C# resemble ___________?


  • Which language has gone through major revision?


  • What features does C# have that Java does not?
48
Overview of the Presentation
  • What is .NET?
  • .NET Architecture
  • CLR
  • Languages of .NET
  • ASP.NET
  • WinForms
  • Web Services
  • Strengths and Weakness
  • Conclusion
49
ASP
  • Microsoft’s web  server technology
  • Largely VBScript or JavaScript driven
  • What about C++ or VB?
  • These are written as ASP components which are called from ASP script
    • Not very elegant
  • Still quite a bit of effort in developing web apps
  • You mix HTML and script in your code
  • In ASP.NET, VB.NET is the default, not VBScript
50
What does ASP.NET solve?
  • Less code
    • You rely on controls that manage session state with almost no code to be written
    • You get better control towards code reuse
    • Not interpretive – code compiled
      • .NET class created on first visit to a page
      • Similar to how JSP works!
      • Any changes are automatically recompiled
      • Cached class gives better performance
    • Much better control over components development/reuse
      • Easy to upgrade and redeploy
      • Strong typed languages make it easy to use components
    • Good separation of HTML and Script code
    • Better control on client variations
      • Server side components sense type of browser and can tailor response
      • Adaptive user interface (AUI) for support of devices
    • Strong XML support
      • Probably most driving feature SOAP leading to web services
51
ASP.NET and Web Server
52
Writing an ASP.NET Page
53
HTML Server Controls
  • Think of these as macros
    • they expand to HTML code
  • They appear like HTML tags
    • But much shorter and replace several lines of HTML
  • Smart enough to remember state between pages


54
Server-side Event Handling
  • Traditionally in ASP, browser handles client events


  • Some times we want to perform some thing on server
    • like accessing additional data

  • Still good idea to handle client events on client


  • Allows you to handle events on server side as well


  • Browser handles event and sends postback to server
55
Types of Controls
  • Intrinsic Controls


  • Rich Controls


  • User Controls
56
Code-Behind Page
  • You can create a class/Page


  • You can then refer to that class from your ASP.NET page


  • Gives exceptional reuse and extensibility


57
Overview of the Presentation
  • What is .NET?
  • .NET Architecture
  • CLR
  • Languages of .NET
  • ASP.NET
  • WinForms
  • Web Services
  • Strengths and Weakness
  • Conclusion
58
Event Handling
59
Delegate
  • Event handlers traditionally were global or static functions
  • In .NET, delegates allow a lot more
  • Delegates are data structures (objects) that hold
    • either a pointer to global or static function
    • or a pointer to an object’s method and the object itself
    • are object-oriented, type safe and secure
  • All Delegates derive from the Delegate class


60
Events
  • Events are implemented using the Delegates
  • Act like the connection point in COM
  • You first declare a delegate, only if a suitable one is not available
    • must take two arguments: Object source, EventArgs e
    • .NET has predefined delegate EventHandler
  • Any number of events can use the same Delegate definition
  • Use event keyword to declare event in a class
  • events appear like fields within a class
    • big difference: fields can’t appear in interface, events can
61
What does WinForms provide
  • Windows Forms or WinForms are classes that provide User Interfaces
  • These bring rich VB UI to all .NET languages
  • Set of class library to develop efficient UI on .NET
  • Provides visual inheritance
    • If you inherit from a class, you inherit its UI as well
    • You can say inherit from a dialog and simply add a button
62
Hierarchy (Partial)
63
Form Class
  • Representation of any window in the application
  • You can create an object of this, set it to be modal, create as a dialog, create and attach MDI windows
64
Writing a WinForm Application
  • Using Visual Studio .NET to write a windows application



  • The main class


  • Modifying the main class


  • EXAMPLE
65
Overview of the Presentation
  • What is .NET?
  • .NET Architecture
  • CLR
  • Languages of .NET
  • ASP.NET
  • WinForms
  • Web Services
  • Strengths and Weakness
  • Conclusion
66
Distributed Computing
With Interfaces
  • DCOM, CORBA, RMI architectures
67
Distributed Computing & XML
  • Problems with DCOM & CORBA
    • Interfaces based clients bind to the interface IDL
    • DCOM works only among select platforms
      • Predominantly on Windows NT, 2000, etc.
    • Client side ORB is required in case of CORBA


    • These technologies are for intranet and not internet
      • firewall will block the requests from a truly remote client!

  • XML
    • provides cross platform transfer mechanism
    • has multi-language / multi-vendor support
    • So why not use XML to transport method invocation rather than simply data?
68
A Remoting Scenario
  • The Payload
    • XML document could simply present method names
      • as elements
    • data may be carried by sub-elements
  • The receiving system could
    • parse the XML document
    • Generate an XML response and send it back to the client
  • The client waits for response, receives & parses it
69
SOAP
  • A well-formed XML may be used as a wire protocol
  • XML documents can be easily transported to remote systems
    • Most convenient to use HTTP (walks through firewall)
    • Other mechanisms like SMTP
  • Mechanism is addressed by SOAP
    • Simple Object Access Protocol (SOAP)

  • SOAP relies on the XML schema definition and elements
    • It uses the schema definition
    • The elements are used to communicate information
    • attributes are used to communicate SOAP specific meta-information
70
SOAP’s approach
  • To use HTTP (or other mechanisms) for transport
  • Use XML for data encoding/information exchange
  • Keep it simple and extensible
71
Basic SOAP Payload Structure
72
SOAP Applied
  • Web Services is simply an application of SOAP
73
Web Service Infrastructure
  • Web Service Wire Format
    • Protocol to allow open communication between various entities independent of platform
    • SOAP
  • Web Service Description
    • Allows for finding the details of web services, its methods, arguments, types, etc
    • Web Service Description Language (WSDL)
  • Web Service Discovery
    • Allows for a web service to make its presence known and for a client to find it
    • SOAP Discovery (DISCO)
74
Writing a Web Service
  • Write a web service source with .asmx
75
Compiling the Web Service
  • Packaging into DLL Module: useful to call from ASP.NET or rich clients
  • Visual Studio .NET makes it easier to build a web service.
  • Click on File, New, Project
  • Select Visual C# Projects, and ASP.NET Web Service under Templates:.
  • Modify Location to http://localhost/WeatherInfo
  • Delete the created service1.asmx and create a new web service by right clicking WeatherInfo in solutions explorer, clicking on Add, Add Web Service.
  • Give the name as TemperatureProvider.asmx and modify the code to add a method named temperature as shown in previous page.
  • Right click on TemperatureProvider.asmx in solutions explorer and select “Set as start page.”
  • Press Ctrl+F5 to test it!
76
What about traditional clients?
  • For non-web based client, you can create proxy
  • The web client proxy receives a request, generates XML request & sends it using SOAP
  • Receives response, parses it and hands it over to client!
  • You can generate a web service proxy using the WSDL compiler.
  • You provide a reference to service description using which proxy can be generated
77
Making an Asynchronous call
  • Your proxy has three special methods for each web service methods:
    • yourWebServiceMethod [example: temperature]
    • BeginyourWebServiceMethod [Begintemperature]
    • EndyourWebServiceMethods [Endtemperature]
  • You can
    • invoke the Being… method
    • go about doing other things you have to do
    • finally, when you are ready, call the End… method

78
Being Notified on Asynchronous call
  • In the above example, you have to check back when you are ready for the result


  • Would it be nice to be notified when result is ready?


  • You can register a callback delegate for notification when the method is complete!


79
Quiz Time
  • What is a delegate in .NET?


  • Process of packaging req. in distributed computing?


  • What is used for marshaling/wire protocol in web services?


  • What is SOAP?


  • What is used to describe and expose a web service?


  • Attribute used to make a method a web method is _________.


  • Rich client communicates with web service using _________?


  • By nature, as far as state goes, a web service is  __________?


  • For each web method, how many methods are in proxy?


  • What .NET concept is used in registering an asynch call back?
80
Overview of the Presentation
  • What is .NET?
  • .NET Architecture
  • CLR
  • Languages of .NET
  • ASP.NET
  • WinForms
  • Web Services
  • Strengths and Weakness
  • Conclusion
81
Strengths and Weakness
  • Strengths
    • Visual Studio enhances productivity
    • Shortest time to market
      • faster to develop, lower cost
    • Fairly stable (especially compared to beta 2!)
    • High interoperability
    • You code in the language you like, no force
  • Weakness
    • from Microsoft ;)  (just kidding)
    • Leveraging with existing unmanaged code
    • Until future release of OS, requires special installation of framework
    • Security of Web Services major concern
82
Overview of the Presentation
  • What is .NET?
  • .NET Architecture
  • CLR
  • Languages of .NET
  • ASP.NET
  • WinForms
  • Web Services
  • Strengths and Weakness
  • Conclusion
83
Conclusion
  • Truly a very exciting technology
  • High productivity
  • Low cost of development
  • Fun to program in - my opinion :)


  • It is going to change the way we develop systems – I sincerely hope so


  • Now, lets go crack some code!
84
References
  • http://www.w3.org


  • http://msdn.microsoft.com


  • http://www.durasoftcorp.com/download
85
Thanks to the CACP group