
7.15.2002
Remoting - Private Object per Caller
Remoting server object with "factory" pattern.The only two settings in WellKnownObjectMode enum are SingleCall (every incoming message gets a new instance) and Singleton, (all incoming messages get the same instance). Neither of these are the same pattern as a standard remotable COM object, where each unique client caller instantiates and keeps a unique remote object.
To simulate this, you can implement a factory pattern. A class function (sometimes static) that creates new instances of the remotable object and returns their interface.
(See sample code in link).
public class CorporateAccountantExamFactory :
MarshalByRefObject, IAccountantExamFactory
{
public IAccountantTest CreateAccountTestInstance()
{
return new CorporateAccountantTest();
}
}
}
TcpServerChannel chl =
new TcpServerChannel(9988);
ChannelServices.RegisterChannel(chl);
RemotingConfiguration.
RegisterWellKnownServiceType(
typeof(CorporateAccountantExamFactory), // Name
"IExamFactory", // What the outside world calls it
WellKnownObjectMode.SingleCall); // How to contact
Comments:
Post a Comment