Title: Microsoft .NET
1Microsoft .NET
Junhui wang July 10, 2003
2Outline
- Introduction to MS.NET
- .NET Framework
3What is MS .NET
- Old .NET is the Microsoft platform for XML Web
service. - New .NET is the set of Microsoft technologies
for connecting your world of information,people,sy
stems and devices. - .NET is infused into the Microsoft platform
providing the ability to build,host,deploy and
consume XML Web service connected solutions.
4Why MS .NET
- .Interoperability between languages and execution
environments - .Uniformity in schema or formats for Data
Exchange using XML,XSL - .Extend or use existing code that is valid
- .Programming complexity of environment is reduced
5Services provided by MS .NET
- A new run-time environment, the .NET
Framework - A new programming model for constructing HTML
pages, named ASP.NET - A new way for Internet servers to expose
functions to any client, named XML Web services - Windows Forms, a new way of writing rich client
applications using the .NET framework - Support for db access within the .NET
framework,namely ADO.NET - Support for handling XML documents and streams
- A standardized mechanism for signaling
asynchronous events - Support for writing multithreaded code
- Support for writing your own Windows Forms
and Web Forms controls -
6Component of MS .NET
- .NET spans clients,servers and develop tools
- .NET framework
- .Developer tools
- such as MS visual studio.NET 2003
- . A set of servers
- including MS Windows server 2003,MS
SQL server - .Client software
- such as Windows XP
7What is .NET Framework
- .NET framework is an integral Windows component
for building and running all kinds of
software,including web-based applications,smart
client applications and XML Web services. - . Support over 20 different programming
languages. - . Manages much of the plumbing involved in
developing - software,enabling developers to focus on the
core business logic code. - . Makes it easier than ever before to
build,deploy,and administer secure,robust and
high-performing applications.
8Component of .NET Framework
- . Common Language Runtime(CLR)
- . A unified set of class libraries
9 .NET Framework Architecture
Microsoft .NET provides prefabricated
infrastructure for solving the common problems of
writing Internet software.
10Common Language Runtime
- Provide the common services for .NET framework
- Run-time
- .Language integration
- .Security enforcement
- .Memory management
- .Process management
- . Thread management
- Developing time
- .Life-cycle management
- .Strong type naming
- .Cross-language exception handling
- . Dynamic binding reduce the amount of code
11CLR Execution Model
Source code
VB
C
C
Unmanaged Component
Compiler
Compiler
Compiler
Managed code
Assembly IL Code
Assembly IL Code
Assembly IL Code
Common Language Runtime
JIT Compiler
Native Code
Operating System Services
12Class Library
- ASP.NET building Web applications and Web
services - ADO.NET connecting applications to database
- Windows Forms an environment for building smart
client applications - System Class XML,security,network,messaging
13 14 ADO.NET features
- Designed for disconnected access
- Can model data logically!
- The DataSet replaces the RecordSet
- DataSet can contain multiple tables
15Core Concepts and Architecture
- The ADO.NET Object Model
- DataSet objects
- Managed providers
- ADO.NET-related Namespaces
- System.Data
- System.Data.ADO
- System.Data.Internal
- System.Data.SQL
- System.Data.SQLTypes
16 ADO.NET Objects
.NET Applications
Data Set
Data Reader
Command Object
Connection Object
Managed Data Provider (OLEDB)
Database
17ADO.NET and Managed Providers
- A collection of classes for accessing data
sources - Microsoft SQL Server 2000, SQL Server 7, and
MSDE - Any OLE Database (OLE DB) providers
- Including Oracle, JET, and SQL OLE DB Providers
- Establish connection between DataSets and data
stores - Two managed providers
- ADO via the System.Data.ADO namespace
- SQL Server via the System.Data.SQL namespace
- System.Data.ADO is the ADO.NET managed provider
18Connection with a Connection Object
- A connection object represents a unique session
with a data source. - Connection string database, OLE DB provider,
password, etc. - Use the Open/Close method to open/close a
connection.
19Connection String
- Containing information about database, OLE DB
provider, password, if any, security, etc. - For Jet database
- ProviderMicrosoft.Jet.OLEDB.4.0Persist Security
info FalseData Sourcec\ \Nwind.mdb
20Connection Object
- Example
- dim strConn as string "ProviderMicrosoft.Jet.OLE
DB.4.0Data Source c\sales2k.mdb" - dim objConn as new ADOConnection(strConn)
- objConn.open()
- Basic Methods
- Open, Close
21Command Object
- The command object allows us to execute a SQL
statement. - Properties
- CommandType SQL or stored procedure
- CommandText SQL statement
- Connection
- Basic Methods
- ExecuteReader Creates a DataReader object that
contains the results of the query. - ExecuteNonQuery Execute SQLs INSERT, DELETE,
UPDATE statements.
22DataReader Object
- It is read-only and forward-only cursor.
- Basic Methods
- Read Reads the current record and advances the
pointer to the next record. - Close Closes the dataReader.
23ADODataReader Sample
// Code for creating the ADOConnection adoConn
not shown String myQuery SELECT FROM
Customers adoConn.Open() ADOCommand myCmd
new ADOCommand( myQuery,adoConn ) // Declare the
ADODataReader... ADODataReader myDataReader //
Instantiate the ADODataReader with Execute(...)
... myCmd.Execute(out myDataReader) // Always
call Read before accessing data.
while(myDataReader.Read()) //code //
Always Close the reader and the connection when
done myDataReader.Close() adoConn.Close()
24DataSet Object
- A DataSet object can hold several tables and
relationships between tables. - A DataSet is a set of disconnedted data. Data is
extracted from the database and stored in the
DataSet object. Updates to the DataSet must copy
back to the database to make the changes
permanent.
25 DataSet and Related Objects
DataView
DataSet
DataTable
DataTable
Command
DataAdapter
Connection
26 DataSet and Related Objects
- DataSet Can contain multiple tables and
relationships. - DataTable object Represents a table in the
dataset. - DataAdapter This the object used to pass data
between the database and the dataset. The Fill
method copies the data into the dataset, and the
Update method copies the updates back into the
database.(datasetcom) - DataView This represents a specific view of the
DataTables held in the dataset.
27System.DataDataSet and XML
- DataSet can read/write XML for its data and/or
schema - Means You can create or modify a DataSet using
XML! - XML-related DataSet methods for reading
- ReadXml Reads an XML schema and data into the
DataSet - ReadXmlData Reads XML data into the DataSet
- ReadXmlSchema Reads an XML schema into the
DataSet - And for writing WriteXml, WriteXmlData,
WriteXmlSchema
28Methods of Reading and Writing XML
// Code for creating the DataSet mds and loading
the // DataSet from a data source not shown.
String oFile C\\My_ADO.NET\\myXmlOutput.xsd
String iFile C\\My_ADO.NET\\myXmlInput.xsd
// Write the DataSets XMLSchema to an XML
Document mds.WriteXmlSchema( oFile ) //
Read/Upload XML Data into the DataSet mds.ReadXmlD
ata( iFile, true ) // Write the existing Data
to an XML Document mds.WriteXmlSchema(
C\\My_ADO.NET\\myXmlData.txt ) // Or output
the XML Data using the XmlData property! Console.W
riteLine( mds.XmlData )
29 30ASP.NET
- ASP.NET is a new programming framework designed
to make web apps easier to - Build, Deploy, Run
- Radical advancement of todays ASP
- Broader programming language support
- Visual Basic.NET, Jscript.NET, C
- Form-based programming model(similar to VB form)
- Event driven programming
- Programmable control
- New application model
- XML Web service
- Mobile Web device support
- Better reliability and recovery
- Excellent Visual Studio support
31ASP.NET Cont.
- Improved performance scalability
- ASP.NET is compiled, not interpreted
- Rich output caching
- Session state can now be shared across a web form
of ASP.NET servers - .NET State Server Process manages state
- ASP.NET detects and recovers from problems
- Access violations, memory leaks, dead
32ASP.NET Application
- Web formsbuilding powerful forms-based Web pages
- XML Web Services providing the means to access
server functionality remotely. - Combinations
33Web Forms
- The visual component(Web Form Pages)
- consists of a file(.aspx extension)
- (1)static HTML
- (2) ASP.NET server controls
- HTML server controls
- Web server controls
- Validation controls
- user controls
- (3) both.
- The logic for the Web Form page(code)
- separate file(.aspx.vb or .aspx.cs extension)
34.NET Web Services
- NET is built on Internet standard protocols
- Uses Framework classes, such as
- System.Web.Services
- Enables communication through open standards
- XML
- Service description expressed with WSDL
- SOAP
- Basic wire format
- Universal Description Discovery Integration
(UDDI) - HTTP
35Define XML Web Services
-
- To create an XML Web service, simply write a .NET
object as if it were being accessed directly by
local clients, mark it with an attribute that
says this object should be available to Web
clients, and ASP.NET will do the rest. - ASP.NET automatically hooks up a prefabricated
infrastructure that accepts incoming requests
through HTTP and maps them to calls on the object
36ASP.net for XML Web Services
- Creating a Web service
- 1. Create a file with an .asmx file name
extension . - 2.Within the file ,declare the XML web
service using directive - 3.Define the XML service methods that compose
the functionality of the XML Web service - Creating a discovery file
- Create a XML document with a .DISCO
extension - (not compulsory to create)
37Server-side view of XML Web services
Windows 2000 server machine
with .NET
- HTTP requests arrive, with method name and
parameters encoded in URL or separate XML. - 5. ASP.NET converts results to XML and returns to
client via HTTP.
2. ASP.NET creates object specified in .ASMX file.
3. ASP.NET calls specified method on object.
.NET object Method 1..Method N
4. Object returns results to ASP.NET.
38Client-side view of XML Web services
0. At programming time, a developer generates
proxyobject code from a description of an XML
Web service.
- Client Program
- At run time, client creates proxy object.
- Client calls method on proxy.
Proxy 3. Proxy converts call to HTTP and XML and
sends it to server over the Internet. 4. Proxy
receives results in XML over HTTP and converts to
function return value.
To/from server via Internet
5. Client receives return value from proxy.
39Example building a Web Service
- lt_at_ WebService Language"VB" Class"TimeService"gt
- Imports System
- Imports System.Web.Services
- Public Class TimeService Inherits WebService
- ltWebMethod()gt Public Function GetTime
(ShowSeconds as Boolean) As String - If (ShowSeconds TRUE) Then
- return DateTime.Now.ToLongTimeString
- Else
- return DateTime.Now.ToShortTimeString
- End if
- End Function
- End Class
40Describing XML Web Services by WSDL File
- To develop client applications that uses the XML
Web services, programmers need a description of
what the service does and how to use the service
(e.g. methods exposed, parameters required by
those methods, protocols supported) - Problem a universal approach not restricted to
the MS world of describing a service is needed! - Solution The ASP.NET can generate such a
description in the form of a WSDL (Web Service
Description Language) file. - To obtain the WSDL file from ASP.NET, request the
.asmx file with ?WSDL attached to the URL. - Alternatively, the developer can write the WSDL
file first or obtain it from a 3rd party to
describe what the service should do, and use the
SDK utility program wsdl.exe to generate a
template file. - The client application developer will probably
not deal with raw WSDL files but rather use them
through interpretive tools to develop client
application. - The WSDL file also shows the supported protocols
and how to access the service via these protocols
from the client application.
41Building XML Web Service Clients
- ASP.NET funnels incoming requests to XML Web
service objects packaged in 3 different ways - HTTP GET
- HTTP POST
- SOAP (Simple Object Access Protocol)
- SOAP is easier and more powerful than the other
two methods. - A Web service client formats a SOAP request
packet - The client sends the SOAP request to the XML Web
service via an HTTP POST operation. - The XML Web service parses the request, create
the object, call the method with the specified
parameters, and return a SOAP response to the Web
service client.
42Calling a Web Service via SOAP
- A client-side SOAP proxy class makes client
applications much easier to write - The .NET Framework SDK provides wsdl.exe to
generate proxy class from the WSDL file for
accessing the methods in the specified language. - Visual Studio .NET uses the proxy class generator
internally. - Create a Windows Forms project
- Add the XML Web service page as a Web Reference
to the project. This will run wsdl.exe internally
and ask for a SOAP-based proxy in the language of
the project. - Visual Studio then displays the namespace of the
proxy class in Solution Explorer. - To access the XML Web service from the client,
simply create an object of the proxy class and
call the desired method on it.
43Web Service Discovery
- This is the aspect of making the presence and
capabilities of a Web Service known to the world. - This is the UDDI (Universal Discovery,
Description, and Integration) business registry
service. - Initiated by Ariba, IBM, and Microsoft.
Supported by more than 130 companies. - Provides a standard place to register Web
Services. Check out www.uddi.org. - UDDI is a specification built on SOAP/XML and
defines a document format and protocol for
searching and retrieving discovery documents -
which in turn link to DISCO documents. - DISCO (Discovery of Web Services) is a Microsoft
protocol for retrieving the contracts for Web
Services (WDSL documents).
44Calling a Web Service via HTTP Get
- By requesting a Web Service URL from the IE
Address field, ASP.NET will respond with a
neatly-formatted page that describes the Web
Service and its methods. This page even
provides a simple means to run the methods. - This is not UDDI or DISCO. Just a
nicely-formatted page built from the metadata. - You can get the WSDL by appending ?wsdl to the
URL. - To call a method, append the method name and
parameters to the URL like this - /MethodName?ParmValueNextParmNextValue
- e.g. http//localhost/timeservice/TimeServiceVB.as
mx/GetTime?ShowSecondsFALSE - Calling the service in this manner will result in
a simple XML response containing the return value.
45Calling a Web Service via HTTP Post
- The WSDL describes the requirements for doing
this. - The Web Service expects that the incoming
parameter values be contained in FORM fields with
specific names. Therefore, the FORM has to
contain INPUT elements named according to the
WSDL. The ACTION attribute names the method - ltFORM MethodPost ActionTimeServiceVB.asmx/Get
Timegt - The response is an XML string.
46 47Visual Studio .NET
- Increased programming productivity
- Easier to write code drag and drop Web App and
Services Development. - Fully supports the .NET Framework
- Simplified development
- Multi-language support
- Improved debugging
- Unified IDE
- Powerful design tools
- Windows Forms, Web Forms
- XML and component designers
- Consistent set of tools across languages
48Visual Studio.NET
- Integrated Development Environment
- Visual Basic.NET
- Many language enhancements
- Inheritance,Overloading, Free Threading
- Visual C
- Integration with .NET Framework with managed
extensions (classes) - C
- New development language
- Based on C/C with Garbage Collection/Memory
Management - JUMP (Java User Migration Path) to .NET (1/25/01)
- Visual J has been removed from the Visual
Studio suite.
49VS.NET Features
- Single IDE for all Languages
- Server Explorer
- Event Viewer, Message Queues, Services
- SQL Databases, Data Connection, Etc.
- Integrated IE Browser
- HTML/XML Editors
- Macros/Macro Explorer
- Solution Explorer
- Tabbed Documents
- Dynamic Help
- Common Forms Editor
- VB.NET, C, and C
50Reference
- 1.http//www.microsoft.com
- 2.http//www.15seconds.com
- 3.http//asp.net
- 4.http//ado.net