RemotingConfiguration.RegisterActivatedServiceType 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将服务端上的对象 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)
参数
客户端激活类型的配置设置。
例外
在调用堆栈上部,至少有一个调用方没有配置远程处理类型和通道的权限。
注解
若要在服务器上创建客户端激活对象的实例,必须知道它 Type ,并且必须使用 方法在服务器端 RegisterActivatedServiceType 注册它。 若要获取客户端激活对象的新实例的代理,客户端必须先向 ChannelServices 注册通道,然后通过调用 new 或 Activator.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)
参数
例外
在调用堆栈上部,至少有一个调用方没有配置远程处理类型和通道的权限。
示例
下面的代码示例演示将服务器上的对象类型注册为可由客户端激活的类型。 有关与呈现的服务器代码对应的客户端代码,请参阅 方法的示例 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,必须将 URL 封装在 类的 UrlAttribute 实例中。
有关客户端激活对象的详细说明,请参阅 客户端激活。