Thursday, May 1, 2008

What’s New with .NET 2.0

Agenda
Improvements to the Platform
Improvements to the Languages
Improvements to the Framework (BCL)
Improvements to the Tools



Common Language Runtime 2.0
Generics
Create generic classes whose type is specified by the class consumer
Vastly improved performance
Code errors are detected at compile-time
Edit & Continue
Best feature of Visual Basic 6.0!
Halt application execution in the debugger, change a line of code and continue execution without recompiling
Performance & Load time
CLR loads faster and with a smaller memory footprint



Platform Improvements
64-Bit Platform Support
Build managed 64-bit applications
InterOp with 64-bit native applications
Improved ASP .NET administration and caching
ASP .NET Web Site Administration Tool
IIS 6.0 Kernel-level Caching
Improved Smart (Rich) Client Deployment
ClickOnce
Improved COM InterOp performance
Ability to wrap native function pointers into delegates
Faster call performance between applications in different application domains
Improved XML Serialization performance
Improves Web Service performance



.NET Language Improvements / Enhancements
Generics
Partial Classes
Classes can be split across multiple files
Incredibly useful for classes whose implementation is specified partially by a tool
E.g. ASP .NET, WinForms, Web Service proxies
Iterators
New syntax to support easy implementation of custom class iterators
Anonymous Methods
… and much more!
(come see me in tomorrow’s session!)



Generics Example
public class MyList<> {
private Node head;
private class Node {
private Node next;
private Type data;
public Node( Type t ) {
next = null;
data = t;
}
public void Add( Type t ) {
Node n = new Node( t );
n.Next = head;
head = n;
}
MyList list;
list = new MyList();
for(int i = 0; i<10;i++)
{
list.Add(i);
}

Partial Classes Example
public partial class MySplitClass {
private int _foo = 0;
public MySplitClass( int foo ){
_foo = foo;
_bar = foo + 5;
}
}
public partial class MySplitClass {
private int _bar = 0;
public int Bar { get { return _bar; } }
public int Foo { get { return _foo; } }
}



What’s new in the BCL?
Compression Support (Gzip)
System.IO.Compression
ACLs Support
Manipulate and manage ACLs from managed code
System.Security
SecureString
Used for holding confidential data
Base Collections
Overhauled to support collections
New LinkedList and Stack collections!
System.Collections
Improved Encryption Support
System.Security.Encryption



System.IO.Compression.GZipStream Example
using System.IO.Compression;
using System.IO;
public class Unzip
{
public int UnzipFile(string filename)
{
FileStream fs;
try
{
fs = new FileStream( filename, FileMode.Open, FileAccess.Read, FileShare.Read );
byte[] buffer = new byte[fs.Length -1];
if( buffer.Length != fs.Read( buffer, 0, buffer.Length ) )
{
fs.Close();
throw new IOException( "Failed to read data from file" );
}
fs.Close();
MemoryStream ms = new MemoryStream();
GZipStream zipStream = new GZipStream( ms, CompressionMode.Decompress );
byte[] decompressBuffer = new byte[buffer.Length + 100];
int offset = 0;
while( true ) {
if( 0 == zipStream.Read( decompressBuffer, offset, 100 ) )
break;
else
offset += 100;
}
zipStream.Close();
// decompressBuffer now contains the original bytes
}
}



What’s new in the BCL? (…cont’d)
New network classes
Support for FTP
Ability to respond to network interface changes (disconnected cable, wireless LAN out of range)
HTTPWebListener
Supported by Windows 2003 and Windows XP SP2
Requires new HTTP.SYS
Supports hosting the ASP .NET runtime without IIS!
Now client applications can host web services!
SerialPort component
Semaphore class for Threading
System.Transactions namespace
Leverage DTC without the rest of System.EnterpriseServices



What’s new in ASP .NET 2.0?
Master Pages
Themes & Skins
Web Site Administration Tool
New Security Controls
Profile Management
Site Navigation Controls & Management
Web Parts
More than 45 new web controls!
Security, data access, navigation, image generation, menus, tree views, portals, and more!
All built-in controls are now mobile enabled!




What’s new in Smart Clients (WinForms) 2.0?
Big Changes!
67% more public types
127% more public properties
XP Themes Support
Application.EnableVisualStyles();
Control Layout improvements
Snap-To Alignment 
Layout Controls



WinForms 2.0 Layout Controls

Easier layout and resizing management of complex forms
Flow Layout: similar to ASP .NET (HTML) flow layout


Table Layout: form organized via rows and columns (one control per cell)



WinForms 2.0: Property Editing Mode
Enables in-place editing of properties



WinForms 2.0: New Controls
GridView
New version of GridControl
More intuitive object model for manipulating bound data
Supports Smart Tags for rapidly binding to a data source
MenuStrip
Powerful new menu tool with incredible rendering capabilities
WebBrowser
Managed IE .NET Component
SoundPlayer
Simples component to add sound to your applications
BackgroundWorker
Simplifies the task of using worker threads to retrieve data required by the UI



ClickOnce Deployment
Vastly simplified Smart Client development!
Rich Client applications with deployment and updates as simple as a web application
Invoked via BuildPublish Solution menu item



ClickOnce Configuration
Select Project  Properties
Brand new UI for manipulating project properties
Deployment Options:
Web Server
File Share
Update Options:
Check for updates when application starts
Check for updates in background while application is running
Allow whether or not user can accept update
Prerequisite Options:
dotnetfx
Windows installer
MDAC
SQL Server 2005 Express Edition
J# redistributable package



Project Properties




What’s new in ADO .NET 2.0?
Bulk Copy Operation
Enables bulk copying of one data source to another
Fastest way to transfer data from one source to another
Batch Update
Big performance improvement
Enables multiple rows to be updated in a single round trip
Used by the DataAdapter.Update() method
Batch size is set using UpdateBatchSize property
Data Paging
New method of the command object:
ExecutePageReader( Behavior, startIndex, pageSize)
Vastly simplified pagination logic



What else is new in ADO .NET 2.0?
Connection Statistics
Enables tracking of database statistics (data transferred, transactions, user details, …)
Set via Connection.StatisticsEnabled property
Statistics retrieved via Connection.RetrieveStatistics()
Statistics reset via Connection.ResetStatistics()
DataSet.RemotingFormat
Significant performance improvement for remoting a DataSet
Setting
ds.RemotingFormat = SerializationFormat.Binary;
results in binary wire serialization
New & Improved DataTable class
Supports Load() and Save() methods to directly load XML
No more DataSet objects with a single DataTable!



More ADO .NET Goodies!
New & Improved DataReader functionality
ExecutePageReader()
ExecuteResultSet()
ExecuteRow()



ADO .NET Common Provider Model
Simplified development of provider independent applications
DbProviderFactory class provides two methods:
GetFactoryClasses: Retrieves all providers installed on the machine
GetFactory( string ProviderName): Retrieves the provider class associated with the given name



What’s new in Web Services?
namespace WebService
{
[WebServiceBinding(
ConformanceClaims=WsiClaims.BP10 ]
public class Service : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
}
ConformanceClaims attribute alters the Web Services stack behavior to work in accordance with WS-I Basic Profile 1.0
Exceptions are thrown for logic that breaks compliance



XML Serialization Improvements
Performance hit when Web Service proxy is first instantiated
Direct result of code generation / class compilation for serialization logic
.NET 2.0 introduces a new tool: SGEN.exe
Generates the serialization class at design-time
Place the resulting binary in the same path as your client and the pre-compiled class will be used at runtime



WSDL.exe Improvements
Problem occurred in ASMX v1.x when two web services exposed the same custom type (i.e. “Customers” class)
Proxies generated by WSDL.exe would generate two separate instances of “Customer” which were not interchangeable.
Problem solved with new “/shareTypes” flag:
wsdl.exe /out:proxies.cs /shareTypes
http://localhost/CustomerService/CustomerMgmt.asmx?wsdl
http://localhost/CustomerService/CustomerInfo.asmx?wsdl
Creates one source file “proxies.cs” which contains proxy implementations for both web services as well as a single .NET representation of the “Customer” object

No comments: