RemotingConfiguration.RegisterWellKnownServiceType メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
サービス エンドで Type オブジェクトを既知の型 (単一呼び出しまたはシングルトン) として登録します。
オーバーロード
| 名前 | 説明 |
|---|---|
| RegisterWellKnownServiceType(WellKnownServiceTypeEntry) |
サービス エンドで指定されたWellKnownServiceTypeEntryに記録Typeオブジェクトを既知の型として登録します。 |
| RegisterWellKnownServiceType(Type, String, WellKnownObjectMode) |
指定されたパラメーターを使用して、サービス エンドで Type オブジェクトを既知の型として登録 WellKnownServiceTypeEntryの新しいインスタンスを初期化します。 |
RegisterWellKnownServiceType(WellKnownServiceTypeEntry)
サービス エンドで指定されたWellKnownServiceTypeEntryに記録Typeオブジェクトを既知の型として登録します。
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)
パラメーター
既知の種類の構成設定。
例外
呼び出し履歴の上位の呼び出し元の少なくとも 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として登録されている場合は、メソッド呼び出しが完了した後に破棄されます。 呼び出されたメソッドごとに、オブジェクトの新しいインスタンスが作成されます。
Activator.GetObjectとnewの唯一の違いは、前者ではパラメーターとして 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)
パラメーター
- 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として登録されている場合は、メソッド呼び出しが完了した後に破棄されます。 呼び出されたメソッドごとに、オブジェクトの新しいインスタンスが作成されます。
Activator.GetObjectとnewの唯一の違いは、前者ではパラメーターとして URL を指定でき、後者は構成から URL を取得することです。
リモート オブジェクト自体は、登録プロセスによってインスタンス化されません。 これは、クライアントがオブジェクトのメソッドを呼び出そうとしたとき、またはクライアント側からオブジェクトをアクティブ化しようとした場合にのみ発生します。