I. Question proposal: (The following lists my problems) 1. Each request of the end user reads the mapping file, which can be resolved through the cache; 2. The xxx subsystem needs to constantly write the mapping file. You can also write the file into the memory and then write the file in batches; Ii. analyze and solve the problem: Because there are two or more subsystems that need to read and write the same file, and the client has a large degree of concurrency, read/write conflicts or errors are very likely to occur, it will also affect the system performance. Read and Write files by calling a common out-of-process component, which loads the file content to the memory only when it is started, and updates the memory when the file changes. Iii. Introduction to COM + components: As early as the release of window2000, COM + was generated and integrated into the operating system. It existed as a service during operation. COM + adds a series of MTS (a system service used to manage persistent data in the database, and also to process persistent message queues and file systems in transactions) services: 1. Transaction Service: It ensures data integrity in distributed systems. 2. Security Service: its security model provides processing security without writing anyCode. 3. Synchronization Service: provides a management method to solve the concurrency problem in components, but does not need to write code. 4. Resource Management: (including resource manager and resource distributor) manages database connections, network connections, and memory. 5. JIT activation: Just in time is a service inherited from Mts, an instance of this object remains active and cached in the server memory only when the customer calls it. After the object is used up, the MTS environment is notified to release the resources occupied by the object, such as database connection. 6. Object pool: provides a thread pool to store ready-made objects for future use. It is an automatic service of the system. When there is an applicationProgramWhen you access the COM + component, an instance of this component is created for the application and stored in the object pool. When the application is closed, the instance is destroyed, the component can be freely configured to make its instance status in the pool, realizing the reusability of the instance and improving the performance and scalability of the application. 7. Role-based security: This is easy to understand, that is, to verify the role, give security permissions, and grant different permissions to different users. 8. Queue component (MSMQ): provides an asynchronous message queue, which can automatically convert data into data packets. 9. Shared Property Manager (SPM): used to manage the object state information stored in the memory. It can be used to share the State among multiple objects in a server process and provide concurrent processing. 10. Compensation Resource Manager (CRM): used to generate log files during transaction processing and handle system crashes. Includes CRM worker (which is the main part of CRM. It writes transaction-related information to logs through interfaces provided by CRM infrastructure and retrieves log files as needed) and CRM compensator (used to submit the transaction and generated log files to the user who executes the transaction after the transaction is completed ). 11. Concurrency: Allows multiple processes in an application to run simultaneously, and processes are divided into different groups of contexts (sets of objects with the same requirements) contained in a unit (a group of contexts within a process), a process can contain multiple contexts, objects with different requirements are involved, and each context has a unique COM object to provide services such as COM + transaction processing and JIT activation. Using the tools provided by COM +, you can create multi-tier applications that execute transactions and handle thread allocation issues. OK. After introducing the COM + function, next we will introduce the COM + type. COM + has several different usage types: 1. application proxy: a file containing application registration information, that is, when a customer accesses a server program on a remote computer, the application agent running on the client writes information about the server application to the client computer. 2. server applications: Execute COM + applications in the processes of COM + applications, and use concurrency to process components. 3. Database Application: it is executed within the process of the customer application and loaded in the Process of the customer application. It uses task-based security, the disadvantage is that remote access and queue components are not supported. 4. COM + pre-installed applications: Go to the COM + application folder in the component service in the management tool to see what the COM + pre-installed application is, it is an application automatically installed in the component service during the COM + installation process and cannot be modified or deleted. It also involves the concept of "assembly": it is a set of all CLR types and other resources (such as bitmap files. You can view the configuration. NET Framework in the management tool. Includes private and shared assemblies. Private Assembly: It can only be accessed by applications in the same path as the assembly. The default value is private and must be placed in the folder of the application that uses it. Shared Assembly: an Assembly added to GAC (Global Assembly Cache. GAC is used to store the Assembly so that the application can share the Assembly. Note that the Assembly stored in GAC must have a unique name. in the net Command Execution window, enter Sn-K assemblyname. the SNK generates a unique name, called a strong name. After a strong name is generated, a public key is appended to this Assembly to prevent similar names from being replaced. . NET provides two mechanisms for Assembly Security: Strong names and signcode (which can be understood as digital signatures ). Signcode.exe is used to mark an assembly and embed a digital signature into the Assembly so that users can identify the developers who created the assembly. (Note: there cannot be two strong names with the same name in GAC; otherwise, they will not be called, however, it can store multiple copies of an assembly and the Assembly in GAC can only be deleted by users with certain permissions) About the assembly version number: each version has a 128-bit version number, which is represented in four parts: Major (the main version number, which is changed when the project changes ). minor (changed when a function is added to the project ). build. revision (the last two are automatically updated). The version information can be obtained through assemblyinfo in the application. to view the CS file. There are a bunch of theories. The following describes the application of COM +: In. the COM + service component in. NET is called.. net service components, unlike general components, the difference is that the former uses the COM + service. The purpose of using the. net service component is to access some basic classes of the COM + service, such as servicedcomponent, automatic transaction processing, JIT, Object pool, and security. You must register the service components before using the. NET service components. There are three methods: 1. manual registration: You can use the regsvcs.exe command line tool for registration, for example, regsvcs yourcomponent. the dll will generate a yourcomponent. TLB Type Library, including object type information (note that you must register a strong yourcomponent name before using this command) 2. Programming registration: Use the registrationhelper class, mainly using methods in the iregistrationhelper interface. 3. Dynamic Registration: Check the version of the installed component during application execution. If the correct version of the component is not installed, the required version is automatically installed at runtime, automatic Registration. (Note: The user who calls automatic registration must be a member of the window2000 Administrative Group, because dynamic registration cannot change the COM + directory; otherwise, the registration process fails) Iv. instance analysis 1. Create a new class library. (Xmloperate in my project) It will generate two files, assemblyinfo. CS and class1.cs (I changed class1.cs to main. CS, and the specific name can be set by myself) 2. Add reference (system. enterpriseservices) 3. Return to main. CS: Using system; Using system. reflection; Using system. runtime. interopservices; Using system. enterpriseservices; Namespace xmloperator { /// <Summary> /// Summary of ompmsaxmloperator. /// </Summary> [Objectpooling (minpoolsize = 0, maxpoolsize = 1)] [Justintimeactivation (true)] [Classinterface (classinterfacetype. autodual)] Public class xmloperate: servicedcomponent { Protected override void construct (string constructstring) { Base. Construct (null ); } Protected override void activate (){} Protected override void deactivate (){} Protected override bool canbepooled () {return true ;} Protected override void dispose (bool disposing) { Base. Dispose (disposing ); } /// /// Remove many of my methods, and write a simple visit to demonstrate it. /// [AutoComplete] Public String visit (string name) { Return "welcome" + name; } } } 4. Return to assemblyinfo. CS and add the reference using system. enterpriseservices; Add code: // Set the component to the server startup mode. [Assembly: applicationactivation (activationoption. Server)] // Specify the application server name [Assembly: applicationname ("xmloperate")] 5. Next, give the server program a strong name (equivalent to registration ). Open the Visual Studio. net2003 (maybe you are using 2005) command prompt, find the file address, enter Sn-K, generate the key, for example, my file is in disk D, work, D: \ work \ xmloperate> Sn-K xmloperate. SNK Xmloperate. SNK is the name of the generated file. (After execution, a file server. SNK will be added to the file) 6. After a strong name is generated, return to the program and go to assemblyinfo. in the last few lines of CS, We can find [Assembly: assemblykeyfile ("")], write the file path into [Assembly: assemblykeyfile (".. /.. /xmloperate. SNK ")] 7. Generate a solution. There will be an xmloperate. dll in OBJ \ debug, return to the Visual Studio. net2003 command prompt, go to the OBJ \ DEBUG directory of the file, execute the regsvcs command, and register the service. (You do not need to manually register. In Step 9, the system automatically registers the component service if it is not registered when the client calls New. For details, see (3) part of the final registration method .) This is the case in my project. D: \ work \ xmloperate \ OBJ \ debug> regsvcs xmloperate. dll; In this way, the server is built. Open my computer, control panel, management tools, component services, and COM + applications. Now we can see that there are more than one in COM +, and xmloperate is the newly created server. 8. Right-click xmloperate to Open Properties and modify Security: The call identity verification level is none, and the simulation level is identity. Remove the authorization check box (these are changed according to the situation, and now only a column on the local machine ). Then find activation and change the remote server name to the IP address of your machine. 9. Create a client. Create a winfrom (in my project, there is actually one Web Service and one window service to call xmloperate) Add reference: Using system. enterpriseservices; Using xmloperate; You can use the method directly in the new place to be referenced by the client. |