RemotingConfiguration.RegisterWellKnownClientType 方法

定义

将客户端上的对象 Type 注册为已知类型(“单个调用”(singlecall) 或 singleton)。

重载

RegisterWellKnownClientType(WellKnownClientTypeEntry)

将在客户端提供的 Type 中记录的对象 WellKnownClientTypeEntry 注册为可在服务器上激活的已知类型。

RegisterWellKnownClientType(Type, String)

通过使用给定的参数初始化 Type 类的新实例,将客户端上的对象 WellKnownClientTypeEntry 注册为可在服务器上激活的已知类型。

RegisterWellKnownClientType(WellKnownClientTypeEntry)

将在客户端提供的 Type 中记录的对象 WellKnownClientTypeEntry 注册为可在服务器上激活的已知类型。

public:
 static void RegisterWellKnownClientType(System::Runtime::Remoting::WellKnownClientTypeEntry ^ entry);
public static void RegisterWellKnownClientType (System.Runtime.Remoting.WellKnownClientTypeEntry entry);
static member RegisterWellKnownClientType : System.Runtime.Remoting.WellKnownClientTypeEntry -> unit
Public Shared Sub RegisterWellKnownClientType (entry As WellKnownClientTypeEntry)

参数

entry
WellKnownClientTypeEntry

已知类型的配置设置。

例外

在调用堆栈上部,至少有一个调用方没有配置远程处理类型和通道的权限。

注解

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

有关已知对象的详细说明,请参阅 服务器激活

另请参阅

适用于

RegisterWellKnownClientType(Type, String)

通过使用给定的参数初始化 Type 类的新实例,将客户端上的对象 WellKnownClientTypeEntry 注册为可在服务器上激活的已知类型。

public:
 static void RegisterWellKnownClientType(Type ^ type, System::String ^ objectUrl);
public static void RegisterWellKnownClientType (Type type, string objectUrl);
static member RegisterWellKnownClientType : Type * string -> unit
Public Shared Sub RegisterWellKnownClientType (type As Type, objectUrl As String)

参数

type
Type

对象 Type

objectUrl
String

已知客户端对象的 URL。

例外

在调用堆栈上部,至少有一个调用方没有配置远程处理类型和通道的权限。

示例

下面的代码示例演示了在客户端上将对象类型注册为已知类型。 有关与呈现的客户端代码对应的服务器代码,请参阅 方法的示例 RegisterWellKnownServiceType

#using <system.dll>
#using <system.runtime.remoting.dll>
#using "service.dll"

using namespace System;
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Channels::Tcp;
using namespace System::Runtime::Remoting::Channels;
int main()
{
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels;

public class ClientClass {

    public static void Main() {
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels.Tcp
Imports System.Runtime.Remoting.Channels


Public Class ClientClass
   
   
   Public Shared Sub Main()
ChannelServices::RegisterChannel( gcnew TcpChannel );
RemotingConfiguration::RegisterWellKnownClientType( HelloService::typeid,
                                                    "tcp://localhost:8082/HelloServiceApplication/MyUri" );
HelloService ^ service = gcnew HelloService;
ChannelServices.RegisterChannel(new TcpChannel());

RemotingConfiguration.RegisterWellKnownClientType(
                                                   typeof(HelloService),
                                                   "tcp://localhost:8082/HelloServiceApplication/MyUri"
                                                 );

HelloService service = new HelloService();
ChannelServices.RegisterChannel(New TcpChannel())

RemotingConfiguration.RegisterWellKnownClientType(GetType(HelloService), "tcp://localhost:8082/HelloServiceApplication/MyUri")

Dim service As New HelloService()
   if ( service == nullptr )
   {
      Console::WriteLine( "Could not locate server." );
      return  -1;
   }

   // Calls the remote method.
   Console::WriteLine();
   Console::WriteLine( "Calling remote Object*" );
   Console::WriteLine( service->HelloMethod( "Caveman" ) );
   Console::WriteLine( service->HelloMethod( "Spaceman" ) );
   Console::WriteLine( service->HelloMethod( "Client Man" ) );
   Console::WriteLine( "Finished remote Object* call" );
   Console::WriteLine();
   return 0;
}

        if(service == null) {
            Console.WriteLine("Could not locate server.");
            return;
        }

        // Calls the remote method.
        Console.WriteLine();
        Console.WriteLine("Calling remote object");
        Console.WriteLine(service.HelloMethod("Caveman"));
        Console.WriteLine(service.HelloMethod("Spaceman"));
        Console.WriteLine(service.HelloMethod("Client Man"));
        Console.WriteLine("Finished remote object call");
        Console.WriteLine();
    }
}

      If service Is Nothing Then
         Console.WriteLine("Could not locate server.")
         Return
      End If
            
      ' Calls the remote method.
      Console.WriteLine()
      Console.WriteLine("Calling remote object")
      Console.WriteLine(service.HelloMethod("Caveman"))
      Console.WriteLine(service.HelloMethod("Spaceman"))
      Console.WriteLine(service.HelloMethod("Client Man"))
      Console.WriteLine("Finished remote object call")
      Console.WriteLine()

   End Sub

End Class

注解

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

有关已知对象的详细说明,请参阅 服务器激活

另请参阅

适用于