RemotingConfiguration.RegisterWellKnownServiceType メソッド

定義

既知の型 (単一の呼び出しまたはシングルトン) として、サービス エンドでオブジェクト Type を登録します。

オーバーロード

RegisterWellKnownServiceType(WellKnownServiceTypeEntry)

既知の型として、サービス エンドで提供される Type に記録されているオブジェクト WellKnownServiceTypeEntry を登録します。

RegisterWellKnownServiceType(Type, String, WellKnownObjectMode)

既知の型として、サービス エンドでオブジェクト Type を登録し、特定のパラメーターを使用して WellKnownServiceTypeEntry の新しいインスタンスを初期化します。

RegisterWellKnownServiceType(WellKnownServiceTypeEntry)

既知の型として、サービス エンドで提供される Type に記録されているオブジェクト WellKnownServiceTypeEntry を登録します。

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

パラメーター

entry
WellKnownServiceTypeEntry

既知の型の構成設定。

例外

コールスタックの上位にある 1 つ以上の呼び出し元に、リモート処理の型とチャネルを構成するためのアクセス許可がありません。

#using <system.dll>
#using <system.runtime.remoting.dll>

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

public ref class RemoteObject: public MarshalByRefObject
{
public:
   void Method1( LocalObject^ param )
   {
      Console::WriteLine( "Invoked: Method1( {0})", param );
   }
};

int main()
{
   ChannelServices::RegisterChannel( gcnew HttpChannel( 8090 ) );
   WellKnownServiceTypeEntry^ wkste = gcnew WellKnownServiceTypeEntry( RemoteObject::typeid,"RemoteObject",WellKnownObjectMode::Singleton );
   RemotingConfiguration::RegisterWellKnownServiceType( wkste );
   RemoteObject^ RObj = dynamic_cast<RemoteObject^>(Activator::GetObject( RemoteObject::typeid, "http://localhost:8090/RemoteObject" ));
   LocalObject^ LObj = gcnew LocalObject;
   RObj->Method1( LObj );
   Console::WriteLine( "Press Return to exit..." );
   Console::ReadLine();
}
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Serialization;
using System.Security.Permissions;

public class ObjRefExample {

   public static void Main() {

      ChannelServices.RegisterChannel(new HttpChannel(8090));

      WellKnownServiceTypeEntry wkste =
         new WellKnownServiceTypeEntry(typeof(RemoteObject),
                                       "RemoteObject",
                                       WellKnownObjectMode.Singleton);

      RemotingConfiguration.RegisterWellKnownServiceType( wkste );

      RemoteObject RObj =
         (RemoteObject)Activator.GetObject(typeof(RemoteObject),
                                           "http://localhost:8090/RemoteObject");

      LocalObject LObj = new LocalObject();

      RObj.Method1( LObj );

      Console.WriteLine("Press Return to exit...");
      Console.ReadLine();
   }
}

public class RemoteObject : MarshalByRefObject {

   public void Method1(LocalObject param) {
      Console.WriteLine("Invoked: Method1({0})", param);
   }
}
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Http
Imports System.Runtime.Remoting.Messaging
Imports System.Runtime.Serialization
Imports System.Security.Permissions

' code that drives the example
Public Class ObjRefExample

   <PermissionSet(SecurityAction.LinkDemand)> _
   Public Overloads Shared Sub Main()
      ChannelServices.RegisterChannel(New HttpChannel(8090))

      RemotingConfiguration.RegisterWellKnownServiceType(New WellKnownServiceTypeEntry(GetType(RemoteObject), "RemoteObject", WellKnownObjectMode.Singleton))

      Dim RObj As RemoteObject = CType(Activator.GetObject(GetType(RemoteObject), "http://localhost:8090/RemoteObject"), RemoteObject)
      Dim LObj As New LocalObject()

      RObj.Method1(LObj)

      Console.WriteLine("Press Return to exit...")

      Console.ReadLine()
   End Sub

End Class


' a simple remote object
<PermissionSet(SecurityAction.Demand, Name:="FullTrust")> _
Public Class RemoteObject
   Inherits MarshalByRefObject

   Public Sub Method1(ByVal param As LocalObject)
       Console.WriteLine("Invoked: Method1({0})", param)
   End Sub

End Class

注釈

登録済みの既知のオブジェクトの URI を認識するすべてのクライアントは、 に希望 ChannelServicesするチャネルを登録し、 または メソッドを呼び出 new してオブジェクトをアクティブ化することで、オブジェクトのプロキシを Activator.GetObject 取得できます。 で既知のオブジェクト newをアクティブ化するには、 メソッドを使用して、まず既知のオブジェクト型をクライアントに登録する RegisterWellKnownClientType 必要があります。 メソッドを RegisterWellKnownClientType 呼び出すと、リモート処理インフラストラクチャにリモート オブジェクトの場所が与え、 キーワードで new 作成できるようになります。 一方、 メソッドを使用 Activator.GetObject して既知のオブジェクトをアクティブ化する場合は、オブジェクトの URL を引数として指定する必要があるため、クライアント側での事前登録は必要ありません。

呼び出しがサーバーに到着すると、.NET Frameworkはメッセージから URI を抽出し、リモート処理テーブルを調べて URI に一致するオブジェクトの参照を見つけ、必要に応じてオブジェクトをインスタンス化し、メソッド呼び出しをオブジェクトに転送します。 オブジェクトが として SingleCall登録されている場合、メソッド呼び出しの完了後に破棄されます。 呼び出されるメソッドごとに、 オブジェクトの新しいインスタンスが作成されます。 と new の唯一の違いActivator.GetObjectは、前者では URL をパラメーターとして指定でき、後者は構成から URL を取得することです。

リモート オブジェクト自体は、登録プロセスによってインスタンス化されません。 これは、クライアントが オブジェクトのメソッドを呼び出そうとするか、クライアント側からオブジェクトをアクティブ化する場合にのみ発生します。

既知のオブジェクトの詳細については、「 サーバーのアクティブ化」を参照してください。

こちらもご覧ください

適用対象

RegisterWellKnownServiceType(Type, String, WellKnownObjectMode)

既知の型として、サービス エンドでオブジェクト Type を登録し、特定のパラメーターを使用して WellKnownServiceTypeEntry の新しいインスタンスを初期化します。

public:
 static void RegisterWellKnownServiceType(Type ^ type, System::String ^ objectUri, System::Runtime::Remoting::WellKnownObjectMode mode);
public static void RegisterWellKnownServiceType (Type type, string objectUri, System.Runtime.Remoting.WellKnownObjectMode mode);
static member RegisterWellKnownServiceType : Type * string * System.Runtime.Remoting.WellKnownObjectMode -> unit
Public Shared Sub RegisterWellKnownServiceType (type As Type, objectUri As String, mode As WellKnownObjectMode)

パラメーター

type
Type

オブジェクト Type

objectUri
String

オブジェクトの URI。

mode
WellKnownObjectMode

登録されている既知のオブジェクト型のアクティベーション モード。 (「WellKnownObjectMode」を参照)。

例外

コールスタックの上位にある 1 つ以上の呼び出し元に、リモート処理の型とチャネルを構成するためのアクセス許可がありません。

次のコード例は、サーバー上のオブジェクト型を既知のオブジェクト型として登録する方法を示しています。 提示されたサーバー コードに対応するクライアント コードについては、 メソッドの例を RegisterWellKnownClientType 参照してください。

#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()
{
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

public class ServerClass {

    public static void Main()  {
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Tcp


Public Class ServerClass
   
   Public Shared Sub Main()
ChannelServices::RegisterChannel( gcnew TcpChannel( 8082 ) );
RemotingConfiguration::ApplicationName = "HelloServiceApplication";
RemotingConfiguration::RegisterWellKnownServiceType( HelloService::typeid,
                                                     "MyUri",
                                                     WellKnownObjectMode::SingleCall );
ChannelServices.RegisterChannel(new TcpChannel(8082));

RemotingConfiguration.ApplicationName = "HelloServiceApplication";

RemotingConfiguration.RegisterWellKnownServiceType( typeof(HelloService),
                                                    "MyUri",
                                                    WellKnownObjectMode.SingleCall
                                                  );
ChannelServices.RegisterChannel(New TcpChannel(8082))

RemotingConfiguration.ApplicationName = "HelloServiceApplication"

RemotingConfiguration.RegisterWellKnownServiceType(GetType(HelloService), "MyUri", WellKnownObjectMode.SingleCall)
   Console::WriteLine( "Press enter to stop this process." );
   Console::ReadLine();
   return 0;
}

        Console.WriteLine("Press enter to stop this process.");
        Console.ReadLine();
    }
}

      Console.WriteLine("Press enter to stop this process.")
      Console.ReadLine()

   End Sub

End Class

次のコード例は、上記のサンプル コードに登録されているサービス オブジェクトを示しています。

#using <system.dll>

using namespace System;
public ref class HelloService: public MarshalByRefObject
{
private:
   static int n_instances;

public:
   HelloService()
   {
      n_instances++;
      Console::WriteLine( "" );
      Console::WriteLine( "HelloService activated - instance # {0}.", n_instances );
   }

   ~HelloService()
   {
      Console::WriteLine( "HelloService instance {0} destroyed.", n_instances );
      n_instances--;
   }

   String^ HelloMethod( String^ name )
   {
      Console::WriteLine( "HelloMethod called on HelloService instance {0}.", n_instances );
      return String::Format( "Hi there {0}.", name );
   }

};
using System;

public class HelloService : MarshalByRefObject {

    static int n_instances;

    public HelloService() {
        n_instances++;
        Console.WriteLine("");
        Console.WriteLine("HelloService activated - instance # {0}.", n_instances);
    }

    ~HelloService()  {
        Console.WriteLine("HelloService instance {0} destroyed.", n_instances);
        n_instances--;
    }

    public String HelloMethod(String name)  {

        Console.WriteLine("HelloMethod called on HelloService instance {0}.", n_instances);
        return "Hi there " + name + ".";
    }
}
Public Class HelloService
   Inherits MarshalByRefObject
   
   Private Shared n_instances As Integer
     
   Public Sub New()
      n_instances += 1
      Console.WriteLine("")
      Console.WriteLine("HelloService activated - instance # {0}.", n_instances)
   End Sub
   
   
   Protected Overrides Sub Finalize()
      Console.WriteLine("HelloService instance {0} destroyed.", n_instances)
      n_instances -= 1
      MyBase.Finalize()
   End Sub
   
   
   Public Function HelloMethod(name As [String]) As [String]
      Console.WriteLine("HelloMethod called on HelloService instance {0}.", n_instances)
      Return "Hi there " + name + "."
   End Function 'HelloMethod

End Class

注釈

登録済みの既知のオブジェクトの URI を認識するすべてのクライアントは、 に希望 ChannelServicesするチャネルを登録し、 または メソッドを呼び出 new してオブジェクトをアクティブ化することで、オブジェクトのプロキシを Activator.GetObject 取得できます。 で既知のオブジェクト newをアクティブ化するには、 メソッドを使用して、まず既知のオブジェクト型をクライアントに登録する RegisterWellKnownClientType 必要があります。 メソッドを RegisterWellKnownClientType 呼び出すと、リモート処理インフラストラクチャにリモート オブジェクトの場所が与え、 キーワードで new 作成できるようになります。 一方、 メソッドを使用 Activator.GetObject して既知のオブジェクトをアクティブ化する場合は、オブジェクトの URL を引数として指定する必要があるため、クライアント側での事前登録は必要ありません。

呼び出しがサーバーに到着すると、.NET Frameworkはメッセージから URI を抽出し、リモート処理テーブルを調べて URI に一致するオブジェクトの参照を見つけ、必要に応じてオブジェクトをインスタンス化し、メソッド呼び出しをオブジェクトに転送します。 オブジェクトが として SingleCall登録されている場合、メソッド呼び出しの完了後に破棄されます。 呼び出されるメソッドごとに、 オブジェクトの新しいインスタンスが作成されます。 と new の唯一の違いActivator.GetObjectは、前者では URL をパラメーターとして指定でき、後者は構成から URL を取得することです。

リモート オブジェクト自体は、登録プロセスによってインスタンス化されません。 これは、クライアントが オブジェクトのメソッドを呼び出そうとするか、クライアント側からオブジェクトをアクティブ化する場合にのみ発生します。

既知のオブジェクトの詳細については、「 サーバーのアクティブ化」を参照してください。

こちらもご覧ください

適用対象