ActivatedClientTypeEntry 类

将在客户端注册的对象类型的值保存为可以在服务器上激活的类型。

**命名空间:**System.Runtime.Remoting
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
<ComVisibleAttribute(True)> _
Public Class ActivatedClientTypeEntry
    Inherits TypeEntry
用法
Dim instance As ActivatedClientTypeEntry
[ComVisibleAttribute(true)] 
public class ActivatedClientTypeEntry : TypeEntry
[ComVisibleAttribute(true)] 
public ref class ActivatedClientTypeEntry : public TypeEntry
/** @attribute ComVisibleAttribute(true) */ 
public class ActivatedClientTypeEntry extends TypeEntry
ComVisibleAttribute(true) 
public class ActivatedClientTypeEntry extends TypeEntry

备注

若要在客户端上创建客户端激活的对象的实例,则必须知道其 Type,而且必须使用 RegisterActivatedClientType 方法在客户端上注册该对象实例。若要获取客户端激活的对象的新实例的代理,客户端必须首先通过 ChannelServices 注册一个信道,然后调用 new 来激活该对象。

若要激活具有 new 关键字的客户端激活对象类型,必须首先使用 RegisterActivatedClientType 方法在客户端注册该对象类型。通过调用 RegisterActivatedClientType 可为远程处理基础结构提供远程应用程序的位置,new 关键字试图在该处进行创建。另一方面,如果使用 Activator.CreateInstance 方法来创建客户端激活的对象的新实例,则必须提供远程应用程序的 URL 作为参数,因此,没有必要预先在客户端注册。若要为 Activator.CreateInstance 方法提供要在其上创建该对象的服务器的 URL,必须将该 URL 封装到 UrlAttribute 类的实例中。

有关客户端激活对象和远程对象激活的详细说明,请参见 远程对象的激活

示例

下面的代码示例演示如何使用 ActivatedClientTypeEntry 来注册客户端激活的远程对象。此示例包含三个部分:客户端、服务器以及客户端和服务器使用的远程对象。

下面的代码示例演示客户端:

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
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 <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( gcnew TcpChannel );
   
   // Create activated client type entry.
   ActivatedClientTypeEntry^ activatedClientTypeEntry = gcnew ActivatedClientTypeEntry( HelloServer::typeid, "tcp://localhost:8082" );
   
   // Register type on client to activate it on the server.
   RemotingConfiguration::RegisterActivatedClientType( activatedClientTypeEntry );
   
   // Activate a client activated object type.
   HelloServer^ helloServer = gcnew HelloServer( "ParameterString" );
   
   // Print the object type.
   Console::WriteLine( "Object type of client activated object: {0}", activatedClientTypeEntry->ObjectType->ToString() );
   
   // Print the application URL.
   Console::WriteLine( "Application url where the type is activated: {0}", activatedClientTypeEntry->ApplicationUrl->ToString() );
   
   // Print the string representation of the type entry.
   Console::WriteLine( "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( "Could not locate server" );
   }
   else
   {
      Console::WriteLine( "Calling remote object" );
      Console::WriteLine( helloServer->HelloMethod( "Bill" ) );
   }
}
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

下面的代码示例演示此客户端的服务器:

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
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 <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( gcnew TcpChannel( 8082 ) );
   RemotingConfiguration::RegisterActivatedServiceType( HelloServer::typeid );
   Console::WriteLine( "Press enter to stop this process" );
   Console::ReadLine();
}
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

下面的代码示例提供了服务器和客户端使用的远程对象:

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
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 namespace System;
public ref class HelloServer: public MarshalByRefObject
{
public:
   HelloServer( String^ myString )
   {
      Console::WriteLine( "HelloServer activated" );
      Console::WriteLine( "Paramater passed to the constructor is {0}", myString );
   }

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

};
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

继承层次结构

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

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

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

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

ActivatedClientTypeEntry 成员
System.Runtime.Remoting 命名空间
RegisterActivatedClientType

其他资源

客户端激活