WellKnownServiceTypeEntry 类

将在服务端注册的对象类型的值保存为服务器激活类型对象(单个调用或 singleton)。

**命名空间:**System.Runtime.Remoting
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
<ComVisibleAttribute(True)> _
Public Class WellKnownServiceTypeEntry
    Inherits TypeEntry
用法
Dim instance As WellKnownServiceTypeEntry
[ComVisibleAttribute(true)] 
public class WellKnownServiceTypeEntry : TypeEntry
[ComVisibleAttribute(true)] 
public ref class WellKnownServiceTypeEntry : public TypeEntry
/** @attribute ComVisibleAttribute(true) */ 
public class WellKnownServiceTypeEntry extends TypeEntry
ComVisibleAttribute(true) 
public class WellKnownServiceTypeEntry extends TypeEntry

备注

服务器激活对象类型或者为单个调用,或者为 singleton。如果对象类型是单个调用,则每次来自客户端的调用到来时都创建该对象的新实例。对 singleton 对象的所有调用都由该对象的一个实例来处理。

任何客户端只要知道该对象的 URI,就可以通过向 ChannelServices 注册它首选的信道,并调用 newActivator.GetObject 激活该对象来获取该对象的代理。

值得注意的是,远程对象本身不由注册过程创建。仅当客户端试图对该对象调用方法或从客户端激活该对象时,才会发生这种情况。

有关服务器激活对象和远程对象激活的更多详细说明,请参见 远程对象的激活

示例

Imports System
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Http

Public Class MyServer
   
   Public Shared Sub Main()
      ' Create a 'HttpChannel' object and register it with the 
      ' channel services.
      ChannelServices.RegisterChannel(New HttpChannel(8086))
      ' Record the 'HelloServer' type as 'Singleton' well-known type.
      Dim myWellKnownServiceTypeEntry As New WellKnownServiceTypeEntry(GetType(HelloServer), _ 
                                                 "SayHello", WellKnownObjectMode.Singleton)
      ' Register the remote object as well-known type.
      RemotingConfiguration.RegisterWellKnownServiceType(myWellKnownServiceTypeEntry)
      ' Retrieve object types registered on the service end 
      ' as well-known types.
      Dim myWellKnownServiceTypeEntryCollection As WellKnownServiceTypeEntry() = _ 
                                      RemotingConfiguration.GetRegisteredWellKnownServiceTypes()
      Console.WriteLine("The 'WellKnownObjectMode' of the remote object : " + _
                                        myWellKnownServiceTypeEntryCollection(0).Mode.ToString())
      Console.WriteLine("The 'WellKnownServiceTypeEntry' object: " + _ 
                                             myWellKnownServiceTypeEntryCollection(0).ToString())
      Console.WriteLine("Started the Server, Hit <enter> to exit...")
      Console.ReadLine()
   End Sub 'Main
End Class 'MyServer
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;

public class MyServer 
{
   public static void Main() 
   {
      // Create a 'HttpChannel' object and register it with the 
      // channel services.
      ChannelServices.RegisterChannel(new HttpChannel(8086));
      // Record the 'HelloServer' type as 'Singleton' well-known type.
      WellKnownServiceTypeEntry myWellKnownServiceTypeEntry= 
          new WellKnownServiceTypeEntry(typeof(HelloServer),
                                        "SayHello",
                                        WellKnownObjectMode.Singleton);
      // Register the remote object as well-known type.
      RemotingConfiguration.RegisterWellKnownServiceType(
                                          myWellKnownServiceTypeEntry);
      // Retrieve object types registered on the service end 
      // as well-known types.
      WellKnownServiceTypeEntry [] myWellKnownServiceTypeEntryCollection = 
            RemotingConfiguration.GetRegisteredWellKnownServiceTypes();
      Console.WriteLine("The 'WellKnownObjectMode' of the remote object : "
                       +myWellKnownServiceTypeEntryCollection[0].Mode);
      Console.WriteLine("The 'WellKnownServiceTypeEntry' object: "+
                  myWellKnownServiceTypeEntryCollection[0].ToString());
      Console.WriteLine("Started the Server, Hit <enter> to exit...");
      Console.ReadLine();
   }
}
#using <System.Runtime.Remoting.dll>
#using <System.dll>
#using <WellKnownServiceTypeEntry_Share.dll>

using namespace System;
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Channels;
using namespace System::Runtime::Remoting::Channels::Http;

int main()
{
   // Create a 'HttpChannel' object and register it with the 
   // channel services.
   ChannelServices::RegisterChannel( gcnew HttpChannel( 8086 ) );

   // Record the 'HelloServer' type as 'Singleton' well-known type.
   WellKnownServiceTypeEntry^ myWellKnownServiceTypeEntry = gcnew WellKnownServiceTypeEntry( HelloServer::typeid,"SayHello",WellKnownObjectMode::Singleton );

   // Register the remote object as well-known type.
   RemotingConfiguration::RegisterWellKnownServiceType( myWellKnownServiceTypeEntry );

   // Retrieve object types registered on the service end 
   // as well-known types.
   array<WellKnownServiceTypeEntry^>^myWellKnownServiceTypeEntryCollection = RemotingConfiguration::GetRegisteredWellKnownServiceTypes();
   Console::WriteLine( "The 'WellKnownObjectMode' of the remote object : {0}", myWellKnownServiceTypeEntryCollection[ 0 ]->Mode );
   Console::WriteLine( "The 'WellKnownServiceTypeEntry' object: {0}", myWellKnownServiceTypeEntryCollection[ 0 ] );
   Console::WriteLine( "Started the Server, Hit <enter> to exit..." );
   Console::ReadLine();
}
import System.*;
import System.Runtime.Remoting.*;
import System.Runtime.Remoting.Channels.*;
import System.Runtime.Remoting.Channels.Http.*;

public class MyServer
{
    public static void main(String[] args)
    {
        // Create a 'HttpChannel' object and register it with the 
        // channel services.
        ChannelServices.RegisterChannel(new HttpChannel(8086));
        // Record the 'HelloServer' type as 'Singleton' well-known type.
        WellKnownServiceTypeEntry myWellKnownServiceTypeEntry = 
            new WellKnownServiceTypeEntry(HelloServer.class.ToType(),
            "SayHello", WellKnownObjectMode.Singleton);
        // Register the remote object as well-known type.
        RemotingConfiguration.RegisterWellKnownServiceType(
            myWellKnownServiceTypeEntry);
        // Retrieve object types registered on the service end 
        // as well-known types.
        WellKnownServiceTypeEntry myWellKnownServiceTypeEntryCollection[] =
            RemotingConfiguration.GetRegisteredWellKnownServiceTypes();
        Console.WriteLine("The 'WellKnownObjectMode' of the remote object : " 
            + myWellKnownServiceTypeEntryCollection[0].get_Mode());
        Console.WriteLine("The 'WellKnownServiceTypeEntry' object: " 
            + myWellKnownServiceTypeEntryCollection.get_Item(0).ToString());
        Console.WriteLine("Started the Server, Hit <enter> to exit...");
        Console.ReadLine();
    } //main
} //MyServer

继承层次结构

System.Object
   System.Runtime.Remoting.TypeEntry
    System.Runtime.Remoting.WellKnownServiceTypeEntry

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

WellKnownServiceTypeEntry 成员
System.Runtime.Remoting 命名空间
RegisterWellKnownServiceType

其他资源

服务器激活