Share via


RemotingConfiguration.RegisterActivatedClientType 方法

定義

在用戶端上登錄物件 Type 為可在伺服器上啟動的型別。

多載

RegisterActivatedClientType(ActivatedClientTypeEntry)

登錄記錄在用戶端上所提供 Type 中的物件 ActivatedClientTypeEntry 為可在伺服器上啟動的型別。

RegisterActivatedClientType(Type, String)

在用戶端上登錄物件 Type 為可在伺服器上啟動的型別,藉由使用指定的參數初始化 ActivatedClientTypeEntry 類別的新執行個體。

RegisterActivatedClientType(ActivatedClientTypeEntry)

登錄記錄在用戶端上所提供 Type 中的物件 ActivatedClientTypeEntry 為可在伺服器上啟動的型別。

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

參數

entry
ActivatedClientTypeEntry

用戶端啟動型別的組態設定。

例外狀況

至少有一個呼叫堆疊中較高的呼叫端,不具有設定遠端類型和通道的使用權限。

備註

若要在伺服器上建立客戶端啟動物件的實例,您必須知道它, Type 而且必須使用 方法在伺服器端 RegisterActivatedServiceType 註冊它。 若要取得客戶端啟動物件之新實例的 Proxy,客戶端必須先向 ChannelServices 註冊通道,然後呼叫 new來啟用 物件。

若要使用 new 關鍵字啟用用戶端啟動的物件類型,您必須先使用 RegisterActivatedClientType 方法在用戶端端註冊物件類型。 RegisterActivatedClientType呼叫 方法會提供遠端基礎結構嘗試建立遠端應用程式new的位置。 另一方面, Activator.CreateInstance 如果您使用 方法來建立用戶端啟動物件的新實例,則必須提供遠端應用程式的 URL 做為參數,因此不需要在用戶端端進行先前的註冊。 若要提供 Activator.CreateInstance 方法,並提供您想要建立對象的伺服器URL,您必須將URL封裝在類別的 UrlAttribute 實例中。

如需客戶端啟動物件的詳細說明,請參閱 客戶端啟用

另請參閱

適用於

RegisterActivatedClientType(Type, String)

在用戶端上登錄物件 Type 為可在伺服器上啟動的型別,藉由使用指定的參數初始化 ActivatedClientTypeEntry 類別的新執行個體。

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

參數

type
Type

物件 Type

appUrl
String

啟動這個型別的應用程式的 URL。

例外狀況

typeNameURI 參數為 null

至少有一個呼叫堆疊中較高的呼叫端,不具有設定遠端類型和通道的使用權限。

範例

下列程式代碼範例示範在用戶端上將物件類型註冊為可在伺服器上啟用的類型。 如需對應至所呈現用戶端程式代碼的伺服器程式代碼,請參閱 方法的 RegisterActivatedServiceType 範例。

#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;
using namespace System::Runtime::Remoting::Channels::Tcp;

int main()
{
   ChannelServices::RegisterChannel( gcnew TcpChannel );
   RemotingConfiguration::RegisterActivatedClientType( HelloServiceClass::typeid, "tcp://localhost:8082" );
   try
   {
      HelloServiceClass ^ service = gcnew HelloServiceClass;

      // 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" );
    }
    catch (Exception ex)
    {
        Console::WriteLine("An exception occurred: " + ex.Message);
    }
   Console::WriteLine();
   return 0;
}
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

public class ClientClass {

    public static void Main() {

        ChannelServices.RegisterChannel(new TcpChannel());

        RemotingConfiguration.RegisterActivatedClientType(typeof(HelloServiceClass),
                                                   "tcp://localhost:8082");

        try
        {
            HelloServiceClass service = new HelloServiceClass();

           // 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();
        }
    catch (Exception ex)
    {
       Console.WriteLine("An exception occurred: " + ex.Message);
        }
    }
}
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Tcp


Public Class ClientClass
   
   Public Shared Sub Main()
      
      ChannelServices.RegisterChannel(New TcpChannel())
      
      RemotingConfiguration.RegisterActivatedClientType(GetType(HelloServiceClass), "tcp://localhost:8082")
      
      Try
          Dim service As New HelloServiceClass()
      
       
          ' 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")
      Catch ex as Exception
          Console.WriteLine("An exception occurred: " + ex.Message)
      End Try

      Console.WriteLine()

   End Sub

End Class

備註

若要在伺服器上建立客戶端啟動物件的實例,您必須知道它, Type 而且必須使用 方法在伺服器端 RegisterActivatedServiceType 註冊它。 若要取得客戶端啟動物件之新實例的 Proxy,客戶端必須先向 ChannelServices 註冊通道,然後呼叫 new來啟用 物件。

若要使用 new 關鍵字啟用用戶端啟動的物件類型,您必須先使用 RegisterActivatedClientType 方法在用戶端端註冊物件類型。 RegisterActivatedClientType呼叫 方法會提供遠端基礎結構嘗試建立遠端應用程式new的位置。 另一方面, Activator.CreateInstance 如果您使用 方法來建立用戶端啟動物件的新實例,則必須提供遠端應用程式的 URL 做為參數,因此不需要在用戶端端進行先前的註冊。 若要提供 Activator.CreateInstance 方法,並提供您想要建立對象的伺服器URL,您必須將URL封裝在類別的 UrlAttribute 實例中。

如需客戶端啟動物件的詳細說明,請參閱 客戶端啟用

另請參閱

適用於