Export (0) Print
Expand All

ActivatedClientTypeEntry Class

Holds values for an object type registered on the client end as a type that can be activated on the server.

Namespace:  System.Runtime.Remoting
Assembly:  mscorlib (in mscorlib.dll)

[ComVisibleAttribute(true)]
public class ActivatedClientTypeEntry : 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 [<topic://cpconActivation>].

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:

using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

public class MyClient
{
    public static void Main()
    {
        // Register TCP Channel.
        ChannelServices.RegisterChannel(new TcpChannel());

        // Create activated client type entry.
        ActivatedClientTypeEntry myActivatedClientTypeEntry =
            new ActivatedClientTypeEntry(typeof(HelloServer),
            "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.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 == null)
        {
            Console.WriteLine("Could not locate server");
        }
        else
        {
            Console.WriteLine("Calling remote object");
            Console.WriteLine(myHelloServer.HelloMethod("Bill"));
        }
    }
}
#using <mscorlib.dll>
#using <System.Runtime.Remoting.dll>
#using <ActivatedClientTypeEntry_Share.dll>
using namespace System;
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Channels;
using namespace System::Runtime::Remoting::Channels::Tcp;

static void main()
{
    // Register TCP Channel.
    ChannelServices::RegisterChannel(new TcpChannel());

    // Create activated client type entry.
    ActivatedClientTypeEntry* activatedClientTypeEntry =
        new ActivatedClientTypeEntry(__typeof(HelloServer),
        "tcp://localhost:8082");

    // Register type on client to activate it on the server.
    RemotingConfiguration::RegisterActivatedClientType
        (activatedClientTypeEntry);

    // Activate a client activated object type.
    HelloServer* helloServer = new HelloServer(S"ParameterString");

    // Print the object type.
    Console::WriteLine(
        S"Object type of client activated object: {0}",
        activatedClientTypeEntry->ObjectType->ToString());

    // Print the application URL.
    Console::WriteLine(
        S"Application url where the type is activated: {0}",
        activatedClientTypeEntry->ApplicationUrl->ToString());

    // Print the string representation of the type entry.
    Console::WriteLine(
        S"Type and assembly name and application URL of the remote object: {0}",
        activatedClientTypeEntry->ToString());

    // Print a blank line.
    Console::WriteLine();

    // Check that server was located.
    if (!helloServer)
    {
        Console::WriteLine(S"Could not locate server");
    }
    else
    {
        Console::WriteLine(S"Calling remote object");
        Console::WriteLine(helloServer->HelloMethod(S"Bill"));
    }
};

The following code example shows a server for this client:

using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

public class MyServer
{
    public static void Main()
    {
        ChannelServices.RegisterChannel(new TcpChannel(8082));
        RemotingConfiguration.RegisterActivatedServiceType(typeof(HelloServer));
        Console.WriteLine("Press enter to stop this process");
        Console.ReadLine();
   }
}
#using <mscorlib.dll>
#using <ActivatedClientTypeEntry_Share.dll>
#using <System.Runtime.Remoting.dll>

using namespace System;
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Channels;
using namespace System::Runtime::Remoting::Channels::Tcp;

void main()
{
    ChannelServices::RegisterChannel(new TcpChannel(8082));
    RemotingConfiguration::RegisterActivatedServiceType(__typeof(HelloServer));
    Console::WriteLine(S"Press enter to stop this process");
    Console::ReadLine();
}

The following code example provides the remote object used by the client and the server:

using System;
public class HelloServer : MarshalByRefObject
{
    public HelloServer(String myString)
    {
        Console.WriteLine("HelloServer activated");
        Console.WriteLine("Parameter passed to the constructor is "+myString);
    }
    public String HelloMethod(String myName)
    {
        Console.WriteLine("HelloMethod : {0}",myName);
        return "Hi there " + myName;
    }
}
#using <mscorlib.dll>
using namespace System;
__gc public class HelloServer : public MarshalByRefObject
{
public:
    HelloServer(String* myString)
    {
	    Console::WriteLine(S"HelloServer activated");
	    Console::WriteLine(S"Paramater passed to the constructor is {0}", myString);
    };

    String* HelloMethod(String* myName)
    {
	    Console::WriteLine(S"HelloMethod : {0}", myName);
	    return String::Format(S"Hi there {0}", myName);
    };
};

System.Object
  System.Runtime.Remoting.TypeEntry
    System.Runtime.Remoting.ActivatedClientTypeEntry

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft