Transaction 1 in DOTNET and COM +

Source: Internet
Author: User
Tags dotnet

Http://china.udotnet.com/cnudotnet_num_416.aspx

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

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

Stingy god

2002-4-16

 

Article type: In-Depth

Difficulty level: 6/9

Version: 2.32

 

 

COM + appeared earlier than DOTNET and has become a solution and operation platform for distributed and enterprise-level development on Windows platform over the past few years, it provides some general and underlying facilities for enterprise-level applications, especially the middle layer infrastructure modules of multi-layer application models, with this help, developers can focus more on the application's business logic itself. Interestingly, sometimes it does not really make us satisfied. It is worth mentioning that it started with its father-in-law, has always been a part of the operating system. DOTNET is a next-generation Web-oriented development platform recently published by Microsoft. Compared with all of its predecessors, it is ambitious and imposing, so it is crazy and exciting. For DOTNET, COM + is a mature and significant historical partner, and for COM +, DOTNET is a fresh and slightly aggressive new and expensive friend, no matter what the two do, for non-local developers, getting along with and interacting with them will become a major bottleneck. What's worse is that DOTNET and COM + are constantly developing and changing. So there must be some interesting things, And we narrow down the scope and focus on the transaction programming that may be closely related during our development process. It can be said that, changes have brought about many new changes and new thinking from developers. In the subsequent articles, you will gradually see the inspiration and benefits they have brought to me, in this case, we hope that more people will be able to think and inspire.

 

Eliminate some vague concepts

For a while, we have some vague concepts about DOTNET, CLR, COM, and COM +. DOTNET is the next-generation development platform defined by Microsoft. CLR (Common Language Runtime) is the core and heart of DOTNET, and is also Microsoft's implementation of ECMA specifications on a Windows platform. COM (Component Object Model) is a component object model that provides basic mechanisms and principles for interaction and interaction between components. It is a component development technology and programming model. COM + is a component runtime environment. It provides a series of component runtime environments and toolkit for a collection of services related to distributed system functions. The CLR replaces COM, but it cannot and does not replace COM +. COM + is now called. NET Enterprise Services, of course, if not. net prefix, Enterprise Services can best reflect the role and definition of COM +. CLR is closer to the application layer, and COM + is closer to the operating system.. Net Operating System for a series of enhancements to COM +: application partitioning, application pooling and recycling, resource manager, retriable transaction isolation level, web services, and so on (see Juval Lowy's article, some low-level program APIs, CLR cannot provide corresponding functions at all, and wrapping these new COM + APIS is also required. Of course, we cannot be sure of the future. These COM + APIs are directly implemented using C # or other CLR-managed APIs. Currently, it can be said that if you used the COM technology to work well in the COM + environment (or very painful), it would be equally good to use the CLR to work in the COM + environment, in addition, it is convenient and fast. DOTNET makes it easier and more efficient for developers to use COM +. This is like introducing a graphical mouse interface (DOTNET) from the character keyboard interface (COM) many years ago) it is the same as a revolution in the use of computers (COM +.

 

Use the COM + Transaction Service in DOTNET

The following steps are required to use COM + and transaction services in the DOTNET environment:

1. Implement a COM + configured class

We only inherit a class from system. enterpriseservices. servicedcomponent, and then provide a default constructor.

2. Declare distributed transactions

You can add the transaction attribute before such a name, for example, [transaction (transactionoption. Required)].

3. Submit the transaction

Iobjectcontrol: setcomplete or directly use AutoComplete ()]

4. Other iobjectconstruct, iobjectcontrol, pooling, and justintimeactivation

A) iobjectconstruct: add the [constructionenabled (default = "connection string")] Attribute before the class name, and overwrite the public override void construct (string constructstring ){}

B) pooling: add the attribute [objectpooling (true, 3, 30)] before the class name, and then overwrite the canbepooled method. Public override bool canbepooled () {return true ;}

C) justintimeactivation: add the attribute [justintimeactivation (true)]

 

5. compilation and distribution

A) Component Registration

[Assembly: applicationname ("mydotnetcomapp")]

[Assembly: applicationactivation (activationoption. Library)]

B) strong component name

[Assembly: assemblykeyfile ("Keyfile. SNK")]

In this step, if sn.exe is created first. the SNK file is then stored in.. Net ide To Open assemblyinfo. CS, adding the above line seems more convenient, so you don't need to manually build CSC,. net. Try 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 (regsvcsautomatically calls regasm.exeand tlbexp.exe)

 

A rough file may look like this below. Forgive me for displaying too many attributes first :)

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")]

[Assembly: applicationactivation (activationoption. Library)]

 

// [Assembly: assemblykeyfile (".. // Keyfile. SNK")]

 

Namespace dotcnetwork. dbclass

{

/// <Summary>

/// Summary description for class1.

/// </Summary>

[Constructionenabled (default = "Server = localhost; uid = sa; Pwd =; initial catalog = pubs")]

// [Eventtrackingenabled]

[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. Length = 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;

}

}

}

 
 

For more information about how to generate a DOTNET component and register it in the COM + environment and how the client calls the specific steps and instances, refer to Microsoft's standard specifications and suggestions.

 

 

(Unfinished)

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

Note:

This document is the first release of the csdn signature. for reprinting or adaptation, please indicate the author and source. If you have any questions, please email your new2001@msn.com

The text and images mentioned above involve the privacy and personal rights of others. All texts and images are only used for internal communication and are not used for news or commercial purposes.

 

--------------------------------------------------------------------------------
Copyright? 2005 China. udotnet. com

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.