The Microsoft Way: COM, OLE/ActiveX, COM+ and.net CLR Chapter 15 Microsoft is continually reengineering its existing application and platform base. Started with VBX, continued with OLE, ODBC, ActiveX, MTS and ASP, Microsoft introduces component technology gradually. Lately they introduced.net and CLR and.net is beginning to be accepted by standard bodies. 1
The Fundamental Wiring Model - COM COM is a binary standard: + On binary level, an interface is represented as a pointer to an interface node. + Doubt indirection-the interface pointer is passed as a self parameter to any of the interface s operations. A COM component is free to contain implementations for any number of interface. Every interface has a [uuid(00000000-000-000-c000-000000000046)] QueryInterface Interface IUnknown { operation HRESULT QueryInterface ([in]cons IID iid,[out,iid_is(iid)]iunknown ood); unsigned long AddRef(); unsigned long Release(); 2
COM Interface A COM Interface is: + A pointer Pointing to a table of function pointers, a vtable + Strongly typed Every interface has an globally unique interface identifier (IID) + Immutable A new version of an interface can not have the same identifier as the old version A COM Interface is not: + A C++ class Instances can not implement interfaces before their creation Different binary instances may implement the same interface + An object It is simply a group of methods and binary data 3
IUnknown A COM component may expose multiple interfaces Every component is required to expose a special interface, IUnknown, in order for the client to find out what other interfaces are supported. IUnknown supports three mandatory methods: + QueryInterface - used for interface to obtain an interface component may support + AddRef and Release - used for reference counting IOleObject IDataObject IPersistStorage IOleDocument IUnknown IUnknown * punknown = (some function returning an IUnknown *); IOleObject * poleobject = NULL; HRESULT hr; hr = punknown ->QueryInterface(IID_IOleObject, &poleobject); 4
COM Object Reuse COM supports two models of object reuse: + Containment. A simple delegation model where an outer object contains an inner object. The outer object forwards all the requests for the interfaces it exposes to the inner object. (see figure 14-5 a) + Aggregation. A mechanism in which the outer object exposes interfaces from the inner object as if they were implemented on the outer object itself. (see Figure 14-5 b) Aggregation is available as a convenience to avoid extra implementation overhead in the outer object in this case. Aggregation is a specialized case of containment. 5
Containment & Aggregation COM supports two forms of object composition to enable object reuse: + Containment: Containment is where the client is talking to the outer object, and is unaware of the inner object. Containment puts the outer object in control. You get to re-implement part or all of the interface provided by the contained object. This can provide you with greater control over the usage of the inner object. + Aggregation: Aggregation is where the client is given access to the inner object, and conducts all further interactions (for that interface) directly with the inner object Aggregation has the benefit of least work. You merely return a pointer (in general terms, a reference) to the inner object from the outer object, and the client deals directly with the inner object thereafter. 6
Interface Inheritance COM interfaces may inherit from other interfaces. Inheritance in COM does not mean code reuse. Only the contract associated with an interface is inherited either by adding new methods or by further qualifying the allowed usage of methods. There is no selective inheritance in COM. If one interface inherits from another, it includes all the methods that the other interface defines. All COM interface inherit from IUnknown to make it possible to move freely between the different interfaces that an object supports as well as the means to manage its lifetime by using AddRef and Release. IUnknown * punknown = (some function returning an IUnknown *); IOleObject * poleobject = NULL; HRESULT hr; hr = punknown ->QueryInterface(IID_IOleObject, &poleobject); IDataObject * pdatadocument = NULL; hr = pdataobject->queryinterface(iid_idataobject, &pdataobject); 7
COM Object Creation COM defines + Class identifiers (CLSIDs): to uniquely reference components. CLSIDs are Globally Unique Identifiers (GUIDS) + IID: Interface which takes a CLSID and a IID, then creates a new instance of class (CLSID) and returns an interface (IID). CoCreateInstance() function is used to create a new instance of a COM component given a CLSID COM components can be created as: + In-process - run within the client process + Local - run in a separate process on local host + Remote - run in a separate process on remote host 8
COM Object Initialization Initializing Objects, persistence, structured storage, monkers + Initialize an object by load its data from a file, a stream, or other data storage. + A COM structured storage is a tree structure. + Monkier: refer to an object by specifying a logical access path. For example, a monkier can refer to the spreadsheet object named 1997 Revenue, embedded in the document The previous millennium and stored at a certain place specified by a URL. 9
From COM to Distributed COM (DCOM) DCOM builds on the client-side proxy objects and the server-side stub objects already present in COM, where the yare used only to support inter-process communication. 10
DCOM System registry helps to map a given CLSID to a specific component. The objects can reside either locally or on a remote host - Distributed COM (DCOM) DCOM makes COM interface calls locationally transparent to the component s client Such transparent communication is implemented through the use of proxy objects on client s end and stub objects on the server*s (component s) end. (see Figure 14.11) 11
Object Linking and Embedding (OLE) Compound documents and OLE + OLE is Microsoft*s compound document standard. OLE was created to blend legacy applications, with their own application centric view of the world. Into a single document-centric paradigm. OLE containers and servers + OLE has to provide ways to enable document integration for configurations of in-process, local, and remote server. Controls: from Visual Basic via OLE to ActiveX + ActiveX controls are really just COM objects supported by a special server. But is has larger a number of features and interactions. They not only have regular COM interfaces, but also have outgoing interfaces. 12
MTS and COM+ Microsoft Transaction Server + Is a COM service that supports online transaction processing of COMbased applications. + Transactions are implemented via COM aggregation to add transactional interfaces to components. COM+ + Is an extension of COM and MTS. + Is restricted to in-process objects; across processes or machines, DCOM is used. + Supports automatic garbage collection. 13
Other COM Services Uniform data transfer + Uniform data transfer allows for the unified implementation of all sorts of data transfer mechanisms Dispatch interfaces and dual interfaces + Dispatch interfaces have a fixed number of methods defined in interface IDispatch. It has on principal advantage: they always look the same Outgoing Interfaces and connectable objects + A outgoing interface is an interface that a XOM object would use (rather than provide) if it is *connected* to an object that provides this interface. 14
Contextual Composition Like Corba, Microsoft provides a number of key services on DCOM such as + A directory service - Windows Registry + Enterprise services - interoperability services, MTS Com follows an apartment threading model + Unlike Java (synchronized) programming model, COM uses single threading domains, also known as apartments. + Synchronization issues are automatically inserted into apartment boundaries. Contextual composition + Based on the apartment model the contextual composition is performed by MTS 15
.NET.NET is the latest development platform from Microsoft It consists of a.net Space and a strictly larger.net Framework to improve interoperability and web services.net introduces: + CLI - Common Language Infrastructure + CLR - Common Language Runtime + C#.NET targets: + Web services + Deployment platforms (server and clients) + Developer platform 16
Common * CLI: a language neutral platform with an intermediary language and a eployment platform (packaging) + CTS * Common Type System No primitive types such as integers A single root type: System.Object + CLS * Common Language Specification Contains the superset of many languages core concepts CLR goes beyond CLI specification + Compiles and executes native code + Offers dynamic loading and unloading, garbage collection, context interception, metadata reflection, remoting, persistence and other fully language independent runtime services 17
ASP.NET: Web Services and XML ASP.NET approach is a departure from the old ASP model + ASP.NET is an ISAPI extension + Provides a performance close to raw ISAPI applications with more flexible programming facilities ASP.NET takes advantage of WSDL-defined ports + Using WSDL defined ports, it can process messages without the need of understanding, whether they are SOAP, XML or another language supported by WSDL. 18
Summary - COM Component Object Model has been improved gradually throughout the time. COM has unique identifiers COM Objects may implement multiple interfaces COM follows an apartment threading model for synchronization 19
Summary - DCOM and COM+ Microsoft offers a number of key services that build on DCOM: + Microsoft transaction server: The transaction server supports online transaction processing of COM-based applications. The transaction server currently does not address fault tolerance issues beyond the properties of transactions. + COM+: + In October 1997, Microsoft released COM+, an extension of COM. The COM+ combines with lightweight object models such as that required by a Java Virtual machine. + Extensive use of meta-data makes COM+ well suited for Java, Component Pascal, Visual Basic, or scripting languages and obviates the need to implement dispinterface. 20
Summary -.NET.NET is like an iceberg. The supporting framework is much larger than the.net space.net introduced common language infrastructure and common language runtime to improve interoperability The target of.net is quite large, covering programmers, end-users and web-services. 21
Reference Books: + Understanding ActiveX and OLE-A Guide for Developers David Chappell + ActiveX Controls Inside Out (Denning,1997) Adam Denning + Inside COM (Rogerson,1997) Dale Rogerson + Essential COM (Box,1998) Don Box Websites: + ActiveX Group: http://www.activex.org/ + Microsoft Corporation: http://www.microsoft.com/activex/ + Microsoft Developers Network (MSDN) online library: http://msdn.microsoft.com/library/ 22