One of the new transactions: DOTNET and COM + transactions (1)

zhaozj2021-02-17  68

One of the new matters: transactions in DOTNET and COM

Mood

2002-4-16

Article Type: in-depth

Difficult Level: 6/9

Version: 2.32

COM appears as DOTNET, and has become a solution and operation platform for distributed and enterprise-level development under the Windows platform in these years, which presets some universal and underlying facilities for enterprise applications, especially The infrastructure module of the intermediate layer of the layer application model, with it to make the developer more energy to put the application's business logic itself, interesting is sometimes it doesn't really satisfy us, it is worth mentioning from it The father of the child has always been part of the operating system. The DOTNET is a recently published next generation of Microsoft's development platform, which is ambient and huge, so it is so crazy and exciting than all the predecessors. For DOTNET, COM is a mature and significant history partner, and DOTNET is a fresh and slight aggressive new friend, regardless of both the developers, how to They will get along with interactions, they will become a small bottleneck, some bad is DOTNET and COM in us, and growing and changing. So there must be some interesting things, and we narrow the range, focus on the transaction programming that may be closely related in our development process, can be said that changes have brought many new changes and brings new people. Thinking, in the later article, you will see their inspiration and benefits from them, so I hope that I can also bring more people to inspire and think.

Eliminate some blurred concepts

For a while, we have some blurred concepts for DotNet, CLR, COM, COM , DOTNET is the next-generation development platform defined by Microsoft. CLR (Common Language Runtime) is the core and heart of the DOTNET, as well as Microsoft's implementation of a Windows platform for ECMA specifications. Com (Component Object Model) is a component object model that provides basic mechanisms and principles for interaction and role between components, which are a component development technology and programming model. COM is a component running environment that provides a series of Component Running Environment and Toolkit for Services collection on distributed system features. CLR replaces COM, but it cannot be replaced with COM , COM is now called .NET Enterprise Services, of course, if not .NET's prefix, Enterprise Services can best embody the roles and definitions of COM . CLR is close to the application layer, while COM is closer to the operating system, a series of enhancements for Com for the most recent Windows.net operating system: Application Partition, Application Pooling and Recycling, Resource Manager, Configurable Transaction Isolation Level, Web Services, etc. For details on Juval Lowy's article, some low-level procedural APIs, CLRs are not available at all, and Wrapping is required for these new COM APIs. Of course, it is not possible to definite the future, these COM APIs are directly implemented with C # or other CLR-Managed APIs. It can be said that if you used COM technology to work well (or very painful) in a COM environment, then it is also very good to work with CLR in COM , and it is convenient and fast; DOTNET makes developers use COM More convenient and efficient, this is the same as many years before the introduction of the character keyboard interface (COM) is the same as a revolution of the usage of the computer (COM ). Transaction services using COM in DOTNET

Using COM and transaction services under DOTNET Environment Some steps:

1. Implement a COM Configured class

We only inherit a class from System.EnterpriseServices.ServicedComponent, then provide a default constructor

2. Disclaimer distributed transactions

Use only such names to add transaction attributes, such as: [Transaction (TransactionOption.Required)]

3. Submit a transaction

IOBJECTCONTROL :: setcomplete or direct use of automatic completion properties [AutoComplete ()]

4. Other IObjectConstruct, IObjectControl, Pooling, JustintimeActivation

A) iObjectConstruct: Class Download Pre-[Constructionenabled (Default = "Connection String")] Properties, then override the method public override void construct (String ConstructionString) {}

B) Pooling: Class Name Poly Properties [ObjectPooling (True, 3, 30)], then override the Canbepooled method, public override boel;} c) JustInTimeActivation: plus propertyActivation (TRUE)]

5. Compilation and distribution

a) Component registration

[Assembly: ApplicationName ("MyDotNetcomapp"]]]

[assmbly: ApplicationActivation (ActivationOption.Library)]

b) Strong name

[Assembly: AssemblyKeyFile ("KeyFile.snk")]]]

This step will generate SN.EXE production. SNK files and open assemblyinfo.cs in VS.NET IDE, add the top lines that seem to be more convenient to compile, VS.NET can compile the famous Assembly. Try using AssemblyInfo.cs to be more standardized and unified.

c) Compile components

Sn -k keyfile.snk

CSC / OUT: DBClass.dll / T: library /r :system.EnterpriseServices.dll dbclass.cs

d) Publish registration

Regsvcs dbclass.dll (regsvcs automatically calls Regasm.exe and TLBEXP.exe)

A rough file may be like this, first forgive me, I show too much attribute :)

Using system;

Using System.EnterpriseServices; // Namespace Necessary for Creating COM Application

Using system.reflection;

Using system.Runtime.compilerServices;

Using system.Runtime.InteropServices;

[Assembly: ApplicationName ("ComplusSamplesLib")]]

[assmbly: ApplicationActivation (ActivationOption.Library)]

// [assembly: assemblykeyKeyfile ("..//// keyfile.snk")]

Namespace dotcnetwork.dbclass

{

///

/// summary description for class1.

///

[Constructionenabled (default = "server = localhost; uid = sa; pwd =; initial catalog = pubs")]

// [EventTrackinageNabled]

[ObjectPooling (MINPOOLSIZE = 2, MaxPoolsize = 50)]

[Transaction (TransactionOption.Required)]

[Synchronization (SynchronizationOption.Required)]

JustInTimeActiVation (TRUE)]

[GUID ("569A14C1-5DAD-4C8F-BB48-89DDD89FAD7A")]

Public Class Author: ServicedComponent

{

Private const string connString = "server = localhost; uid = sa; pwd =; initial catalog = pub"; private string connString

Public author ()

{

//

// Todo: add constructor logic here

//

}

// jit / pooling

protected override void activate ()

{}

// jit / pooling

protected override void deactivate ()

{}

// jit / pooling

Protected Override Bool Canbepooled ()

{Return True;}

// construct string

Protected Override Void Construct (String S)

{

IF (s.ley == 0 || s == null)

{

Connstring = connString;

}

Connstring = s;

}

// my function

Public bool alive ()

{

Try

{

// commit the transaction

Contextutil.setComplete ();

Return True;

}

Catch (Exception E)

{

Contextutil.Setabort ();

Return False;

}

}

[AutoComplete]

Public String getConnectionstr ()

{

Return connString;

}

}

}

With regard to how to generate a DOTNET component and sign up to the specific steps and instances of how the client calls, please refer to Microsoft standard specification and suggestions.

(Fail)

especially:

This article 9CBS signature start, reprint, or adaptation, please indicate the author and the source. If there is a problem, please send an email to new2001@msn.com

The above text and pictures involve other people's privacy and personal rights, all texts and pictures are only used for internal communication and do not make any news published and commercial purposes.

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

New Post(0)