语言

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 注册它。 若要获取客户端激活对象的新实例的代理,客户端必须先向 ChannelServices 该通道注册通道,然后通过调用 new 或 Activator.CreateInstance激活该对象。

若要使用 new 关键字激活客户端激活的对象类型,必须先使用 RegisterActivatedClientType 该方法在客户端端注册对象类型。 调用该方法 RegisterActivatedClientType 可让远程处理基础结构位于远程应用程序的位置,尝试 new 在其中创建远程应用程序。 另一方面, CreateInstance 如果使用该方法创建新的客户端激活对象的实例,则必须提供远程应用程序的 URL 作为参数,因此不需要在客户端端进行以前的注册。 若要向方法提供 CreateInstance 要在其中创建对象的服务器的 URL,必须在类的 UrlAttribute 实例中封装该 URL。

有关客户端激活对象的详细说明,请参阅 客户端激活。

另请参阅

适用于

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 注册它。 若要获取客户端激活对象的新实例的代理,客户端必须先向 ChannelServices 该通道注册通道,然后通过调用 new 或 Activator.CreateInstance激活该对象。

若要使用 new 关键字激活客户端激活的对象类型,必须先使用 RegisterActivatedClientType 该方法在客户端端注册对象类型。 调用该方法 RegisterActivatedClientType 可让远程处理基础结构位于远程应用程序的位置,尝试 new 在其中创建远程应用程序。 另一方面, CreateInstance 如果使用该方法创建新的客户端激活对象的实例,则必须提供远程应用程序的 URL 作为参数,因此不需要在客户端端进行以前的注册。 若要向方法提供 CreateInstance 要在其中创建对象的服务器的 URL,必须在类的 UrlAttribute 实例中封装该 URL。

有关客户端激活对象的详细说明,请参阅 客户端激活。

另请参阅

适用于