COM + Getting Started

zhaozj2021-02-16  126

As early as the WINDOW2000 released, COM has been generated, and integrated in the operating system,

It is in the form of a service. Com adds a series of MTS (a system service,

Used to manage persistence data in the database, also handled persistence messages and file systems in transactions

)service:

1. Transaction services: It ensures data integrity in the distributed system.

2. Secure service: Its security model provides processing security without writing any code.

3, Synchronous Service: Provide a method of managed to solve the problem in components, but do not write code

.

4, resource management: (including resource manager and resource allocator) Manage database connections, network connections,

Memory, etc.

5, Just In Time is a service that inherits from MTS, when the customer calls

Keep an instance of the object in an active state and cache in server memory, after using the object,

Notifying the MTS environment to release the resources occupied by the object, such as database connections.

6, the object pool: Provide a thread pool to store the current object, for the next time, it is a system

Auto service. When there is an application to access the COM component, an instance of the component is created for the application.

And stored in the object pool, the application is destroyed, the instance is free to configure the component to make it

In the state of the pool, the reuse of the instance is realized, and the performance and scalability of the application are improved.

7. Based on role: this is easy to understand, that is, verify the role, give a secure license, give different use

Households to different privileges.

8, Queue Components (MSMQ): Provide an asynchronous message queue, which can automatically convert data according to its form

According to the package.

9. Sharing Properties Manager (SPM): Used to manage object status information stored in memory, in one service

Intersectors can be used to share the state between multiple objects and provide concurrent processes.

10. Compensation Resource Manager (CRM): Used to generate log files and handle systems during processing transactions

collapse. Including the CRM grid (the main part of CRM, the interface provided by the CRM's infrastructure

Related information written to logs, and retrieve log files when needed (used to transaction)

After completing, submit transactions and generated log files to users who execute transactions).

11, concurrent: Although it allows multiple processes in an application to run simultaneously, the process is divided into each group context

(Object collection with the same needs) is included in units (a set of contexts within a process), one into

Cheng can include multiple contexts involving different needs of different needs, and each context has a unique

COM objects to provide services such as COM transaction and JIT activation.

Tools provided using COM can create multi-layer applications that perform transactions, and can handle thread allocation

The problem. OK, introduce the "COM " to introduce the type of COM .

COM has several different types of different purposes:

1. Application Agent: Contains files for application registration information, that is, when some customers access remote computers

When the server program is written, the application agent running on the client will write the information of the server application.

Enter the client computer.

2, server application: Just perform COM applications within the process of COM application itself,

Use concurrency to handle components.

3, library applications: Yes in the process of the client application, loaded within the client application process, using task-based security, the disadvantage is not to support remote access and queue components.

4, COM Pre-installation application: to the COM application folder in the component service in the management tool

See what is a COM pre-installed application, it is automatically installed in the COM installation process.

The application of the service is not modified, and cannot be deleted.

At the same time, it involves a concept of "assembly": "it is all types of CLR and

Collection of resources such as bitmap files, etc.). Can be viewed by "Configuring .NET Framework" under management tools.

. Includes an assembly with private and shared.

Private assembly: It can only be placed in an application access to the same path as the assembly. By default, private,

Must be placed in a folder using its application.

Sharing assembly: Refers to the assembly added in GABAL Assembly Cache. GAC is special

Used to store the assembly, make the application can share these assemblies, one must pay attention to the deposit

The assembly placed in the GAC must have a unique name that can be played by playing in the .NET command.

Into Sn -k assemblyname.snk to generate a unique name called strong name, generate strong name

After that, there will be a public key to attach the danger to prevent the name Similar and replaced.

The security of the assembly in .NET provides two mechanisms: one is the strong name mentioned earlier, one

Is using SignCode (understandable as a digital signature). Signcode.exe is used to mark an assembly, while

Embed a digital signature to the program set, allowing users to identify developers who created this assembly.

(Note: There is no strong name in the GAC, otherwise it will not be a strong name, but you can store multiple copies of an assembly and the assembly in the GAC can only be deleted by users with certain permissions. )

About the version of the assembly: Each version has a 128-bit version number, expressed as four

Points: Major (for the primary version number, the project is changed when there is a change) .MINOR (add a function to the project

Changed) .build.revision (the next two is automatically updated), these version information can be applying

The assemblyInfo.cs file in the program is viewed.

Another pile of theory, here is introduced to COM application:

Components using the COM service in .NET are called .NET service components, different from general components, difference

The former uses the COM service. The purpose of using .NET service components is to access COM service

Some of the base classes such as ServiceDcomponent and Automatic Transaction, JIT, Objects, and Security

Aspect.

There must be a service component before using the .NET service component, there are three ways:

1, manual registration: registration with the Regsvcs.exe command line tool, such as: Regsvcs

YourComponent.tlb type library will be produced after youRomponent.dll, including object

Type information (Note that you must register a strong name for your enterboon "before using this command)

2, programming registration: use the registrationHelper class, mainly

Method in the IregistrationHelper interface.

3, dynamic registration: Found that check the version of the installation component during the execution of the application, if the correct version of the component is not installed, automatically install the required version at runtime, that is, automatically registration. (Note: Call automatic

Registered users must be a member of the Window2000 Administrative group, because dynamic registration

Method changes the COM directory, otherwise the registration process failed)

OK, finally finished, then see example:

-------------------------------------------------- -------------------------------------------------- --------

Using system; using system.enterpriseServices; // must introduce the namestem.reflection; // must be introduced in the name of the name for use system.windows.Forms;

[Assembly: ApplicationName ("Calcomp")] [Assembly: AssemblyKeyFileAttribute ("Calcomp.snk")] // must first register a strong name called Calcomp.snk, and comment out in an assemblyInfo.cs file in the project [Assembly "[Assembly : AssemblyKeyFileAttribute ("")], otherwise the definition is repeated.

namespace Calcomp {public interface ICommission {void CommissionCal (string name, int salesamt);} public class Calcomp: ServicedComponent, ICommission // inherited ServicedComponent making a service component {public void CommissionCal (string name, int salesamt) {double comm; // string msgstring; if (salesAmt> = 50000) {Comm = salesAmt * 0.10; MessageBox.show (Comm. Tostring (), "Presto Systems");} f (Salesamt <50000) {Comm = Salesamt * 0.05; MessageBox .Show (comm.toString (), "Presto Systems");}}}}

OK, get it, look at how to call this service component ------------------------- -------------------------------------------------- -------------------------

Using system;

namespace CalClient {class Calculate {static void Main (string [] args) {Calcomp.Calcomp c = new Calcomp.Calcomp (); Console.WriteLine ( "please input the employeer name"); String name = Console.ReadLine (); Console.writeline ("please input the salesamt"; string salesamt = console.readline (); c.commissioncal (name, int.parse (salesAmt));}}} (Note: Before using service components, you must first in the project before using service components Add a reference to the DLL generated by the above service components) ------------------------------------- -------------------------------------------------- -------------------------

There are also many features about the COM service component. This small text is just a piece of chicken.

转载请注明原文地址:https://www.9cbs.com/read-7835.html

New Post(0)