MarshalByRefObject objects are remote objects that run on the server and accept method calls from clients. .NET Remoting
MarshalByRefObjects can be categorized into two groups:
SAOs can be marked as either Singleton or SingleCall. In the first case, one instance serves requests of all clients in a multi-threaded fashion. When using SAOs in SingleCall mode, a new object will be created for each request and destroyed afterwards. Both Singleton and SingleCall SAO modes are supported in VisiBroker for .NET. In addition to that, VisiBroker for .NET supports transient
MarshalByRefObject objects that run either on a server, or on a client for server callback.
A server will implement both the AccountManager interface and the
Account interface. The client will provide the implementation for the
Callback interface so that the bank server can call back to notify the client about all of the banking events.
A server needs to implement the business logic. For the bank example, the bank server needs to provide implementation for both the AccountManager interface and the
Account interface. The following code snippet shows the implementation of the
AccountManager interface and the
Account interface at the server side:
The Open() method of the
AccountManagerImpl class takes in an initial balance and a
Callback object reference that is passed in by the client, then creates a new instance of
AccountImpl class.
The Balance() method of the
AccountImpl class simply returns the balance to the client; the
Credit() method credits the passed in amount to the account balance; the
Debit() method debits the requested amount from the account balance. All of these three account operation events are notified to the client via the
Callback object.
Now that the interface implementation is completed, the next step for the server is to register the AccountManagerImpl object either as a well known
SingleCall service object or as a well known
Singleton object to the .NET Remoting system.
AccountImpl objects are transient as they do not outlive the process that created them.
When a server implementation object is configured as a Singleton well known service type, only one instance of the server implementation object is created. It is this singleton instance that serves all requests coming from all clients. The configuration can be done either explicitly using .NET
RemotingConfiguration APIs, or implicitly using a .NET Remoting configuration file.
Implicit registration of a server implementation object as a well known Singleton service type is done through the
<service> property in the .NET Remoting configuration file as shown in the following example:
and a call to .NET RemotingConfiguration to load in the configuration file:
For more information on Janeva.Remoting.IiopChannel type and its properties, see
“Specifying the Remoting channel”.
When a server object is configured as a well known SingleCall object, the server will create one instance per each client invocation of a method, execute the method and then destroy the object again. Similar to the
Singleton mode, the configuration can be done either explicitly using .NET
RemotingConfiguration APIs, or implicitly using .NET Remoting configuration file.
To register a SingleCall server implementation object explicitly, use the following codes:
To register a SingleCall server implementation object implicitly, change the
<wellknown> property’s mode attribute to be
SingleCall in the .NET Remoting configuration file:
If you compare the output of the bank server example between Singleton and
SingleCall mode, you’ll notice that in
Singleton mode, the
AccountManagerImpl class constructor is invoked only once no matter how many times a client tries to invoke the open method. While in
SingleCall mode, the constructor is invoked once every time when the client invokes the open method.
The .NET remoting configuration file Client.config used by the bank client is listed below:
Refer to “.NET Remoting configuration” for details on how write the Remoting section of the VisiBroker for .NET Remoting configuration file. See
“Configuring properties” for information about configuring VisiBroker for .NET properties in a configuration file.