Professional Documents
Culture Documents
Com/Dcom & Com+: A Primer On The Evolution of A Microsoft Development Environment
Com/Dcom & Com+: A Primer On The Evolution of A Microsoft Development Environment
Objects created using the COM specification support the fundamental notions of
encapsulation, polymorphism, and reusability. Microsoft's Component Object
Model (COM) defines a language-independent notion of what an object is -- how
to create objects, how to invoke methods, and so on. This allows development of
components that programmers can use (and reuse) in a consistent way,
regardless of which languages they use to write the component and its client.
COM is about choice. It provides the choice of the highest volume languages and
tools available, as well as the largest base of applications. COM also provides
choice in the area of security, as it provides a common interface (SSPI) where
various security providers can be plugged in. COM also provides choice of
network transport.
COM Principles
COM forces the Windows operating system to see applications as objects. The
OS takes the responsibility of creating objects when they are required, deleting
them when they are not, and handling communications between them, be it in the
same or different processes or machines. The OS creates a central registry for
the objects. One major advantage of this mechanism is versioning. If the COM
object ever changes to a new version, the applications that use that object need
not be recompiled.
All COM objects are registered with a component database. When a client
wishes to create and use a COM object:
1. It invokes the COM API to instantiate a new COM object.
2. COM locates the object implementation and initiates a server process for
the object.
3. The server process creates the object, and returns an interface pointer at
the object.
The client can then interact with the newly instantiated COM object through the
interface pointer.
COM defines a binary structure for the interface between the client and the
object. This binary structure provides the basis for interoperability between
software components written in arbitrary languages. A fully compliant COM object
can be written in any language that can produce binary compatible code. As long
as a compiler can reduce language structures down to this binary representation,
the implementation language for clients and COM objects does not matter - the
point of contact is the run-time binary representation.
COM defines an application programming interface (API) to allow for the creation
of components for use in integrating custom applications or to allow diverse
components to interact. COM components are never linked to any particular
application. The only thing that an application may know about a COM object is
what functions it may or may not support. In fact, the object model is so flexible
that applications can query the COM object at run-time as to what functionality it
provides.
Garbage collection is another major advantage to using COM. When there are no
outstanding references (a.k.a. pointers) to an object, the COM object destroys
itself.
COM Runtime Architecture
COM/ DCOM is a truly distributed Object-Oriented Architecture. Components
developed using Microsoft’s COM provide a way by which two objects in different
object spaces or networks, can talk together by calling each other’s methods.
COM services are provided in a standard way, whether those services are
required within a single running process, within two different processes on the
same machine, or on two different processes across a network using DCOM.
As a result COM and DCOM provide location transparency.
COM servers (objects) are accessed within the same process, within two
different processes on the same machine, or across the network using RPC:
1. In-process server: The client can link directly to a library containing the
server. The client and server execute in the same process.
Communication is accomplished through function calls.
2. Local Object Proxy: The client can access a server running in a different
process but on the same machine through an inter-process
communication mechanism. This mechanism is actually a lightweight
Remote Procedure Call (RPC).
3. Remote Object Proxy: The client can access a remote server running on
another machine. The network communication between client and server
is accomplished through DCE RPC. The mechanism supporting access to
remote servers is called DCOM.
Package
Pros Cons Preferred Uses
Type
In- High speed (no No security, no Add-on types of
Process remoting overhead), process protection- components that
no remoting limitations crash in component provide simple
crashes process that services (like function
loaded it, UI libraries or child-
synchronization window UI elements)
(sharing a message to clients
pump) tricky
Local Process security Slower than in-process Heavier components
(separation), process (remoting overhead), that are too
ownership (including remoting limitations on expensive to load in-
threading, memory interfaces, no access process, have UI
management, etc.), security beyond simple child
control over UI windows, or wish to
synchronization manage their own
files (such as
databases).
Remote Process and access Slower than local with Components that
security, process and additional remoting need to run in close
possible machine limitations proximity to a
ownership (e.g., particular resource
managing a shared
component resource),
cross-platform
If the client and server are in the same process, the sharing of data between the
two is simple. However, when the server process is separate from the client
process, as in a local server or remote server, COM must format and bundle the
data in order to share it. This process of preparing the data is called marshalling.
Distributed computing purists describe marshalling as the process of packaging
and transmitting data between different address spaces, automatically resolving
pointer problems, while preserving the data’s original form and integrity.
Marshalling is accomplished through a "proxy" object and a "stub" object that
handles the cross-process communication details for any particular interface.
The fact that COM can access services within the same process is a huge
differentiator between COM and CORBA. Allowing for the in-process model
allows for the development of components such as AcitveX Controls or
JavaBeans. CORBA at present cannot handle in-process components and
therefore cannot participate in the component marketplace.
The IDL
Whenever a client needs some service from a remote distributed object, it
invokes a method implemented by the remote object. The service that the remote
distributed object (Server) provides is encapsulated as an object and the remote
object's interface is described in an Interface Definition Language (IDL). The
interfaces specified in the IDL file serve as a contract between a remote object
server and its clients. Clients can thus interact with these remote object servers
by invoking methods defined in the IDL. COM objects and interfaces are
specified using Microsoft Interface Definition Language (IDL), an extension of the
DCE Interface Definition Language standard. To avoid name collisions, each
object and interface must have a unique identifier. Interfaces are considered
logically immutable. Once an interface is defined, it should not be changed (new
methods should not be added and existing methods should not be modified).
When developing a COM-based system, it's important to get the interface down
in IDL code. In modern COM, IDL best describes COM interfaces. After
describing an interface in IDL, run the IDL through the MIDL compiler, which
produces C and C++ header files, a type library, and the source code necessary
for building a proxy-stub DLL. Interfaces must be well defined in IDL, because
the proxy and the stub need to understand exactly how to move data between
the client and the object. This is important because the client and the object
might be on different machines, and moving data from the client to the object
probably involves moving actual bits back and forth.
To invoke a remote method, the client makes a call to the client proxy. The client
side proxy packs the call parameters into a request message and invokes a wire
protocol like IIOP (in CORBA) or ORPC (in DCOM) or JRMP (in Java/RMI) to
ship the message to the server. At the server side, the wire protocol delivers the
message to the server side stub. The server side stub then unpacks the
message and calls the actual method on the object. In both CORBA and
Java/RMI, the client stub is called the stub or proxy and the server stub is called
skeleton. In DCOM, the client stub is referred to as proxy and the server stub is
referred to as stub.
The final consideration for using COM is that a single object instance may play
different roles for different simultaneous clients where each client is using a
different set of interfaces. A COM object can support any number of interfaces.
An interface provides a grouped collection of related methods. In addition, a
single piece of client code may be using many different objects polymorphically
(through the same interface). COM gives up on multiple inheritances to provide a
binary standard for object implementations. Instead of supporting multiple
inheritances, COM uses the notion of an object having multiple interfaces to
achieve the same purpose. This also allows for some flexible forms of
programming.
DCOM
Distributed COM is an extension to COM that allows network-based component
interaction. While COM processes can run on the same machine but in different
address spaces, the DCOM extension allows processes to be spread across a
network. With DCOM, components operating on a variety of platforms can
interact, as long as DCOM is available within the environment.
It is best to consider COM and DCOM as a single technology that provides a
range of services for component interaction, from services promoting component
integration on a single platform, to component interaction across heterogeneous
networks. In fact, COM and its DCOM extensions are merged into a single
runtime. This single runtime provides both local and remote access.
DCOM which is often called 'COM on the wire’ supports remoting objects by
running on a protocol called the Object Remote Procedure Call (ORPC). This
ORPC layer is built on top of DCE's RPC and interacts with COM's run-time
services. A DCOM server is a body of code that is capable of serving up objects
of a particular type at runtime. Each DCOM server object can support multiple
interfaces each representing a different behavior of the object. A DCOM client
calls into the exposed methods of a DCOM server by acquiring a pointer to one
of the server object's interfaces. The client object then starts calling the server
object's exposed methods through the acquired interface pointer as if the server
object resided in the client's address space. As specified by COM, a server
object's memory layout conforms to the C++ vtable layout. Since the COM
specification is at the binary level it allows DCOM server components to be
written in diverse programming languages like C++, Java, Object Pascal (Delphi),
Visual Basic and even COBOL. As long as a platform supports COM services,
DCOM can be used on that platform. DCOM is now heavily used on the Windows
platform.
Active X
In October of 1996 Microsoft turned over COM/DCOM, parts of OLE, and
ActiveX to the Open Group (a merger of Open Software Foundation and
X/Open). The Open Group has formed the Active Group to oversee the
transformation of the technology into an open standard. The aim of the Active
Group is to promote the technology's compatibility across systems (Windows,
UNIX, and MacOS) and to oversee future extension by creating working groups
dedicated to specific functions. However, it is unclear how much control Microsoft
will relinquish over the direction of the technology. Certainly, as the inventor and
primary advocate of COM and DCOM, Microsoft is expected to have strong
influence on the overall direction of the technology and underlying APIs.
An ActiveX control is really just another term for "OLE Object" or, more
specifically, "Component Object Model (COM) Object." In other words, a
control, at the very least, is some COM object that supports the IUnknown
interface and is also self-registering. It usually supports many more interfaces in
order to offer functionality, but all additional interfaces can be viewed as
optional and, as such, a container should not rely on any additional interfaces
being supported. This allows a control to implement as little functionality as it
needs to, instead of supporting a large number of interfaces that actually don't
do anything. Through QueryInterface a container can manage the lifetime of
the control, as well as dynamically discover the full extent of a control's
functionality based on the available interfaces.
In short, this minimal requirement for nothing more than IUnknown allows any
control to be as lightweight as it can. Other than IUnknown and self-
registration, there are no other requirements for a control. There are, however,
conventions that should be followed about what the support of an interface
means in terms of functionality provided to the container by the control. It
should never be assumed that an interface is available, and standard return-
checking conventions should always be followed. It is important for a control or
container to degrade gracefully and offer alternative functionality if a required
interface is not available.
COM+ is the next step in the evolution of the Microsoft Component Object Model
and the Microsoft Transaction Server (MTS). COM+ is the merging of the COM
and MTS programming models with the addition of several new features. COM+
handles many of the resource management tasks a developer had to program
himself, such as thread allocation and security. It automatically makes an
application more scalable by providing thread pooling, object pooling, and just-in-
time object activation. COM+ also protects the integrity of the data by providing
transaction support, even if a transaction spans multiple databases over a
network. COM+ has come along to unify COM, DCOM, and MTS into a coherent,
enterprise-worthy component technology. Indeed, these and other technologies
constitute Microsoft's distributed and web-oriented strategy. This strategy is
globally referred as Distributed interNet Architecture(tm) (DNA) and it comprises
a full set of products and specifications to implement net-centric applications.
COM+ integrates MTS services and message queuing into COM, and makes
COM programming easier through a closer integration with Microsoft languages
as Visual Basic, Visual C++, and J++. COM+ does not change the wire protocol
that Distributed COM (DCOM) uses, so network communication stays
unchanged. COM+ not only adds MTS-like quality of service into every COM+
object, it hides some of the complexities of coding in COM.
COM suffers from some weaknesses that have been recognized by Microsoft
and addressed in Component Object Model+. COM is hard to use. Reference
counting, Microsoft IDL, Global Unique Identifiers (GUID), etc. require deep
knowledge of the COM specification by developers. It has been estimated that up
to 30 percent of the effort in writing component-based software is spent writing
“object housekeeping” software. COM+ will handle this task for developers by
providing implementations of most of the code that deals with the object
infrastructure, leaving the developer free to write logic that deals with the problem
they are trying to solve.
COM+ provides a much better component administration environment, support
for load balancing and object pooling, and an easier-to-use event model. These
changes are based on a new COM+ runtime that moves most of the COM
grunge code (e.g., IUnknown and class factory implementations) into the OS.
COM+ Principles
A good number of developers see COM as more than a little challenging to
understand and use. The reason for this is simple. Using COM's language-
independent objects in any real programming language requires understanding a
new object model -- the one defined by COM. For example, a C++ programmer
knows that creating a new object requires using the language's new operator,
while getting rid of that object requires calling delete. If that same C++
programmer wants to use a COM object, however, the developer can't do things
in this familiar way. Instead, the standard COM function CoCreateInstance (or
one of a few other choices) must be called to create the object. When done with
this COM object, the programmer doesn't delete it explicitly, as in C++, but
instead invokes the object's Release method. The object relies on an internal
reference count that it maintains to determine when it has no more clients, and
thus when it's safe to destroy itself.
COM+ still provides a standard library, and objects and their clients still use it.
But in contrast to COM, COM+ hides calls to this library beneath the equivalent
native functions in the programming language. C++ programmers, for example,
can once again use the standard new operator rather than CoCreateInstance to
create a COM+ object. In doing so, they are relying on a C++ compiler that is
aware of COM+ to generate the correct code to call the COM+ library. To
accomplish this, the compiler uses the COM+ library at compile time, then
embeds calls to this same COM+ library in the generated binary. Microsoft will
provide this library, and any language tool that wants to use COM+ must rely
upon it. Unlike classic COM, where only COM objects and their clients use the
COM library, COM+ also requires compilers (or interpreters, such as those for
Visual Basic, and scripting languages, like JavaScript) to rely on a standard
library to produce the correct code.
COM+ eliminates the need for clients to call Release when they are done using
an object. COM+ also allows implementation inheritance between COM+ objects
running in the same process.
In COM+, developers no longer need to define interfaces using IDL. Instead, they
can just use their programming language's syntax to define the object's
interfaces. The compiler for that language then works with the COM+ library to
generate metadata for the object. Since every COM+ object has metadata, it's
also possible to approach marshaling consistently. Marshaling is packaging a
method call's parameters in some standard way, allowing these parameters to
move effectively between objects written in entirely different languages or running
on entirely different machines. A developer in a COM+ world just provides the
Meta data that is needed and provides the methods. Most of the other code
dealing with things such as registering components, reference counting for
memory management etc. will be handled by the system.
Interceptors provide services based on attributes that have been previously set
on an object by a developer. These interceptors provide automatic behavior at
runtime based on the attribute set. As an example interception allows for things
such as dynamic load balancing. Also, an interceptor makes sure that when a
transactional object attempts to change data either all succeed or all fail and
rollback.
COM+ also changes COM's persistence model. Today, the creator of a COM
object must typically implement one or more of a fairly large set of interfaces
related to persistence. A client of this object then calls various methods in those
interfaces to have the object load or save its persistent state. But the COM+
library provides standard support for persistence, removing much of the burden
from the COM+ object implementor. And by representing an object's properties in
a standard way ("serialization"), COM+ lets the developer pass objects by value.
All that's required is to send this serialized representation of an object's data to
another object of the same class.
Today, COM and MTS components place all of their configuration information in
the Windows registry. With COM+, however, most component information is
stored in a new database, currently called the COM+ Catalog. The COM+
Catalog unifies the COM and MTS registration models and provides an
administrative environment for components. A developer interacts with the COM+
Catalog using either the COM+ Explorer, which is similar to the MTS Explorer, or
through a series of new COM interfaces that expose its capabilities.
Another interesting change, support for constructors, makes COM+ objects more
like objects in a typical object-oriented programming language. Languages like
C++ and Java can define a constructor method that runs when first creating an
object. The creator of the object can then pass parameters as needed to this
constructor, allowing easy initialization. COM objects do not support constructors,
but COM+ objects do. COM+ constructors even allow passing parameters, better
integrating COM+ objects and the objects used by today's most popular object-
oriented languages.
Windows DNA
Windows Distributed interNet Applications Architecture, or Windows DNA, is
Microsoft’s latest acronym that describes its move from workstation-based to
enterprise-level application development. Windows DNA describes those
Microsoft technologies that provide a complete, integrated n-tier development
model, and those services that developers require to build scalable and
dependable enterprise-level systems on the Windows platform.
Figure 1
At the middle tier, developers use DCOM, MTS, IIS, and Active Server Pages to
handle business logic and other application services. Components executing on
the middle tier access back-end data using Active Data Object (ADO) or OLE DB.
Microsoft also provides tools to access data on non-Windows platforms.
Examples include ODBC, COM services on UNIX, and the new COM Trans-
action Integrator (COMTI).
Figure 2
Storage+ is the future of the Windows file system and will probably look a lot like
OLE DB, but with several new features. Storage+ is the most distant technology
of Windows DNA and we won’t see much on this front until well after Windows
2000.
Conclusion
It is important to note that COM+ essentially is one of the key unifying elements
for Windows DNA, as it allows for the development of applications, which are
flexible and powerful enough to deal with the spectrum of environments found
today, from three tier client server environments to web based.
What all of this means is that Microsoft understands that the software market is
moving faster and faster toward the Internet. All of the future “killer applications”
will be developed for Web environments, be they intranets or the Internet. To
succeed in this new market, Microsoft is making it easier for developers to build
applications without a dependency on the Win32 API.
References
Jason Pritchard, PH.D., COM and CORBA Side by Side, Addison-Wesley
Longman, Inc., 1999
Object Management Group home page [online]. The site provides information
comparing DCOM (ActiveX) to CORBA. <URL: http://www.omg.org/> (1997).