7.10.2. Implementation

An implementation must register the type either as a well known service by calling the RegisterWellKnownServiceType function, or as a client activated service by calling the RegisterActivatedServiceType function, which internally registers a well known activation service for the type. A well known service runs in one of two server activation modes, Singleton or SingleCall. In the Singleton mode, a single instance of the implementation is created and used by all calls, in the SingleCall mode, a new instance of the implementation is created for each call.

With client activated service, the client can create instances on the server simply by calling new. For this, the remote implementation must be registered by the RegisterActivatedClientType function. To avoid the need to refer to the remote implementation type on the client, a factory interface is typically registered.

Apart from the type, the server must create and register a channel, which represents the transport layer. TCP and HTTP channels are available. The TCP channel supports binary and SOAP encoding over TCP. The HTTP channel supports SOAP encoding over HTTP.

TcpChannel channel = new TcpChannel (12345);
ChannelServices.RegisterChannel (channel);

RemotingConfiguration.RegisterWellKnownServiceType (
  typeof (Example), "Example",
  WellKnownObjectMode.Singleton);

Besides registering the type and the channel programmatically, a configuration file describing the type and the channel can be read in by a single method call to RemotingConfiguration.Configure.

TcpChannel channel = new TcpChannel ();
ChannelServices.RegisterChannel (channel);

Example obj = (Example) Activator.GetObject (
  typeof (Example), "tcp://localhost:12345/Example");

obj.printMessage ("Hello World !");

The call to GetObject requires the caller to supply the type for which the proxy is to be created. Typically, this is an interface type rather than a class type.