Docstoc
EXCLUSIVE OFFER FOR DOCSTOC USERS
Try the all-new QuickBooks Online for FREE.  No credit card required.

.net

Document Sample
.net Powered By Docstoc
					     Microsoft .NET




Junhui wang
July 10, 2003
Outline
   Introduction to MS.NET
   .NET Framework
What 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,systems and devices.
  .NET is infused into the Microsoft platform
   providing the ability to build,host,deploy and
   consume XML Web service connected
   solutions.
Why 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
Services 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
Component 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
What 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.
Component of .NET Framework
. Common Language Runtime(CLR)
. A unified set of class libraries
.NET Framework Architecture
   What is .NET anyway?




                Microsoft .NET provides
                      prefabricated
               infrastructure for solving
                the common problems
                   of writing Internet
                        software.
Common 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
  CLR: Execution Model
Source      VB             C#            C++
code
          Compiler       Compiler      Compiler   Unmanaged
                                                  Component
Managed   Assembly      Assembly       Assembly
code       IL Code       IL Code        IL Code



   Common Language Runtime

                     JIT Compiler

                         Native Code

                     Operating System Services
Class 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
ADO.NET
    ADO.NET features

   Designed for disconnected access
   Can model data logically!
   The DataSet replaces the RecordSet
   DataSet can contain multiple tables
    Core 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
ADO.NET Objects
       .NET Applications


     Data Set     Data Reader

        Command Object

        Connection Object

       Managed Data Provider
            (OLEDB)

            Database
    ADO.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
Connection 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.
Connection String
   Containing information about database, OLE DB
    provider, password, if any, security, etc.
   For Jet database:
      Provider=Microsoft.Jet.OLEDB.4.0;Persist Security

       info = False;Data Source=c:\ …\Nwind.mdb
Connection Object
   Example:
       dim strConn as string ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source =
        c:\sales2k.mdb"
       dim objConn as new ADOConnection(strConn)
       objConn.open()

   Basic Methods:
       Open, Close
Command 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 SQL’s INSERT, DELETE, UPDATE

       statements.
DataReader 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.
     ADODataReader 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();
DataSet 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.
DataSet and Related Objects
           DataView


           DataSet
           DataTable
           DataTable


           Command


           DataAdapter


           Connection
     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.
    System.Data—DataSet 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
 Methods 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 DataSet’s XMLSchema to an XML Document
mds.WriteXmlSchema( oFile );

// Read/Upload XML Data into the DataSet
mds.ReadXmlData( 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.WriteLine( mds.XmlData );
ASP.NET
    ASP.NET
   ASP.NET is a new programming framework designed to make web
    apps easier to:
      Build, Deploy, Run

   Radical advancement of today’s 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
    ASP.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
ASP.NET Application

     Web forms:building powerful forms-based
      Web pages
     XML Web Services :providing the means to
      access server functionality remotely.
     Combinations
Web 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)
.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
Define 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
ASP.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)
        Server-side view of XML Web services
1. HTTP requests arrive, with       Windows 2000 server machine
   method name and                           with .NET
   parameters encoded in
   URL or separate XML.
                                    2. ASP.NET creates object
                                    specified in .ASMX file.
5. ASP.NET converts results to
    XML and returns to client                3. ASP.NET calls specified
    via HTTP.                                method on object.
                       4. Object returns                    .NET object
                       results to ASP.NET.
                                                         Method 1
                                                         .
                                                         .
                                                         Method N
Client-side view of XML Web services
0. At programming time, a developer generates proxy
object code from a description of an XML Web service.
                Client Program
   1. At run time, client creates proxy object.
   2. Client calls method on proxy.


                      Proxy
                                                        To/from server
                      3. Proxy converts call to HTTP    via Internet
   5. Client receives and XML and sends it to
   return value       server over the Internet.
   from proxy.
                      4. Proxy receives results in
                      XML over HTTP and converts
                      to function return value.
Example: building a Web Service
<%@ WebService Language="VB" Class="TimeService"%>

Imports System
Imports System.Web.Services

Public Class TimeService : Inherits WebService

<WebMethod()> 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
Describing 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.
Building 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.
    1.   A Web service client formats a SOAP request packet
    2.   The client sends the SOAP request to the XML Web service via an
         HTTP POST operation.
    3.   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.
Calling 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.
Web 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).
Calling 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 it’s 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?Parm=Value&NextParm=NextValue…
    e.g.
       http://localhost/timeservice/TimeServiceVB.asmx/GetTime?ShowSe
       conds=FALSE
   Calling the service in this manner will result in a simple
    XML response containing the return value.
Calling 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:
       <FORM Method=“Post” Action=“TimeServiceVB.asmx/GetTime”>
   The response is an XML string.
Visual studio.NET
Visual 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
Visual 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.
VS.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#
Reference
1.http://www.microsoft.com
2.http://www.15seconds.com
3.http://asp.net
4.http://ado.net

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:6
posted:11/8/2011
language:English
pages:50