WellKnownClientTypeEntry 类

定义

将在客户端注册的对象类型的值保存为服务器激活类型(单个调用或 singleton)。

public ref class WellKnownClientTypeEntry : System::Runtime::Remoting::TypeEntry
public class WellKnownClientTypeEntry : System.Runtime.Remoting.TypeEntry
[System.Runtime.InteropServices.ComVisible(true)]
public class WellKnownClientTypeEntry : System.Runtime.Remoting.TypeEntry
type WellKnownClientTypeEntry = class
    inherit TypeEntry
[<System.Runtime.InteropServices.ComVisible(true)>]
type WellKnownClientTypeEntry = class
    inherit TypeEntry
Public Class WellKnownClientTypeEntry
Inherits TypeEntry
继承
WellKnownClientTypeEntry
属性

示例

#using <System.Runtime.Remoting.dll>
#using <System.dll>
#using <WellKnownClientTypeEntry_Share.dll>

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

int main()
{
   // Create a 'HttpChannel' object and  register with channel services.
   ChannelServices::RegisterChannel( gcnew HttpChannel );
   Console::WriteLine( " Start calling from Client One......." );
   WellKnownClientTypeEntry^ myWellKnownClientTypeEntry = gcnew WellKnownClientTypeEntry( HelloServer::typeid,"http://localhost:8086/SayHello" );
   myWellKnownClientTypeEntry->ApplicationUrl = "http://localhost:8086/SayHello";
   RemotingConfiguration::RegisterWellKnownClientType( myWellKnownClientTypeEntry );

   // Get the proxy object for the remote object.
   HelloServer^ myHelloServerObject = gcnew HelloServer;

   // Retrieve an array of object types registered on the 
   // client end as well-known types.
   array<WellKnownClientTypeEntry^>^myWellKnownClientTypeEntryCollection = RemotingConfiguration::GetRegisteredWellKnownClientTypes();
   Console::WriteLine( "The Application Url to activate the Remote Object :{0}", myWellKnownClientTypeEntryCollection[ 0 ]->ApplicationUrl );
   Console::WriteLine( "The 'WellKnownClientTypeEntry' object :{0}", myWellKnownClientTypeEntryCollection[ 0 ] );

   // Make remote method calls.
   for ( int i = 0; i < 5; i++ )
      Console::WriteLine( myHelloServerObject->HelloMethod( " Client One" ) );
}
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;

public class MyClient 
{
   public static void Main()
   {
   // Create a 'HttpChannel' object and  register with channel services.
   ChannelServices.RegisterChannel(new HttpChannel());
   Console.WriteLine(" Start calling from Client One.......");
   WellKnownClientTypeEntry myWellKnownClientTypeEntry = 
                  new WellKnownClientTypeEntry(typeof(HelloServer),
                                  "http://localhost:8086/SayHello");
   myWellKnownClientTypeEntry.ApplicationUrl="http://localhost:8086/SayHello";
   RemotingConfiguration.RegisterWellKnownClientType(myWellKnownClientTypeEntry);
   // Get the proxy object for the remote object.
   HelloServer myHelloServerObject = new HelloServer();
   // Retrieve an array of object types registered on the 
   // client end as well-known types.
   WellKnownClientTypeEntry [] myWellKnownClientTypeEntryCollection = 
          RemotingConfiguration.GetRegisteredWellKnownClientTypes();
   Console.WriteLine("The Application Url to activate the Remote Object :"
        +myWellKnownClientTypeEntryCollection[0].ApplicationUrl);
   Console.WriteLine("The 'WellKnownClientTypeEntry' object :"
            +myWellKnownClientTypeEntryCollection[0].ToString());
   // Make remote method calls.
   for (int i = 0; i < 5; i++)
         Console.WriteLine(myHelloServerObject.HelloMethod(" Client One"));
   }
}
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Http

Public Class MyClient
   
   Public Shared Sub Main()
      ' Create a 'HttpChannel' object and  register with channel services.
      ChannelServices.RegisterChannel(New HttpChannel())
      Console.WriteLine(" Start calling from Client One.......")
      Dim myWellKnownClientTypeEntry As New WellKnownClientTypeEntry(GetType(HelloServer), _ 
                                                  "http://localhost:8086/SayHello")
      myWellKnownClientTypeEntry.ApplicationUrl = "http://localhost:8086/SayHello"
      RemotingConfiguration.RegisterWellKnownClientType(myWellKnownClientTypeEntry)
      ' Get the proxy object for the remote object.
      Dim myHelloServerObject As New HelloServer()
      ' Retrieve an array of object types registered on the 
      ' client end as well-known types.
      Dim myWellKnownClientTypeEntryCollection As WellKnownClientTypeEntry() = _ 
                                       RemotingConfiguration.GetRegisteredWellKnownClientTypes()
      Console.WriteLine("The Application Url to activate the Remote Object :" + _ 
                                           myWellKnownClientTypeEntryCollection(0).ApplicationUrl)
      Console.WriteLine("The 'WellKnownClientTypeEntry' object :" + _ 
                                              myWellKnownClientTypeEntryCollection(0).ToString())
      ' Make remote method calls.
      Dim i As Integer
      For i = 0 To 4
         Console.WriteLine(myHelloServerObject.HelloMethod(" Client One"))
      Next i
   End Sub
End Class

注解

服务器激活的类型可以是单个调用或单一实例。 如果类注册为单个调用类型,则每次客户端的调用到达时都会创建一个新实例。 对单一实例对象的所有调用都由该对象的一个实例处理,除非已收集该对象。

任何知道已注册服务器激活对象的 URI 的客户端都可以通过注册首选 ChannelServices 通道并通过调用 newActivator.GetObject来激活对象来获取此对象的代理。 若要使用 new激活服务器的对象,必须先使用 RegisterWellKnownClientType 方法在客户端上注册服务器激活的对象类型。 通过调用 RegisterWellKnownClientType,可以向远程处理基础结构提供远程对象的位置,从而允许 new 关键字创建它。 另一方面,如果使用 Activator.GetObject 方法激活服务器激活的对象,则必须提供该对象的 URL 作为参数,因此无需事先在客户端上注册。

有关服务器激活的对象和远程对象激活的详细说明,请参阅 远程对象的激活

构造函数

WellKnownClientTypeEntry(String, String, String)

使用给定的类型、程序集名称和 URL,初始化 WellKnownClientTypeEntry 类的新实例。

WellKnownClientTypeEntry(Type, String)

使用给定的类型和 URL 初始化 WellKnownClientTypeEntry 类的新实例。

属性

ApplicationUrl

获取或设置在其中激活该类型的应用程序的 URL。

AssemblyName

获取配置为远程激活类型的对象类型的程序集名称。

(继承自 TypeEntry)
ObjectType

获取服务器激活客户端类型的 Type

ObjectUrl

获取服务器激活客户端对象的 URL。

TypeName

获取配置为远程激活类型的对象类型的完整类型名。

(继承自 TypeEntry)

方法

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

String 的形式返回服务器激活客户端类型的完整类型名称、程序集名称和对象 URL。

适用于

另请参阅