Showing posts with label service component. Show all posts
Showing posts with label service component. Show all posts

04 September 2004

Should I use SetAbort()/SetComplete() or DisableCommit()/EnableCommit()?

It was originally from a MCP vendor exercise question. I have it modified slightly:


You are creating a serviced component named UserManager. UserManager adds user
accounts to multiple transactional data sources.
The UserManager class includes the following code segment:

[Transaction(TransactionOption.Required)]
[ObjectPooling(true, MinPoolSize=1, MaxPoolSize=50)]
[JustInTimeActivation()]
public class UserManager : ServicedComponent {
public void AddUser(string TestKname, string TestKpassword)
{
// Code to add the user to data sources goes here.
}
}

You must ensure that the AddUser method reliably saves the new user to either all data
sources or no data sources. What should you do?
A. To AddUser, add the following attribute:
[AutoComplete()]
B. To UserManager, add the following attribute:
[JustInTimeActivation(false)]
C. To the end of AddUser, add the following line of code:
ContextUtil.EnableCommit();
D. To the end of AddUser, add the following line of code:
ContextUtil.SetComplete();
E. To the end of AddUser, add the following line of code:
ContextUtil.MyTransactionVote = true;


IMHO, there are two issues need to be addressed here:
1. Object activation and pooling. .NET 247 : object persistence across client method calls discusses this issue. Basically, the ‘done’ flag decide whether an object is ‘done’ and can be deactivated.
2. MyTransactionVote or consistent flag.

The SDK Doc says, ‘When MyTransactionVote is set to Commit, the COM+ consistent bit is set to true and the COM+ context votes to commit the transaction. If MyTransactionVote is set to Abort, the consistent bit is set to false and the COM+ context votes to abort the transaction.’

And here is matrix of the four methods:
METHOD---------------consistent---------------done
SetComplete()------------true-----------------true
SetAbort()---------------false----------------true
EnableCommit()-----------true-----------------false
DisableCommit()----------false----------------false

The question is about when and how to do 1) ‘all or not’ transaction; 2) object activation and pooling.
EnableCommit() cast a 'go' vote for transaction yet maintain the object as activated so C will be the best answer.

27 July 2004

Remoting Basic

MarshalByRef executes remote method calls on the server side. Only ObjRef-networked object pointer is passed around. Client doesn't have the complied object, but the interface or base class to the object.

ByValue - class need to be serializable. Object is serialized to binary or string(xml) and transport between server/client. It then restored to a copy of the original object at the other end. Which means client and server both need the complied class prototype. State info is preserved.

Basic Architecture
At least three three assemblies are needed for a .net remoting project:
1. Shared Assembly: Client and server both need to have access to the same interface definition (MarshalByRef), serializable objects(ByValue)
2. Server
3. Client

Implement remoting project: Life Cycle
1. Implement SharedAssembly
1.1 Define the remote interface
1.2 Define data class that will be passed around in the shared

2. Implement Server
2.1 Implement the interface by Server.
2.2 Create a new channel and register it to the remoting service.
2.3 Register the server service as "RegisterWellKnownServiceType"

3. Implement client
3.1 Registering client channel
3.2 create local proxt object to forward calls to server

28 June 2004

ASMX serialization vs. binary serialization with remoting

Remoting is useful for crossing app domains, but not for crossing machine boundaries. Check
this