Differences between COM, COM + and. net

Source: Internet
Author: User
Tags msmq
All outstanding programmers will do their best to make their programs more reusable, because it allows you to quickly write more robust and scalable programs.

There are two options for code reuse:

1. white box: the simplest one is to copy your program to another file.
2. Black Box: it includes connecting compiled program slices. Therefore, the compiled black box class library that can be called by the client is called a component.

. Net also provides developers with methods similar to com for creating and expanding components. Developers are easily confused by these two component-based development models, so let's take a look at these different development methods to eliminate the confusion.

  Com generation

In the previous programming process, programmers put their function libraries in a separate file called an object, which contains compiled code. When programmers want to use a special target file, they compile the client program into machine code, and then connect the client program to the target file by means of dynamic links, finally, it becomes a single executable file. The only benefit of this practice is that it saves time to compile the function library. However, it has many disadvantages. For example, a library is included in each single executable file, which wastes a lot of storage space. It is also very difficult to maintain the application, if a bug is found in the function library, the entire executable file will be re-compiled and distributed.

There are more than one serious limitation. A client application must be used together with a function library compiled in the same language. For example, a client application written in quickbasic cannot reference a function library written in C ++.

Therefore, Microsoft produces COM, which is only a specification. No matter what language the component is written into, as long as it complies with this COM specification, it can be called by a client program written in any language. In addition, programmers no longer have to worry about creating a single executable file because the component is identified by a guid (globally unique identifier. GUID is a 128-bit number. It is placed in the registry of the system together with some related information to uniquely identify the component. The client application dynamically creates an instance of a component only during running and uses the function of the component. Therefore, only one function library is required to be copied. Its disadvantage is that we often mention it? Quot; DLL hell ". This problem occurs when a DLL is replaced by a new version of DLL. The developer has to clear reference to this component by disabling all client applications (if not, closing the WWW Service. Sometimes all methods do not work, so you have to restart the server to replace the old DLL.

  COM +

To enable enterprise-level applications to use Com, it must have the following specific capabilities.

· Verification capability
· Object pooling)
· Transaction Processing
· Supports distributed architecture

To prevent developers from adding these capabilities to their components, Microsoft has developed DCOM (Distributed COM) and MTS (Microsoft Transaction Server ). With these two technologies, developers can focus on their business logic rather than on their components in the background.

DCOM is a Remote Procedure Call Protocol for communication between distributed components. The client sends a request to the proxy class of a local machine. Then, the proxy class implicitly sends the request to the "root" class installed on the remote machine, and then returns the result to the proxy class, finally, the proxy class sends them back to the client. Therefore, the location of the client program is completely independent of that of the component. The disadvantage of DCOM is that because DCOM uses an independent hardware port instead of the http port 80, it must be enabled during inter-component communication. This is a serious security issue. Therefore, DCOM cannot easily traverse the firewall.

To use MTS, programmers place special MTS hooks in their components and put them in the MTS Package after compilation. Putting related components in a single package has its own advantages. When a customer requests an instance of a component in a package, MTS ensures that a new dedicated thread is created for the package, A new component instance is created on this thread and applied to the transaction service. Whether the object Pool Service and Security Service are to be established depends on the developer's request.

MTS allows related job units to be treated as a transaction, which means that if all job units are successfully completed, the entire transaction will be treated as successful, otherwise, if a unit fails to be completed, the entire transaction will be re-migrated.

After the customer request object and the release object, MTS still saves this object. Therefore, when another customer requests the same component, MTS delivers the saved object to it. In this way, MTS reduces the number of Instantiation times on the server Source.

MTS allows developers to use security measures to assemble their components so that they have the ability to identify the customers who request its services. This prevents unauthorized customers from using component functions.

MTS is fully integrated into Microsoft's Windows 2000 operating system in the name of COM +, but COM + is not only MTS, but also includes some other services. MSMQ (Microsoft Message Queue Server), a service released together with MTS, is also integrated into Windows 2000 in the name of COM +. MSMQ allows synchronous communication between the server and the client. Event Service is also added to enable the server to communicate with the client synchronously. The load balancing service automatically instantiates request objects on servers with the most resources on the machine.

  . Net

. NET provides a completely new method for creating and expanding components. It is the well-known assemblies. To use com, the developer must register the component on the server. That is to say, the component information in the system registry must be updated. This aims to ensure the central position of the component so that COM + can find the appropriate component. Using. Net assemblies, the Assembly file pushes all the required metadata (meta data) into a special segment called manifests (list. In. net, to make Assembly effective to users, simply put them in a directory. When a customer program requests an instance of a special component ,. net Runtime (runtime) searches for assembly in the same directory. After finding it, analyze the manifest to obtain the class information provided by this component. Because the component information is stored in manifest, developers do not need to register the component on the server. Therefore, several identical components can be securely stored on the same machine.

Create. net assembly is not like creating a VB6 component. The only concern for developers is the business logic. All the background code is composed. net is generated during runtime, and.. Net has the fragment collector function during runtime, so the component does not have to worry about the number of its references (in COM, it relies on iunknown help ). To put it simply, creating an assembly in. NET is much easier than creating a VB6 COM.

Pure. Net assemblies cannot be registered under the COM + service, because they are different from the binary standards of COM. In the face of. net, the prospect of assemblies is "Advanced com" compared with COM ". However, due to the reliability of the applications currently structured on COM +, com will continue for a period of time. This may be why Microsoft provides developers with tools for developing. Net assemblies and COM.

The Type Library importer (tlbimp.exe) tool can encapsulate COM components into. net so that previous things can be used in. NET applications.

Type Library exporter (tlbexp.exe) Tool. NET components encapsulated into com, this tool is also very useful, if you want to use your. net assemblies to replace the original COM component, you need to use it. Services provided by COM + cannot be ignored, so it is very important to encapsulate. Net assemblies into COM components. As a choice, developers can select more functions from the. NET base class library.

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: info-contact@alibabacloud.com 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.