RemotingConfiguration.RegisterWellKnownClientType 方法

定义

Type将客户端端的对象注册为已知类型(单个调用或单一实例)。

重载

名称 说明
RegisterWellKnownClientType(WellKnownClientTypeEntry)

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

RegisterWellKnownClientType(Type, String)

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

RegisterWellKnownClientType(WellKnownClientTypeEntry)

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

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关键字创建远程对象。 另一方面, 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关键字创建远程对象。 另一方面, Activator.GetObject 如果使用该方法激活已知对象,则必须使用对象的 URL 作为参数提供该对象,因此不需要在客户端端进行事先注册。

另请参阅

适用于