Moving Your Architecture
to .NET – Part III
Microsoft® Corporation
What We Will Cover
Moving from COM to .NET
COM => .NET
Visual Basic® 6 => Visual Basic .NET
ASP => ASP.NET
Using adapters
XML Web services
.NET Remoting
Session Prerequisites
Knowledge of one of the following
languages: Visual Basic .NET, C#, C++,
or Visual Basic 6
Minimal understanding of the
differences between Visual Basic 6 and
Visual Basic .NET
Level 200
So Why this Presentation?
From COM to .NET, learn how
architecture has changed
Discuss different way to use existing
COM components within Visual Basic
.NET
Web services
.NET Remoting
Best practices
Demonstrations
Adapter components
Wrap Visual Basic 6 components with
Web services
Replace Visual Basic 6 components
with .NET Remoting
Using typed DataSets
Agenda
Re-architecting
Data flow and physical tiers
Migrating the UI
Migrating the business and data logic
Typed DataSets
Best practices
Re-architecting
Migration Leads to some Re-architecting
Migration will lead to some re-architecting of
your application if you want to leverage .NET
properly
You can re-architect your application in steps
(using COM Interop)
Good logical architecture is key: .NET won’t
solve issues caused by bad design
Key question: How does data flow through the
layers?
Re-architecting
Migration Leads to some Re-architecting
.NET uses strong typing
No more variants
No more default properties
Prefer ADO.NET over ADO
.NET can still work with ADO, including recordsets,
but ADO.NET is much faster and requires less
memory
ASP.NET offers better model for building UI
Re-architecting
Migration in Steps with COM(+)
Your Visual Basic .NET code can interact with
existing COM components
You can also expose your .NET components to
COM
Start with migrating the UI from ASP to
ASP.NET
Your ASP.NET pages can then talk to existing COM
business components
In many cases, 70% of the performance gained when
moving to ASP.NET comes from migrating the UI
Agenda
Re-architecting
Data flow and physical tiers
Migrating the UI
Migrating the business and data logic
Typed DataSets
Best practices
Data Flow
How Does Data Flow through the Layers?
Weakly-typed variables (variant, object)
Strongly-typed variables (string, double,
record)
XML
Disconnected ADO recordsets
Straight access from ASP to data via ADO
Data Flow
Recommendations
Weakly-typed variables and functions (variant, object)
must be avoided or replaced by strong typing (all .NET
classes are strongly typed)
XML poses no problem, but .NET uses a different DOM
than ASP/COM
Disconnected ADO recordsets should be replaced by
ADO.NET DataSets
Having code that directly accesses the database in your
ASP or ADO.NET page is not a good idea
Can expose connection strings, etc
Physical Tiers
Questions to Ask Yourself
Does your code currently run on different physical
tiers?
Example: ASP on Web servers, business logic on
dedicated application servers, data on SQL Server
servers
Do you want to keep your current infrastructure
architecture or move to another one?
.NET makes distributing over physical tiers easy with
.NET Remoting or Web services
Serviced components can use DCOM
Agenda
Re-architecting
Data flow and physical tiers
Migrating the UI
Migrating the business and data logic
Typed DataSets
Best practices
Migrating the UI first
Moving from ASP to ASP.NET
Replace ASP pages by ASP.NET pages with
user controls/Web controls
Controls give ASP.NET a Visual Basic 6-like
forms capability – without the developer having
to worry about state
Very powerful
Much shorter development time for UIs
Better code reuse by defining page elements as
reusable controls
Migrating the UI first
Rich Development Environment
ASP.NET comes with many prewritten controls
TextBox, Calendar, DropDown, ...
Other controls can be downloaded
TreeView, TabularControl, ...
Compare to ActiveX® controls, but without the
hassle
No binary code is executed on the client
The controls are executed on the server and
generate HTML output
Agenda
Re-architecting
Data flow and physical tiers
Migrating the UI
Migrating the business and data logic
Typed DataSets
Best practices
Migrating the Business/Data Tiers
Overview
Two possible migration strategies:
Replace Visual Basic 6 components directly by
Visual Basic .NET components, horizontally or
vertically
Let ASP.NET call Web services that encapsulate
Visual Basic 6 business components, then migrate
these as needed to .NET
Migrating the Business/Data Tiers
Using Adapters
Your ASP.NET code can talk directly to Visual
Basic 6 COM code, but...
If your Visual Basic 6 business components
require the passing of variants, write strongly-
typed “in-between” .NET components
(adapters)
ASP.NET talks to the in-between components
The in-between components talk to the existing
Visual Basic 6 components and perform data
conversion to strong types
Migrating the Business/Data Tiers
Using Adapters
VB6.MyWeakComponent:
Public Function UpdatedData(Name As String, Age As
Variant, MyDataArray As Variant) As Variant
VBNet.MyStrongComponent:
Public Function UpdatedData(Name As String, Age As
Integer, MyDataArray As Array Of Single) As Double
Inversion 1, VBNet.MyStrongComponent calls
VB6.MyWeakComponent and performs type
conversion as needed
Migrating the Business/Data Tiers
Using Adapters
After
Before
ASP ASP.NET
Visual Basic Business Visual Basic Adapter
6 comp logic .NET comp logic
Visual Basic Business
6 comp logic
Migrating the Business/Data Tiers
Using Adapters
By building these adapter components,
ASP.NET code can be fully typed as needed and
the UI can be completely replaced
As a next step, you can change the Visual Basic
.NET Business components to replace the
Visual Basic 6 business components
You have now replaced your business logic layer
Migrating the Business/Data Tiers
Replacing Visual Basic 6
Components Directly
After
Before
ASP ASP.NET
Visual Basic Business Visual Basic Adapter
6 comp logic .NET comp logic
Visual Basic Business
6 comp logic
Demonstration 1
Adapter Components
ASP Calling Weakly-typed Visual Basic 6
Component
Weakly–typed Visual Basic 6.0 COM
Component
Strongly-typed ASP.NET Page
Strongly–typed Visual Basic .NET
Component
Migrating the Business/Data Tiers
Replacing Components Layer-by-layer
Ifyour original Visual Basic 6 code returned
ADO Recordsets, it is best to make the Visual
Basic .NET versions return ADO.NET DataSets
instead:
Convert ADO Recordsets to ADO.NET DataSets as
needed in the business layer
ASP.NET then works only with ADO.NET
Many ASP.NET Web controls work with DataSets
ADO.NET DataSets can be marshaled efficiently even
across physical tiers
Migrating the Business/Data Tiers
Replacing Components Layer-by-layer
Later, migrate the Data layer and make it return
ADO.NET DataSets instead of ADO Recordsets
Remove the RecordsetDataSet conversion code
from the business components
For components you can’t migrate, stick to COM
Interop
Migrating the Business/Data Tiers
Replacing Components Layer-by-layer
What about transactional integrity and
security context?
In Visual Basic 6 under Windows NT: MTS
®
In Visual Basic 6 under Windows 2000: COM+
In .NET: COM+
Migrating the Business/Data Tiers
Replacing Components Layer-by-layer
Derive your façade components from the
ServicedComponent base class to use COM+
transactions and security
Note that the components that a ServicedComponent
call, don’t need to be serviced – they use the caller’s
context!
Use attributes to control configuration
Best to put them in the AssemblyInfo.vb file
Register your façade’s assembly in the GAC
Migrating the Business/Data Tiers
Wrap Visual Basic 6 Components with
Web Services
Alternatively, start by having your ASP.NET
pages consume .NET Web services that wrap
the Visual Basic 6 components
This allows for easy separation in physical tiers
(dedicated application servers) as well as
logical tiers
A better option to separate in physical tiers is to
use .NET Remoting
If you need transactional integrity across
physical tiers, use Serviced Components
Migrating the Business/Data Tiers
Wrap Visual Basic 6 Components with
Web Services
After
Before
ASP ASP.NET
Physical boundary
ASP.NET
Visual Basic Business Web
Adapter
service
6 comp logic logic
Visual Basic Business
6 comp logic
Migrating the Business/Data Tiers
Wrap Visual Basic 6 Components with Web
Services
Web services use open standards
You can open your business logic to other
applications as well over the Internet
But be careful: Web services can be
transactional, but only as the transactional root
You can’t combine more than one Web service into
a transaction
Demonstration 2
Wrap Visual Basic 6
Components
with Web Services
Running the Demo Application
Viewing the Client Application
Viewing the Web Service Source Code
Viewing the Visual Basic 6 Source Code
Migrating the Business/Data Tiers
Replace Visual Basic 6 Components with
Remoting
After
Before
ASP ASP.NET
Physical boundary
Visual Basic Business
6 comp Visual Basic Adapter
logic
.NETcomp logic
Visual Basic Business
6 comp logic
Migrating the Business/Data Tiers
Replace Visual Basic 6 Components with
Remoting
Remoting is “.NET DCOM”
Better performance than with Web services
We measured TCP binary remoting to provide 200%-
300% the speed of Web services with SOAP
However, calling a component through remoting
does not maintain transactional integrity and
security context
Remoting only works from .NET to .NET
Demonstration 3
Replace Visual Basic 6
Components
with .NET Remoting
Running the Demo Application
Viewing the Client Application
Viewing the Remote Object Source Code
Agenda
Re-architecting
Data flow and physical tiers
Migrating the UI
Migrating the business and data logic
Typed DataSets
Best practices
Typed DataSets
Overview
Contain structured data:
ShoppingCart, UserProfile, Catalog
Are classes that inherit from DataSet
Inherit all DataSet’s standard functionalities
Can be automatically copied, merged, serialized, ...
Canbe autogenerated by the .NET Framework’s
xsd.exe tool
Typed DataSets
Example
Addproperties specific to the structured
data:
IntelliSense!
Untyped
ds.Tables(“Customers”).Rows(0).Columns(“Name”)
= “Steve Ballmer”
Typed
ds.Customers(0).Name = “Steve Ballmer”
Typed DataSets
Issues
They don’t solve all your data modeling needs:
You still have to write code to populate them
Marshalling serializable objects (such as DataSets)
rather than plain strings (such as XML strings) requires
more CPU
...
but the simplicity and power of using DataSets
more than makes up for it
See IBuySpy reference implementation
Demonstration 4
Using Typed DataSets
Running the Demo Application
Viewing the Client Application
Best Practices
Part I
Build your UI in ASP.NET using Web controls and
user controls
Use ASP.NET’s caching mechanisms to their
maximum for performance
Output caching handled by ASP.NET
Cache API for explicit caching
Don’t use Session state unless you absolutely
have to (and in most cases, you don’t)
Store state in SQL Server for availability – it’s not
much slower than the out-of-process state server
Best Practices
Part II
Use Enterprise Templates that implement and
force good coding practices
Use .NET’s standard naming conventions
Use structured exception handling
Use Typed DataSets rather than “generic”
DataSets whenever possible
It’s not the ultimate panacea but it’s better than generic
DataSets for strong typing and IntelliSense
Session Summary
Migration
ASP -> ASP.NET
Visual Basic 6 -> Visual Basic .NET
COM -> .NET
Typing
Weak
Strong
Adapters
Web service
.NET Remoting
Best practices
For More Information…
MSDN® Web site at
msdn.microsoft.com
Visual Basic .NET Home Page
www.msdn.microsoft.com/vbasic/
Visual Basic .NET Migration
support.microsoft.com/default.aspx?ID
=FH;EN-US;vbdnmig
For More Information…
Migrating to ASP.NET: Key Considerations
other Web sites
msdn.microsoft.com/library/en-us/dnaspp/html/aspne
=true
Converting ASP to ASP.NET
msdn.microsoft.com/library/default.asp?url
=/library/en-us/
dndotnet/html/convertasptoaspnet.asp
MSDN
Essential Resources for Developers
Subscription Library, OS, Professional, Enterprise,
Services Universal Delivered via CD-ROM, DVD, Web
Online MSDN Online, MSDN Flash, How-to
Information Resources, Download Center
Training & MSDN Webcasts, MSDN Online
Events Seminars, Tech-Ed, PDC, Developer Days
Print MSDN Magazine
Publications MSDN News
Membership MSDN User Groups
Programs
How-to Resources
Simple, Step-by-Step Procedures
Embedded development how-to resources
General how-to resources
Integration how-to resources
Microsoft JScript® .NET how-to resources
.NET development how-to resources
Office development resources
Security how-to resources
Visual Basic .NET how-to resources
Visual C#™ .NET how-to resources
Visual Studio® .NET how-to resources
Web development how-to resources (ASP, IIS, XML)
Web services how-to resources
Windows development how-to resources
http://msdn.microsoft.com/howto
MSDN Webcasts
Interactive, Live, Online Event
Interactive, synchronous, live, online
event
Discuss the hottest topics from
Microsoft ®
Open and free for the general public
Takes place each Tuesday
http://www.microsoft.com/usa/webcasts
MSDN Subscriptions
THE way to get Visual Studio .NET
Visual Studio .NET MSDN Subscriptions
Enterprise Architect
• Software and data modeling MSDN Universal
• Enterprise templates $2799 new
• Architectural guidance $2299 renewal/upgrade
Enterprise Developer
• Enterprise lifecycle tools MSDN Enterprise
• Team development support $2199 new
• Core .NET Enterprise $1599 renewal/upgrade
NEW
Servers
Professional
• Tools to build applications MSDN Professional
and XML Web services for $1199 new
Windows and the Web $899 renewal/upgrade
Where Can I Get MSDN?
Visit MSDN Online at
msdn.microsoft.com
Register for the MSDN Flash email
newsletter at
msdn.microsoft.com/flash
Become an MSDN CD subscriber at
®
msdn.microsoft.com/subscriptions
MSDN online seminars
msdn.microsoft.com/training/seminars
Attend more MSDN events
Microsoft Press
Essential Resources for Developers
Microsoft Visual Studio .NET is here!
This is your chance to start building the next big
thing. Develop your .NET skills, increase your
productivity with .NET Books from Microsoft Press
®
www.microsoft.com/mspress
Become a Microsoft
Certified Solution Developer
What is MCSD?
Premium certification for professionals who design
and develop custom business solutions
How do I attain MCSD certification?
It requires passing four exams to prove
competency with Microsoft solution architecture,
desktop applications, distributed application
development, and development tools
Where do I get more information?
For more information about certification
requirements, exams, and training options,
visit www.microsoft.com/mcp
Training
Training Resources for Developers
Course title:
Course number:
Availability:
Detailed syllabus: www.microsoft.com/traincert
Course Title:
Course number:
Availability:
Detailed syllabus: www.microsoft.com/traincert
To locate a training provider for this course, please access
www.microsoft.com/traincert
Microsoft Certified Technical Education Centers
are Microsoft’s premier partners for training services
Session Credits
Author:
Producer/Editor: Field Content Team
Reviewers
Field Content Council