.NET.NET
OverviewOverview
Overview of the Microsoft .NET Overview of the Microsoft .NET FrameworkFramework
Overview of ASP.NetOverview of ASP.Net Overview of WebServicesOverview of WebServices Overview of ADO. NetOverview of ADO. Net
Overview of Overview of FrameworkFramework
Overview of the Microsoft .NET Overview of the Microsoft .NET FrameworkFramework
The .NET FrameworkThe .NET Framework Common Language RuntimeCommon Language Runtime The .NET Framework Class LibraryThe .NET Framework Class Library ADO.NET: Data and XMLADO.NET: Data and XML What is an XML Web Service?What is an XML Web Service? Web Forms and ServicesWeb Forms and Services Garbage CollectionGarbage Collection
The .NET FrameworkThe .NET Framework
Win32Win32
MessageMessageQueuingQueuing
COM+COM+(Transactions, Partitions, (Transactions, Partitions,
Object Pooling)Object Pooling)IISIIS WMIWMI
Common Language RuntimeCommon Language Runtime
.NET Framework Class Library.NET Framework Class Library
ADO.NET: Data and XMLADO.NET: Data and XML
Web ServicesWeb Services User InterfaceUser Interface
VB C++ C#
ASP.NETASP.NET
Perl Python …
Common Language RuntimeCommon Language Runtime
.NET Framework Class Library Support.NET Framework Class Library Support
Thread SupportThread Support COM MarshalerCOM Marshaler
Type CheckerType Checker Exception ManagerException Manager
MSIL to NativeMSIL to NativeCompilersCompilers
CodeCodeManagerManager
GarbageGarbageCollectionCollection
Security EngineSecurity Engine DebuggerDebugger
Class LoaderClass Loader
The .NET Framework Class LibraryThe .NET Framework Class Library
Spans All Programming LanguagesSpans All Programming Languages Enables cross-language inheritance and Enables cross-language inheritance and
debuggingdebugging Integrates well with toolsIntegrates well with tools
Is Object-Oriented and ConsistentIs Object-Oriented and Consistent Enhances developer productivity by Enhances developer productivity by
reducing the number of APIs to learnreducing the number of APIs to learn Has a Built-In Common Type SystemHas a Built-In Common Type System Is ExtensibleIs Extensible
Makes it easy to add or modify Makes it easy to add or modify framework featuresframework features
Is SecureIs Secure Allows creation of secure applicationsAllows creation of secure applications
Benefits of Using the .NET FrameworkBenefits of Using the .NET Framework
Based on Web standards and Based on Web standards and practicespractices
Functionality of .NET classes is Functionality of .NET classes is universally availableuniversally available
Code is organized into hierarchical Code is organized into hierarchical namespaces and classesnamespaces and classes
Language independentLanguage independent
Windows Windows APIAPI
ASPASP
.NET .NET FrameworkFramework
1980’s 1990’s 2000’s
Visual BasicVisual Basic
MFC/ATLMFC/ATL
ADO.NET: Data and XMLADO.NET: Data and XML
ADO.NET: Data and XMLADO.NET: Data and XML
OleDbOleDb SqlClientSqlClient
CommonCommon SQLTypesSQLTypes
System.Data
XSLXSLSerializationSerialization
XPathXPath
System.Xml
ASP.NETASP.NET
Web Forms and ServicesWeb Forms and Services
System.WebSystem.Web
ConfigurationConfiguration SessionStateSessionState
CachingCaching SecuritySecurity
ServicesServices
DescriptionDescription
DiscoveryDiscovery
ProtocolsProtocols
UIUI
HtmlControlsHtmlControls
WebControlsWebControls
The Process of Managed ExecutionThe Process of Managed Execution
Class LoaderClass LoaderClass LoaderClass Loader
JIT CompilerJIT Compilerwith optionalwith optionalverificationverification
JIT CompilerJIT Compilerwith optionalwith optionalverificationverification
ExecutionExecution
Security ChecksSecurity Checks
EXE/DLL(MSIL and
metadata)
EXE/DLL(MSIL and
metadata)
ClassLibraries
(MSIL and
metadata)
ClassLibraries
(MSIL and
metadata)
Trusted,pre-JITedcode only
Call to anuncompiled
method
Runtime Engine
ManagedNative Code
CompilerCompiler SourceCode
SourceCode
Just-In-Time CompilationJust-In-Time Compilation
Process for Code ExecutionProcess for Code Execution MSIL converted to native code as neededMSIL converted to native code as needed Resulting native code stored for subsequent Resulting native code stored for subsequent
callscalls JIT compiler supplies the CPU-specific JIT compiler supplies the CPU-specific
conversion conversion
AssembliesAssemblies
AssemblyAssembly
ManifestManifest
Multiple Managed Modules andResource FilesAre Compiled to Produce an Assembly
Managed Module(MSIL and Metadata)Managed Module
(MSIL and Metadata)
Managed Module(MSIL and Metadata)Managed Module
(MSIL and Metadata)
.html
.gif
Resource Files
Creating a Simple .NET Framework Creating a Simple .NET Framework ComponentComponent
Using Namespaces and Declaring the Using Namespaces and Declaring the ClassClass
Creating the Class ImplementationCreating the Class Implementation Implementing Structured Exception Implementing Structured Exception
HandlingHandling Creating a PropertyCreating a Property Compiling the ComponentCompiling the Component
Using Namespaces and Declaring Using Namespaces and Declaring the Classthe Class
Create a New NamespaceCreate a New Namespace
Declare the ClassDeclare the Class
using System;
namespace CompCS {...}
using System;
namespace CompCS {...}
public class StringComponent {...}public class StringComponent {...}
Creating the Class ImplementationCreating the Class Implementation
Declare a Private Field of Type Declare a Private Field of Type Array of String ElementsArray of String Elements
Create a Public Default ConstructorCreate a Public Default Constructor
Assign the stringSet Field to an Assign the stringSet Field to an Array of StringsArray of Strings stringSet = new string[] {
"C# String 0","C# String 1",
... };
stringSet = new string[] {"C# String 0","C# String 1",
... };
private string[] stringSet;private string[] stringSet;
public StringComponent() {...}public StringComponent() {...}
Implementing Structured Implementing Structured Exception HandlingException Handling
Implement the GetString MethodImplement the GetString Method
Create and Throw a New Object of Type Create and Throw a New Object of Type IndexOutOfRangeExceptionIndexOutOfRangeException
Exceptions Caught by the Caller Using a Exceptions Caught by the Caller Using a try/catch/finally Statementtry/catch/finally Statement
Structured Exception Handling Replaces Structured Exception Handling Replaces HRESULT-Based Error Handling in COMHRESULT-Based Error Handling in COM
public string GetString(int index) {...}public string GetString(int index) {...}
if((index < 0) || (index >= stringSet.Length)) {throw new IndexOutOfRangeException();
}return stringSet[index];
if((index < 0) || (index >= stringSet.Length)) {throw new IndexOutOfRangeException();
}return stringSet[index];
Creating a PropertyCreating a Property
Create a Read-Only Count Property to Get Create a Read-Only Count Property to Get the Number of String Elements in the the Number of String Elements in the stringSet ArraystringSet Array
public int Count { get { return stringSet.Length; }}
public int Count { get { return stringSet.Length; }}
Compiling the ComponentCompiling the Component
Use the /target:library Switch to Create a Use the /target:library Switch to Create a DLLDLL Otherwise, an executable with a .dll file Otherwise, an executable with a .dll file
extension is created instead of a DLL libraryextension is created instead of a DLL library
csc /out:CompCS.dll /target:library CompCS.cscsc /out:CompCS.dll /target:library CompCS.cs
Creating a Simple Console ClientCreating a Simple Console Client
Using the LibrariesUsing the Libraries Instantiating the ComponentInstantiating the Component Calling the ComponentCalling the Component Building the ClientBuilding the Client
Using the LibrariesUsing the Libraries
Reference Types Without Having to Reference Types Without Having to Fully Qualify the Type NameFully Qualify the Type Name
If Multiple Namespaces Contain the If Multiple Namespaces Contain the Same Type Name, Create a Same Type Name, Create a Namespace Alias to Remove Namespace Alias to Remove AmbiguityAmbiguity
using CompCS;
using CompVB;
using CompCS;
using CompVB;
using CSStringComp = CompCS.StringComponent;
using VBStringComp = CompVB.StringComponent;
using CSStringComp = CompCS.StringComponent;
using VBStringComp = CompVB.StringComponent;
Instantiating the ComponentInstantiating the Component
Declare a Local Variable of Type Declare a Local Variable of Type StringComponentStringComponent
Create a New Instance of the Create a New Instance of the StringComponent ClassStringComponent Class//…using CSStringComp = CompCS.StringComponent;//…CSStringComp myCSStringComp = new CSStringComp();
//…using CSStringComp = CompCS.StringComponent;//…CSStringComp myCSStringComp = new CSStringComp();
Calling the ComponentCalling the Component
Iterate over All the Members of Iterate over All the Members of StringComponent and Output the Strings StringComponent and Output the Strings to the Consoleto the Console
for (int index = 0; index < myCSStringComp.Count; index++) {
Console.WriteLine (myCSStringComp.GetString(index));
}
for (int index = 0; index < myCSStringComp.Count; index++) {
Console.WriteLine (myCSStringComp.GetString(index));
}
Building the ClientBuilding the Client
Use the /reference Switch to Reference Use the /reference Switch to Reference the Assemblies That Contain the the Assemblies That Contain the StringComponent ClassStringComponent Class
csc /reference:CompCS.dll,CompVB.dll /out:ClientCS.exe ClientCS.cs
csc /reference:CompCS.dll,CompVB.dll /out:ClientCS.exe ClientCS.cs
Memory Management BasicsMemory Management Basics
Developer BackgroundsDeveloper Backgrounds Manual vs. Automatic Memory Manual vs. Automatic Memory
ManagementManagement Memory Management of .NET Framework Memory Management of .NET Framework
TypesTypes Simple Garbage CollectionSimple Garbage Collection
Manual vs. Automatic Memory Manual vs. Automatic Memory ManagementManagement
Manual Memory ManagementManual Memory Management Programmer manages memoryProgrammer manages memory
Common ProblemsCommon Problems Failure to release memoryFailure to release memory Invalid references to freed memoryInvalid references to freed memory
.NET Runtime Provides Automatic .NET Runtime Provides Automatic Memory ManagementMemory Management Eases programming taskEases programming task Eliminates a potential source of bugsEliminates a potential source of bugs
Memory Management of .NET Memory Management of .NET Framework TypesFramework Types
Instances of Value Types Use Stack Instances of Value Types Use Stack MemoryMemory Allocation and deallocation are automatic and Allocation and deallocation are automatic and
safesafe Managed Objects Are Reference Types Managed Objects Are Reference Types
and Use Heap Memoryand Use Heap Memory Created by calls to the new operatorCreated by calls to the new operator Freed by garbage collectionFreed by garbage collection
Simple Garbage CollectionSimple Garbage Collection
Simple Garbage Collection AlgorithmSimple Garbage Collection Algorithm Wait until managed code threads are in a safe Wait until managed code threads are in a safe
statestate Build a graph of all reachable objectsBuild a graph of all reachable objects Move reachable objects to compact heapMove reachable objects to compact heap
- Unreachable objects’ memory is reclaimed- Unreachable objects’ memory is reclaimed Update references to all moved objectsUpdate references to all moved objects
Reference Cycles Are Handled Reference Cycles Are Handled AutomaticallyAutomatically
Multimedia: Simple Garbage Multimedia: Simple Garbage CollectionCollection
Non-Memory Resource Non-Memory Resource ManagementManagement
Implicit Resource ManagementImplicit Resource Management Explicit Resource ManagementExplicit Resource Management
• Implicit Resource ManagementImplicit Resource Management
FinalizationFinalization Garbage Collection with Finalization Garbage Collection with Finalization Finalization GuidelinesFinalization Guidelines Controlling Garbage CollectionControlling Garbage Collection
FinalizationFinalization
Finalize Code Called by Garbage Finalize Code Called by Garbage CollectionCollection
In C#, the Finalize Code Is Provided by a In C#, the Finalize Code Is Provided by a Destructor Destructor
Use C# Destructor to Implicitly Close a Use C# Destructor to Implicitly Close a FileStreamFileStream
class Foo { private System.IO.FileStream fs; //... public Foo() { fs = new System.IO.FileStream( "bar", FileMode.CreateNew); } ~Foo() { fs.Close(); }}
class Foo { private System.IO.FileStream fs; //... public Foo() { fs = new System.IO.FileStream( "bar", FileMode.CreateNew); } ~Foo() { fs.Close(); }}
Garbage Collection with Garbage Collection with FinalizationFinalization
Runtime Maintains a List of Objects That Runtime Maintains a List of Objects That Require FinalizationRequire Finalization Finalization queueFinalization queue
Garbage Collection Process InvokedGarbage Collection Process Invoked Unreachable Objects Requiring FinalizationUnreachable Objects Requiring Finalization
References added to freachable queueReferences added to freachable queue Objects are now reachable and not garbageObjects are now reachable and not garbage
Move Reachable Objects to Compact the Move Reachable Objects to Compact the HeapHeap Unreachable objects' memory is reclaimedUnreachable objects' memory is reclaimed
Update References to All Moved ObjectsUpdate References to All Moved Objects
Garbage Collection with Garbage Collection with Finalization (Finalization (continuedcontinued))
Finalize Thread RunsFinalize Thread Runs Executes freachable objects' Executes freachable objects' FinalizeFinalize methods methods References removed from freachable queueReferences removed from freachable queue Unless resurrected, objects are now garbageUnless resurrected, objects are now garbage May be reclaimed next time garbage collection May be reclaimed next time garbage collection
occursoccurs
Multimedia: Garbage CollectionMultimedia: Garbage Collection
Controlling Garbage CollectionControlling Garbage Collection
To Force Garbage CollectionTo Force Garbage Collection
To Suspend Calling Thread Until Thread’s Queue of To Suspend Calling Thread Until Thread’s Queue of Finalizers is Empty Finalizers is Empty
To Allow a Finalized Resurrected Object to Have Its To Allow a Finalized Resurrected Object to Have Its Finalizer Called AgainFinalizer Called Again
To Request the System Not to Call the Finalizer To Request the System Not to Call the Finalizer MethodMethod
void System.GC.Collect(); void System.GC.Collect();
void System.GC.WaitForPendingFinalizers(); void System.GC.WaitForPendingFinalizers();
void System.GC.ReRegisterForFinalize(object obj); void System.GC.ReRegisterForFinalize(object obj);
void System.GC.SuppressFinalize(object obj);void System.GC.SuppressFinalize(object obj);
The IDisposable Interface and the The IDisposable Interface and the Dispose MethodDispose Method
Inherit from the IDisposable InterfaceInherit from the IDisposable Interface Implement the Dispose MethodImplement the Dispose Method Follow the .NET Framework SDK’s Design Follow the .NET Framework SDK’s Design
PatternPattern
class ResourceWrapper : IDisposable{
// see code example for details}
class ResourceWrapper : IDisposable{
// see code example for details}
Overview of Overview of ASP.NETASP.NET
Overview of ASP.NETOverview of ASP.NET
What is ASP.NET?What is ASP.NET? ASP.NET Web ApplicationASP.NET Web Application Multimedia: ASP.NET Execution ModelMultimedia: ASP.NET Execution Model
What is ASP.NET?What is ASP.NET?
Evolutionary, more flexible successor to Evolutionary, more flexible successor to Active Server PagesActive Server Pages
Dynamic Web pages that can access Dynamic Web pages that can access server resourcesserver resources
Server-side processing of Web FormsServer-side processing of Web Forms XML Web services let you create XML Web services let you create
distributed Web applicationsdistributed Web applications Browser-independentBrowser-independent Language-independentLanguage-independent
ASP.NET Web ApplicationASP.NET Web Application
XML Data Database
InternetInternet
Page1.aspx
Page2.aspx
WebServices
WebServices ComponentsComponents
Web Forms
Code-behind pages
global.asax
Web.config
machine.config
ASP.NET Web Server
Out
put C
ache
Clients
Multimedia: ASP.NET Execution Multimedia: ASP.NET Execution ModelModel
Creating Web FormsCreating Web Forms
What is a Web Form? What is a Web Form? Creating a Web Form with Visual Creating a Web Form with Visual
Studio .NETStudio .NET
What Is a Web Form?What Is a Web Form?
<%@ Page Language="vb" Codebehind="WebForm1.aspx.vb" <%@ Page Language="vb" Codebehind="WebForm1.aspx.vb" SmartNavigation="true"%>SmartNavigation="true"%>
<html><html><body ms_positioning="GridLayout"><body ms_positioning="GridLayout"> <form id="Form1" method="post" runat="server"><form id="Form1" method="post" runat="server"> </form></form></body></body>
</html></html>
<%@ Page Language="vb" Codebehind="WebForm1.aspx.vb" <%@ Page Language="vb" Codebehind="WebForm1.aspx.vb" SmartNavigation="true"%>SmartNavigation="true"%>
<html><html><body ms_positioning="GridLayout"><body ms_positioning="GridLayout"> <form id="Form1" method="post" runat="server"><form id="Form1" method="post" runat="server"> </form></form></body></body>
</html></html>
.aspx extension.aspx extension Page attributesPage attributes
@ Page@ Page directive directive Body attributesBody attributes Form attributesForm attributes
Using Server ControlsUsing Server Controls
What is a Server Control?What is a Server Control? Types of Server ControlsTypes of Server Controls HTML Server Controls HTML Server Controls Web Server Controls Web Server Controls Selecting the Appropriate ControlSelecting the Appropriate Control
What is a Server Control?What is a Server Control?
Runat="server"Runat="server" Events happen on the serverEvents happen on the server View state savedView state saved
Have built-in functionalityHave built-in functionality Common object modelCommon object model
All have All have IdId and and TextText attributes attributes Create browser-specific HTMLCreate browser-specific HTML
<asp:Button id="Button1" runat="server" <asp:Button id="Button1" runat="server" Text="Submit"/>Text="Submit"/><asp:Button id="Button1" runat="server" <asp:Button id="Button1" runat="server" Text="Submit"/>Text="Submit"/>
Types of Server ControlsTypes of Server Controls
HTML server controlsHTML server controls Web server controlsWeb server controls
Intrinsic controlsIntrinsic controls Validation controlsValidation controls Rich controlsRich controls List-bound controlsList-bound controls Internet Explorer Web controlsInternet Explorer Web controls
HTML Server ControlsHTML Server Controls
Based on HTML Based on HTML elementselements
Exist within the Exist within the System.Web.UI.HtmlCSystem.Web.UI.HtmlControls namespaceontrols namespace
<input type="text" id="txtName" runat="server" />
<input type="text" id="txtName" runat="server" />
Web Server ControlsWeb Server Controls
Exist within theExist within the System.Web.UI.WebContSystem.Web.UI.WebControls namespacerols namespace
Control syntaxControl syntax
HTML that is generated by HTML that is generated by the controlthe control
<asp:TextBox id="TextBox1"runat="server">Text_to_Display</asp:TextBox>
<asp:TextBox id="TextBox1"runat="server">Text_to_Display</asp:TextBox>
<input name="TextBox1" type="text" value="Text_to_Display"Id="TextBox1"/>
<input name="TextBox1" type="text" value="Text_to_Display"Id="TextBox1"/>
You need specific functionality such as a calendar or ad rotator
The control will interact with client and server script
You are writing a page that might be used by a variety of browsers
You are working with existing HTML pages and want to quickly add ASP.NET Web page functionality
You prefer a Visual Basic-like programming model
You prefer an HTML-like object model
Use Web Server Use Web Server Controls if:Controls if:
Use HTML Server Use HTML Server Controls if:Controls if:
Bandwidth is not a problemBandwidth is limited
Selecting the Appropriate ControlSelecting the Appropriate Control
Overview of Overview of ADO .NETADO .NET
Overview of ADO.NETOverview of ADO.NET
Connected ApplicationsConnected Applications Disconnected ApplicationsDisconnected Applications
Evolution of ADO to ADO.NETEvolution of ADO to ADO.NET
ConnectionConnection
AD
OA
DO
.NET
CommandCommand
RecordsetRecordset
XxxConnectionXxxConnection
XxxCommandXxxCommand
DataSetDataSet
XxxTransactionXxxTransaction
XxxDataReaderXxxDataReader
XxxDataAdapterXxxDataAdapter
Object Model for Connected Object Model for Connected ApplicationsApplications
Data Source
XxxConnection
XxxParameter
XxxDataReaderXxxCommand
XxxParameterXxxParameter
XmlReader
Classes in a Connected Application
Disconnected ArchitectureDisconnected Architecture
Employees OrdersCustomersProductsCategories
Categories Products
SqlDataAdapter OleDbDataAdapter
SQL Server 2000
Customers Orders
SQL Server 6.5
DataSet
XML Web service
XML Web service
XmlDataDocumentXML File
XML File
What Is a DataAdapter?What Is a DataAdapter?
Data sourceDataAdapterDataTable
DataTable
DataSet
DataAdapter
FillFill
UpdateUpdateFillFill
UpdateUpdate
The XxxDataAdapter Object ModelThe XxxDataAdapter Object Model
sp_SELECT
XxxCommandXxxCommand
SelectCommand UpdateCommand InsertCommand DeleteCommand
XxxDataAdapter
XxxCommandXxxCommand XxxCommandXxxCommand XxxCommandXxxCommand
XxxConnectionXxxConnection
sp_UPDATE sp_INSERT sp_DELETE
XxxDataReaderXxxDataReader
Overview of Overview of Web ServicesWeb Services
OverviewOverview
Service-Oriented ArchitectureService-Oriented Architecture Web Service Architectures and Service-Web Service Architectures and Service-
Oriented ArchitectureOriented Architecture Roles in a Web Service ArchitectureRoles in a Web Service Architecture The Web Service Programming ModelThe Web Service Programming Model
What Is an XML Web Service?What Is an XML Web Service?
SOAPSOAPSOAPSOAP XML Web services consumers can send and
receive messages using XML
WSDLWSDLWeb Services Web Services
Description LanguageDescription Language
WSDLWSDLWeb Services Web Services
Description LanguageDescription Language
XML Web services are defined in terms of the formats and ordering of messages
Built using open Internet protocols XML & HTTPXML & HTTP
UDDIUDDIUniversal Description, Universal Description,
Discovery, and IntegrationDiscovery, and Integration
UDDIUDDIUniversal Description, Universal Description,
Discovery, and IntegrationDiscovery, and Integration
Provide a Directory of Services on the Internet
A programmable application component A programmable application component accessible via standard Web protocolsaccessible via standard Web protocols
OpenOpen Internet Internet Protocols Protocols
XML Web XML Web serviceservice
Service-Oriented ArchitectureService-Oriented Architecture
ServiceBroker
ServiceConsumer
ServiceProvider
Bind
Publi
sh
Find
Web Service Architectures and Web Service Architectures and Service-Oriented ArchitectureService-Oriented Architecture
Overview of Web Service ArchitecturesOverview of Web Service Architectures Web Services as a Service-Oriented Web Services as a Service-Oriented
Architecture Implementation Architecture Implementation Demonstration: An Electronic Funds Demonstration: An Electronic Funds
Transfer Web Service SolutionTransfer Web Service Solution
ServiceBroker
Publ
ish Find
ServiceConsumer
ServiceProvider
Web Service Provider Web Service Consumer
UDDI(Web Service Broker)
Bind
Internet
Overview of Web Service Overview of Web Service ArchitecturesArchitectures
Web Services as a Service-Oriented Web Services as a Service-Oriented Architecture ImplementationArchitecture Implementation
UDDI
AnyClient
SOAP
SOAP
.NET Web Service
SOAP
IIS
Roles in a Web Service Roles in a Web Service ArchitectureArchitecture
The Web Service ProviderThe Web Service Provider The Web Service ConsumerThe Web Service Consumer The Web Service BrokerThe Web Service Broker
The Web Service ProviderThe Web Service Provider
Web ServersWeb Servers The .NET Common Language RuntimeThe .NET Common Language Runtime
The Web Service ConsumerThe Web Service Consumer
Minimum FunctionalityMinimum Functionality Service LocationService Location ProxiesProxies Synchronous vs. Asynchronous CallsSynchronous vs. Asynchronous Calls
The Web Service BrokerThe Web Service Broker
Interactions Between Broker and ProviderInteractions Between Broker and Provider Interactions Between Broker and Interactions Between Broker and
ConsumerConsumer UDDI Registries UDDI Registries
Questões ???????Questões ???????