Share via


RemotingConfiguration.RegisterActivatedServiceType 方法

定義

在服務端上登錄物件 Type 為可從用戶端要求啟動的型別。

多載

RegisterActivatedServiceType(ActivatedServiceTypeEntry)

登錄記錄在服務端上所提供 ActivatedServiceTypeEntry 中的物件型別為可從用戶端要求啟動的型別。

RegisterActivatedServiceType(Type)

在服務端登錄指定的物件型別為可從用戶端要求啟動的型別。

RegisterActivatedServiceType(ActivatedServiceTypeEntry)

登錄記錄在服務端上所提供 ActivatedServiceTypeEntry 中的物件型別為可從用戶端要求啟動的型別。

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

參數

entry
ActivatedServiceTypeEntry

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

例外狀況

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

備註

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

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

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

另請參閱

適用於

RegisterActivatedServiceType(Type)

在服務端登錄指定的物件型別為可從用戶端要求啟動的型別。

public:
 static void RegisterActivatedServiceType(Type ^ type);
public static void RegisterActivatedServiceType (Type type);
static member RegisterActivatedServiceType : Type -> unit
Public Shared Sub RegisterActivatedServiceType (type As Type)

參數

type
Type

要登錄的物件 Type

例外狀況

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

範例

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

#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( 8082 ) );
   RemotingConfiguration::RegisterActivatedServiceType( HelloServiceClass::typeid );
   Console::WriteLine( "Press enter to stop this process." );
   Console::ReadLine();
   return 0;
}
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

public class ServerClass {

    public static void Main()  {

        ChannelServices.RegisterChannel(new TcpChannel(8082));

        RemotingConfiguration.RegisterActivatedServiceType(typeof(HelloServiceClass));

        Console.WriteLine("Press enter to stop this process.");
        Console.ReadLine();
    }
}
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Tcp


Public Class ServerClass
      
   Public Shared Sub Main()
      
      ChannelServices.RegisterChannel(New TcpChannel(8082))     
      RemotingConfiguration.RegisterActivatedServiceType(GetType(HelloServiceClass))
      
      Console.WriteLine("Press enter to stop this process.")
      Console.ReadLine()

   End Sub

End Class

下列程式代碼範例顯示上述範例程式代碼中註冊的服務物件。

#using <system.dll>

using namespace System;

public ref class HelloServiceClass: public MarshalByRefObject
{
private:
   static int n_instance;

public:
   HelloServiceClass()
   {
      n_instance++;
      Console::WriteLine(  "{0} has been created.  Instance # = {1}", this->GetType()->Name, n_instance );
   }

   ~HelloServiceClass()
   {
      Console::WriteLine( "Destroyed instance {0} of HelloServiceClass.", n_instance );
      n_instance--;
   }

   String^ HelloMethod( String^ name )
   {
      // Reports that the method was called.
      Console::WriteLine();
      Console::WriteLine( "Called HelloMethod on instance {0} with the '{1}' parameter.", n_instance, name );

      // Calculates and returns the result to the client.
      return String::Format( "Hi there {0}", name );
   }
};
using System;

public class HelloServiceClass : MarshalByRefObject {

    static int n_instance;

    public HelloServiceClass() {
        n_instance++;
        Console.WriteLine(this.GetType().Name + " has been created.  Instance # = {0}", n_instance);
    }

    ~HelloServiceClass() {
        Console.WriteLine("Destroyed instance {0} of HelloServiceClass.", n_instance);
        n_instance --;
    }

    public String HelloMethod(String name) {

        // Reports that the method was called.
        Console.WriteLine();
        Console.WriteLine("Called HelloMethod on instance {0} with the '{1}' parameter.",
                             n_instance, name);

        // Calculates and returns the result to the client.
        return "Hi there " + name + ".";
    }
}
Public Class HelloServiceClass
   Inherits MarshalByRefObject
   
   Private Shared n_instance As Integer

      
   Public Sub New()
      n_instance += 1
      Console.WriteLine(Me.GetType().Name + " has been created.  Instance # = {0}", n_instance)
   End Sub
      
   
   Protected Overrides Sub Finalize()
      Console.WriteLine("Destroyed instance {0} of HelloServiceClass.", n_instance)
      n_instance -= 1
      MyBase.Finalize()
   End Sub
   
   
   
   Public Function HelloMethod(name As [String]) As [String]
      
      ' Reports that the method was called.
      Console.WriteLine()
      Console.WriteLine("Called HelloMethod on instance {0} with the '{1}' parameter.", n_instance, name)
      
      ' Calculates and returns the result to the client.
      Return "Hi there " + name + "."

   End Function 'HelloMethod

End Class

備註

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

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

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

另請參閱

適用於