COM, COM + and. NET Differences (RPM)

Source: Internet
Author: User
Tags continue copy message queue thread msmq
Difference Author: Sunwen translation

All the best programmers do their best to make their written programs more reusable, because it allows you to quickly write more robust and scalable programs.

There are two choices to make code reusable:
1. White box: The simplest one is to copy your program to another file.
2. Black box: It involves connecting a compiled piece of the program. So the compiled black box class library that the client can invoke is called a component.

. NET also provides developers with a way to build and expand components similar to those of COM. Developers are easily fooled by these two component-based development models, so let's take a look at these different development methods so that we can eliminate the confusion.

The generation of COM

In the course of previous programming, programmers placed their libraries in a separate file called the object file, which contained the compiled code. When programmers use a particular target file, they compile the client program into machine code, and then rely on dynamic linking to connect the client to the target file and finally become a single executable file. The only benefit of this approach is that it saves the time it took to compile the function library. But it has a lot of flaws, for example, because there is a library included in each individual executable file, a lot of storage space is wasted, and it is very difficult to maintain the application, if a bug is found in the library, the entire executable file is recompiled and distributed.

There's more than one serious limitation. A client application must be used together with a library of libraries in the same language. For example, a client application written in QuickBasic cannot refer to a library of functions written in C + +.

As a result, Microsoft has produced com,com just a specification. Regardless of the language in which the component is written, a client program written in any language can be invoked as long as the COM specification is met. In addition, programmers do not have to worry about building a single executable file because the component is identified by the GUID (Global unique identifier). A GUID is a 128-bit number that is placed in the registry of the system, together with some relevant information, to uniquely identify the component. Client applications only dynamically build an instance of a component during run time and use the functionality of this component, so only one copy of the function library is required. Its disadvantage is that people often refer to the Quot;dll hell. This problem is raised when a DLL is to be replaced by a new version of the DLL. Developers have to use the method of shutting down all client applications (and, if not, shutting down the WWW service) to achieve a reference to the component used by the purge. Sometimes all methods do not work, then you have to restart the server to replace the old DLL.


In order for an enterprise-class application to use COM, it must have the following specific capabilities.
· Verification capabilities
· Objects pool (object pooling)
· Transaction processing
· Support for distributed architectures
To make it unnecessary for developers to add these capabilities to their components, Microsoft has produced DCOM (Distributed COM Distributed COM) and MTS (Microsoft Transaction server Microsoft Transaction servers). With both technologies, developers can focus on their business logic without having to put them on their components in the background.

DCOM is an RPC (Remote Procedure Call) protocol for communication between distributed components. The client sends a request to the proxy class of a local machine, which is then implicitly given by the proxy class to the "root" class installed on the remote machine, and then the result is sent back to the proxy class, and finally the proxy class sends them back to the client. Therefore, the location of the client program is entirely independent of the location of the component. The disadvantage of DCOM is that because DCOM uses a separate hardware port, rather than the HTTP protocol's 80 port, you must ensure that the port is open during communication between components. This is a serious security issue. So DCOM is not able to easily traverse the firewall.

To use MTS, Programmers place special MTS hooks in their components and place them in an MTS package after compiling them. Putting a relational component in a single package has its own benefits. When a customer requests an instance of a component in a package, MTS ensures that a new dedicated thread is created for the package, and a new component instance is built on this thread and applied to the transaction service. As to whether object pooling services and security services are to be built, it depends on the developer's request.

MTS allows related units of work to be treated as a transaction, which means that if all the units are successfully completed, the entire transaction is treated as a successful completion, whereas if one of the units is not successfully completed, the whole transaction will be reborn again.

MTS still holds the object after the client requests the object and releases the object, so when another client requests the same component, MTS gives it to the saved object. In this way, MTS reduces the number of times the server source is instantiated.

MTS allows developers to use security measures to assemble their components so that they have the ability to identify the customers requesting their services. This ensures that unauthorized customers are not able to use the functionality of the component.

MTS is fully integrated into Microsoft's Windows 2000 operating system in the name of COM +, but COM + is not only MTS, it also includes some other services. MSMQ (Microsoft message Queue Server), a service that is published with MTS, is also integrated into Windows 2000 in the name of COM +. MSMQ allows synchronous communication between the server side and the client. The event service was also added to enable the server to communicate events synchronously with the client. The Load Balancing Service (load Balancing) automatically instantiates the request objects on the server with the most resources on the machine.


. NET provides a new way to build and expand components. It is the famous assemblies. With COM, developers will need to register components on the server, which means that the information in the system registry for components must be updated. This is done to ensure the central location of the components so that COM + can find the right components. Use. NET, the assembly (Assembly) file assemblies all the required metadata (meta data) into a special section called Manifests (list). In. NET, to make assembly work for users, simply put them in a directory. When a client program requests an instance of a particular component,. NET runtime (runtime) searches assembly in the same directory, and after it is found, analyzes the manifest to obtain information about the classes provided by this component. Since the component information is placed in the manifest, it is not necessary for the developer to register the component on the server, so that several identical components can be allowed to coexist securely on the same machine.

Building a. Net assembly is not like building a VB6 component, the only thing developers worry about is the business logic, all the background code. NET runtime is generated, and due to. NET runtime has the capability of a fragment collector, the component does not have to worry about the number of references it has (in COM, by IUnknown Help). Simply put, it is much simpler to build a assembly in. NET than to build a VB6 com.

Pure. NET assemblies cannot be registered under COM + services because they are binary standards that are different from COM. Face. Net,assemblies's outlook is "advanced com" relative to COM. However, COM will continue for some time because of the reliability of the applications currently being architected on COM +. This may be why Microsoft has provided developers with the tools to develop. NET assemblies and COM at the same time.

The Type Library Importer (TLBIMP.exe) tool encapsulates COM components into. NET so that previous things can continue to be used in. NET Applications.

The type Library Exporter (Exporter (TLBEXP.exe)) tool will. NET component into COM, this tool is also useful, if you want to use your. NET assemblies to replace the original COM components, you have to use it. The services provided by COM + cannot be ignored, so encapsulating. NET assemblies into COM components becomes very important. As a choice, developers can start from. NET base Class library to select more features.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.