ActivatedClientTypeEntry Class
Assembly: mscorlib (in mscorlib.dll)
'Declaration <ComVisibleAttribute(True)> _ Public Class ActivatedClientTypeEntry Inherits TypeEntry 'Usage Dim instance As ActivatedClientTypeEntry
/** @attribute ComVisibleAttribute(true) */ public class ActivatedClientTypeEntry extends TypeEntry
ComVisibleAttribute(true) public class ActivatedClientTypeEntry extends TypeEntry
To create an instance of a client-activated object on the client, you must know its Type and it must be registered on the client by using the RegisterActivatedClientType method. To obtain a proxy for a new instance of the client-activated object the client must first register a channel with ChannelServices and then activate the object by calling new.
To activate a client-activated object type with the new keyword, you must first register the object type on the client using the RegisterActivatedClientType method. By calling RegisterActivatedClientType you are giving the remoting infrastructure the location of the remote application where new attempts to create it. If, on the other hand, you use the Activator.CreateInstance method to create a new instance of the client-activated object, you must supply the remote application's URL as a parameter, so no prior registration on the client end is necessary. To supply the Activator.CreateInstance method with the URL of the server on which you want to create the object, you must encapsulate the URL in an instance of the UrlAttribute class.
For a detailed description of client activated objects and remote object activation see Activation of Remote Objects.
The following code example shows how to use a ActivatedClientTypeEntry to register a client activated remote object. The example contains three parts, a client, a server, and a remote object used by the client and server.
The following code example shows a client:
Imports System Imports System.Runtime.Remoting Imports System.Runtime.Remoting.Channels Imports System.Runtime.Remoting.Channels.Tcp Public Class MyClient Public Shared Sub Main() ' Register TCP Channel. ChannelServices.RegisterChannel(New TcpChannel()) ' Create activated client type entry. Dim myActivatedClientTypeEntry As _ New ActivatedClientTypeEntry(GetType(HelloServer), _ "tcp://localhost:8082") ' Register type on client to activate it on the server. RemotingConfiguration.RegisterActivatedClientType( _ myActivatedClientTypeEntry) ' Activate a client activated object type. Dim myHelloServer As New HelloServer("ParameterString") ' Print the object type. Console.WriteLine("Object type of client activated object: " + _ myActivatedClientTypeEntry.ObjectType.ToString()) ' Print the application URL. Console.WriteLine("Application url where the type is activated: " + _ myActivatedClientTypeEntry.ApplicationUrl) ' Print the string representation of the type entry. Console.WriteLine( _ "Type name, assembly name and application URL " + _ "of the remote object: " + _ myActivatedClientTypeEntry.ToString()) ' Print a blank line. Console.WriteLine() ' Check that server was located. If myHelloServer Is Nothing Then Console.WriteLine("Could not locate server") Else Console.WriteLine("Calling remote object") Console.WriteLine(myHelloServer.HelloMethod("Bill")) End If End Sub 'Main End Class 'MyClient
import System.*;
import System.Runtime.Remoting.*;
import System.Runtime.Remoting.Channels.*;
import System.Runtime.Remoting.Channels.Tcp.*;
public class MyClient
{
public static void main(String[] args)
{
// Register TCP Channel.
ChannelServices.RegisterChannel(new TcpChannel());
// Create activated client type entry.
ActivatedClientTypeEntry myActivatedClientTypeEntry =
new ActivatedClientTypeEntry(HelloServer.class.ToType(),
"tcp://localhost:8082");
// Register type on client to activate it on the server.
RemotingConfiguration.RegisterActivatedClientType(
myActivatedClientTypeEntry);
// Activate a client activated object type.
HelloServer myHelloServer = new HelloServer("ParameterString");
// Print the object type.
Console.WriteLine(("Object type of client activated object: "
+ myActivatedClientTypeEntry.get_ObjectType().ToString()));
// Print the application URL.
Console.WriteLine("Application url where the type is activated: "
+ myActivatedClientTypeEntry.get_ApplicationUrl());
// Print the string representation of the type entry.
Console.WriteLine("Type name, assembly name and application URL "
+ "of the remote object: " + myActivatedClientTypeEntry.ToString());
// Print a blank line.
Console.WriteLine();
// Check that server was located.
if (myHelloServer == null) {
Console.WriteLine("Could not locate server");
}
else {
Console.WriteLine("Calling remote object");
Console.WriteLine(myHelloServer.HelloMethod("Bill"));
}
} //main
} //MyClient
The following code example shows a server for this client:
Imports System Imports System.Runtime.Remoting Imports System.Runtime.Remoting.Channels Imports System.Runtime.Remoting.Channels.Tcp Public Class MyServer Public Shared Sub Main() ChannelServices.RegisterChannel(New TcpChannel(8082)) RemotingConfiguration.RegisterActivatedServiceType(GetType(HelloServer)) Console.WriteLine("Press enter to stop this process") Console.ReadLine() End Sub 'Main End Class 'MyServer
import System.*;
import System.Runtime.Remoting.*;
import System.Runtime.Remoting.Channels.*;
import System.Runtime.Remoting.Channels.Tcp.*;
public class MyServer
{
public static void main(String[] args)
{
ChannelServices.RegisterChannel(new TcpChannel(8082));
RemotingConfiguration.RegisterActivatedServiceType(HelloServer.
class.ToType());
Console.WriteLine("Press enter to stop this process");
Console.ReadLine();
} //main
} //MyServer
The following code example provides the remote object used by the client and the server:
Imports System Public Class HelloServer Inherits MarshalByRefObject Public Sub New(myString As String) Console.WriteLine("HelloServer activated") Console.WriteLine("Parameter passed to the constructor is " + myString) End Sub 'New Public Function HelloMethod(myName As String) As String Console.WriteLine("HelloMethod : {0}", myName) Return "Hi there " + myName End Function 'HelloMethod End Class 'HelloServer
import System.*;
public class HelloServer extends MarshalByRefObject
{
public HelloServer(String myString)
{
Console.WriteLine("HelloServer activated");
Console.WriteLine("Parameter passed to the constructor is "
+ myString);
} //HelloServer
public String HelloMethod(String myName)
{
Console.WriteLine("HelloMethod : {0}", myName);
return "Hi there " + myName;
} //HelloMethod
} //HelloServer
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.