Web Services Overview

Download Report

Transcript Web Services Overview

Visual Basic.NET
Taking the Most Successful Language
One Step Further
Objectives
 Introduction
to Microsoft Visual Basic.NET

New concepts

Changes
 Integration
 Tools
into .NET
Contents
 Section
1: Overview
 Section
2: Language Features
 Section
3: Integration into .NET
 Section
4: Putting It All Together
 Summary
Section 1: Overview
 Make

the language even easier to use
...at least easier to learn
 Get
rid of some design flaws
 Add
full set of object-oriented programming features
 Make
 ...but
it a first-class citizen of the .NET world
don't reinvent the language
First-Class Object Orientation
 Concept
of classes and interfaces

Inheritance

Overloading

Shared members

Constructors and initializers

Sub New()

anObject = New Class(“Data”, data)
 Object-oriented
event system
Inheritance Concepts
 Concept

Composition (Has-A)


of Reuse
MyForm
Control
MyForm Has-A Control
Inheritance (Is-A)

MyForm Is-A EntryForm
 Building
Form
Type Hierarchies
 Versioning
 Polymorphism
EntryForm
MyForm
MyNewForm
Section 2: Language Features
 Type
System
 Classes
and Inheritance
 Exception
 Event
Handling
Concept
 Changes
Type System
 Uses

No need for marshalling between languages
 Every

Primitives, enumerations, structures
Reference Types:


type is either a value or a reference type
Value types:


the .NET common type system
Classes, modules, interfaces, arrays, delegates, and strings
Object can contain both

Everything implicitly inherits from System.Object
Primitive Types
 Integral
Types

Byte (8 bits), Short (16 bits)

Integer (32 bits), Long (64 bits)
 Floating-Point

Single (4 bytes), Double (8 bytes)
 Exact

Types
Numeric Type
Decimal (28 digits) (replaces Currency)
 Boolean,
 String
 Signed
Date, Char
(Reference Type!)
bytes and unsigned integers not supported
Enumerations
 Symbolic
 Strongly
 Based
name for a set of values
typed
on integral type

Byte, Short, Integer, or Long

Integer is default
 Example:
Enum Color As Byte
red
yellow
green
End Enum
Arrays
 Built
on .NET System.Array class
 Defined
with type and shape
Dim OneDimension(10) As Integer
Dim TwoDimensions(20,intVal) As Integer
 Declaration
only syntax
Dim anArray() As Integer
ReDim anArray(10)
 Lower
bound index is always zero
 Fixed
size no longer supported
 Rank
cannot be changed
Interfaces
 Declare

semantic contracts between parties
Enable component orientation
 Define
structure and semantics for specific purpose
 Abstract
definitions of methods and properties
 Support
(multiple) inheritance
 Example: Interface IPersonAge
Property YearOfBirth() As Integer
Function GetAgeToday() As Integer
End Interface
Classes
 Concept
for objects: data and code
 Classes
contain members:

Data members: variables, constants

Properties: values accessed through get/set
methods

Methods: functionality for object or class


Subs and Functions
Specials: events, delegates, constructor
 Concept

of Overloading
Method Overloads another

With same name, but different parameters
Accessibility
 Each

Private


Access from same assembly
Protected Friend


Additional access by derived classes
Friend


Restricted to context of declaration
Protected (class members only)


member can have its own accessibility
Union of Protected and Friend access
Public

No restrictions
Properties
 Not a storage location—can be computed
Public Class Sample
Private m_val as Integer
Public Property val() as Integer
Get
return m_val
End Get
Set
m_val = value
End Set
End Property
End Class
 Usage
like data members
intVal = Sample.val
 Can
be ReadOnly or WriteOnly
Sample Class Definition
Public Class Customer
Implements ICustomer
Private CustomerNo As String
Public Property Customer() As String
Get
Return CustomerNo
End Get
Set
CustomerNo = Customer
End Set
End Property
Public Overloads Sub New()
End Sub
Public Overloads Sub New(ByVal par as Integer)
MyBase.New(par)
End Sub
Public Sub DoAny(ByVal c as Char) Implements ICustomer.DoAny
End Sub
End Class
Inheritance 1/2
 Single
base class, but multiple base interfaces
Public Class DerivedClass
Inherits BaseClass
Implements IBase1, IBase2
...
End Class
 Abstract
base classes
Public MustInherit Class AbstractBase
...
End Class
 Non-inheritable
classes
Public NotInheritable Class FinalClass
...
End Class
Inheritance 2/2
 Overrides

Method overrides another with same signature
 NotOverridable

(default)
Cannot be overridden
 MustOverride

Must be overridden – empty method body
 Qualified

access
MyClass, MyBase
Structures
 User-defined
 Lightweight
types—replace Type
“Classes“

Consists of the same members

Is value types, Classes are reference types

Can implement Interfaces

Can not be inherited
Public Structure Customer
Implements ICustomer
Public CustomerNo, Name As String
Public Sub New()
End Sub
Public Sub Do(ByVal c as Char) Implements ICustomer.Do
End Sub
End Structure
Exception Handling
 Exceptions
 Two
are not necessarily errors
styles: structured (SEH) and unstructured (UEH)
 Only
one style allowed in a method
 UEH
supported for backward compatibility

On Error, Resume, Error

Microsoft.VisualBasic.Information.Err
Structured Exception Handling
 Exceptions

are system concepts
Propagated between components
 Syntactical
form of handling:
Try
<something risky>
Catch e As Exception
<recover from the exception>
Finally
<execute this regardless>
End Try

Can define custom exceptions

Derived from System.Exception
 Exceptions

Throw
can be user-defined and thrown explicitly
Delegates
 Object-oriented
 Can
function pointers
point to a specific method of a specific instance
Delegate Function CmpFunc(x As Integer, y As Integer) As Boolean
Public Function Cmp(x As Integer, y As Integer) As Boolean
... (This function implemented in some class)
End Function
Sub Sort(Sort As CmpFunc, ByRef IntArray() As Integer)
...
If Sort.Invoke(IntArray(i), Value) Then
... Exchange values
End If
...
End Sub
Call Sort( new CmpFunc( AddressOf aObj.Cmp), AnArray)
Events
 Traditional
WithEvents style still supported
Private WithEvents mW As Widget
Public Sub mW_MouseHover(...) Handles mW.MouseHover
 New

event system based on .NET Framework
Implemented on top of delegates
 Multicast
events
 Dynamic
hookup of method as handler

AddHandler, RemoveHandler
 Many
events can be routed to same method
Simpler, More Consistent
 Boolean
operators

And, Or, Xor, and Not are still bitwise

AndAlso and OrElse added for short-circuiting
 More
obvious declarations

Visual Basic 6: Dim i,j as Integer
i is Variant, j is Integer

Visual Basic.NET: Dim i,j as Integer
i and j are Integer
 Variables
 No
declared in a block have block scope
implicit object creation—must use New
More Robust
 Strict

type checking
Implicit and explicit type conversions
Dim Base as CBase
Dim Derived as CDerived = new CDerived()
Base = Derived

Option Strict

Option Explicit
 Optional

parameters must have default values
Sub Calculate(Optional ByVal
param As Boolean = False)
Better Performance
 Supports

free threading
More responsiveness
 Short-circuit

evaluation
X = A AndAlso B AndAlso (C OrElse D)
 Reference
assignment for arrays
Some Other Changes
 Parentheses

Always required for function and procedure calls
 Default
parameter passing method is now ByVal
 Properties

around nonempty parameter lists
as reference parameters
Changes are now reflected back
 Gosub/Return
 Default
data types no longer supported
 Arithmetic
 Late
no longer supported
operator shortcuts: x += 7
binding
Deterministic Finalization
 An

 No
object used to be destroyed automatically
Just at the moment it is no longer needed
longer available with Visual Basic.NET:

No automatic reference counting behind the scenes

Objects are destroyed at garbage collector’s choice

Resources may stay locked virtually forever
 One

possible solution:
Provide your own reference counting and disposal scheme
 Make
your objects stateless
Section 3: Integration into .NET
 Common
Language Runtime
 Concepts
of Namespaces, Assemblies, Modules
 Free
Threading
 Reflection
 Attributes
 Windows
 Tools
Forms
The Common Language Runtime
 Access
to .NET platform services
 Cross-language

interoperation
That includes inheritance
 Interoperation
w/ COM and Platform Invocation Services

COM-Interop

PInvoke

Calling unmanaged code has its implications
Namespaces
 Organizational
concept

May and should be nested

System.Reflection

MyLib.Helpers.Controls.Inputs
 Multiple
 Importing
End Namespace
can span multiple programs
namespaces

Allows unqualified access to types

Placed at file or project level

...
namespaces declared in program
 Namespaces
 Global
Namespace MyLib
namespace without a name
Globally declared members have program scope
Assemblies
 Result

of compiling is still a .dll or .exe file
Single-file or multiple-file assembly
 File
contains metadata (manifest)

Description of the assembly itself

Description of implemented types

External references

Version information

Enforce security

And more ...
Modules
 Smallest
unit that can be compiled
 Contains
one or more classes or interfaces

Sub Main() usually has module scope
 More

than one module can share an assembly
which is an multifile assembly then
 Example: Imports System
Public Module MainMod
Sub Main()
Console.WriteLine("Hello World!")
End Sub
End Module
Free Threading
 Run

multiple tasks independently
Objects can be shared by threads
 Use
AddressOf operator on Sub to declare
Dim myThread As New Threading.thread(AddressOf MySub)
myThread.Start()
myThread.Join()
 Sub
cannot have arguments or return value
 Synchronization
needed
Threading Sample
Dim Writer As Thread = new Thread(AddressOf AnObj.ThreadSub)
Dim Reader As Thread = new Thread(AddressOf AnObj.ThreadSub)
...
Writer.Start()
Reader.Start()
Writer.Join()
Reader.Join()
...
Public Sub ThreadSub
Monitor.Enter(Me) 'Enter Synchronization block
...
Monitor.Exit(Me)
End Sub
Reflection
 Mechanism
for obtaining run-time information

Assemblies

Types: classes, interfaces, methods
 Provides
 May

explicit late-bound method invocation
even construct types at run time
System.Reflection.Emit
Attributes
 Additional
 May
declarative information on program item
define custom attribute classes
Public Class PersonFirstName
Inherits Attribute
End Class
 Can
be retrieved at run time
 Enhance

program functionality
Giving hints to the system runtime
<WebMethod()> Public Function Hello As String ...

Use as meta elements
<PersonFirstName()> Dim Vorname As String
<PersonFirstName()> Dim NamaDepan As String
Windows® Forms
 New
forms library based on .NET Framework
 Can
be used for desktop applications
 Local
user interface for three-tier applications
Windows Client
Web Service
Form1.vb
Business Object
GetOrder
HTTP
Dataset
orders.xsd
XML
Dataset
orders.xsd
Dataset Command
orderCommand
OLE DB
Database
Command-Line Compiler
 Compiles
Visual Basic source into MSIL
Vbc /target:exe /out:myprogram.exe *.vb
 Can
have a multitude of options
 Can
be called from arbitrary environment
 Uses
 Can

fewer system resources than Visual Studio
be used with nmake
Useful for multi-language projects
Visual Studio.NET
 Built
around the .NET Framework SDK
 Improved
integration and functionality

Multiple-language projects

One integrated IDE for all languages and tasks

Integrated tools: Visual Modeler, database management

Perfect help integration: Dynamic Help, IntelliSense®
 Highest
productivity for all:

Rapid application development

Large-scale projects
From Visual Basic 6 to Visual Basic.NET
 Visual

Basic.NET is a true successor of Visual Basic 6
...but some things make a difference
 Compatibility
classes help with the transition

Microsoft.VisualBasic imported by default

Classes that deliver the functionality of...

Collections

Date/time functions

More
 Prepare
for porting!
Visual Basic Upgrade Wizard
 Applies
changes automatically
 Generates

solution
Type conversions

Variant to Object

Integer to Short, Long to Integer

Type to Structure

Currency to Decimal

Zero-bound arrays

.NET Windows Forms replace Visual Basic 6 Forms
 Recommendations
for upgrading
Section 4: Putting It All Together
 Sample

Walkthrough
Exploring Visual Basic.NET Features in Duwamish Books
Demo: Duwamish Books
 Enterprise
 "Best
practice" multiple-tier design
 Included
 Great
Sample application
with Visual Studio.NET
start to learn about

Visual Basic.NET

ASP.NET

ADO.NET
Summary
 Major
touchup to take advantage of the .NET Framework
 Modernized
 Legacy
 Your
and consistent language
features finally dropped
Visual Basic.NET code can be reused
 Supported
migration path
Questions?
Duwamish Books
A Sample Application for Microsoft .NET
Installing the Sample 1/2
 Install
the "Enterprise Samples" with Visual Studio.NET
 Location

of the Visual Basic Version
Directory .\EnterpriseSamples\DuwamishOnline VB
 Installation


Tasks
Check the prerequisites

Microsoft Windows 2000 Server; Microsoft SQL Server™ 2000 with
English Query optional and supported

Read the Readme.htm
Run Installer Duwamish.msi (double-click it)
Installing the Sample 2/2
 The
installation wizard will guide you
 Defaults
 Setup
 After
should be OK for almost everybody.
will install database, Web site, and code
installation is complete:

File/Open Solution with the Duwamish.sln file

Can build the sample with Build/Build Solution
Duwamish Architecture Overview
User / Browser
ASP.NET
IIS
Web
BusinessRules
DataAccess
ADO.NE
T
Database
Common.Data
SystemFramework
BusinessFacade
Common Components
 Duwamish7.Common

Contains systems configuration options

Contains common data definitions (classes)


subnamespace Duwamish.Common.Data
"Internal" data representation for Book, Category,
Customer, OrderData
 Duwamish7.SystemFramework

Diagnostics utilities

Pre and post condition checking classes

Dynamic configuration

In short:

Everything that's pure tech and not business code
Duwamish7.DataAccess
 Contains
all database-related code
 Uses ADO.NET
architecture

Using SQL Server managed provider

Shows DataSet, DataSetCommand usage
 Optimized
for performance by using stored procs
Duwamish7.BusinessRules
 Implements
all business rules

Validation of business objects (for examle,
Customer EMail)

Updating business objects

Calculations (Shipping Cost, Taxes)
 All
data access performed through DataAccess
Duwamish7.BusinessFacade
 Implements
logical business subsystems

CustomerSystem: Profile management

OrderSystem: Order management

ProductSystem: Catalog management
 Reads
 Data
data through DataAccess
validated and updated using BusinessRules
 BusinessFacade
functionality
encapsulates all business-related
Duwamish7.Web
 Implements
the user interface for Web access
 Uses ASP.NET
architecture

Employs Web Forms model

Uses code behind forms

Manages state

Uses custom Web controls
 All
functionality accessed through BusinessFacade
Shop at Duwamish Online.NET
 Demo:
Duwamish in Action
Exploring Duwamish VB
 Exploring
Visual Basic.NET Features in Duwamish
Extending Duwamish VB
 Extending
Duwamish VB
Legal Notices
Unpublished work.  2001 Microsoft Corporation. All rights
reserved.
Microsoft, IntelliSense, Visual Basic, Visual Studio, and
Windows are either registered trademarks or trademarks of
Microsoft Corporation in the United States and/or other
countries.
The names of actual companies and products mentioned
herein may be the trademarks of their respective owners.