クライアントからの要求に基づいてアクティブにできる型として、サービス エンドでオブジェクト Type を登録します。
オーバーロードの一覧
クライアントからの要求に基づいてアクティブにできる型として、サービス エンドで提供される ActivatedServiceTypeEntry に記録されているオブジェクト型を登録します。
[Visual Basic] Overloads Public Shared Sub RegisterActivatedServiceType(ActivatedServiceTypeEntry)
[C#] public static void RegisterActivatedServiceType(ActivatedServiceTypeEntry);
[C++] public: static void RegisterActivatedServiceType(ActivatedServiceTypeEntry*);
[JScript] public static function RegisterActivatedServiceType(ActivatedServiceTypeEntry);
クライアントからの要求に基づいてアクティブにできる型として、サービス エンドで指定したオブジェクト型を登録します。
[Visual Basic] Overloads Public Shared Sub RegisterActivatedServiceType(Type)
[C++] public: static void RegisterActivatedServiceType(Type*);
[JScript] public static function RegisterActivatedServiceType(Type);
使用例
[Visual Basic, C#, C++] クライアントでアクティブにできる型としてサーバーでオブジェクト型を登録する例を次に示します。ここで示すサーバー コードに対応するクライアント コードについては、 RegisterActivatedClientType メソッドのトピックの例を参照してください。
[Visual Basic, C#, C++] メモ ここでは、RegisterActivatedServiceType のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。
Imports System
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 'Main
End Class 'ServerClass
[C#]
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();
}
}
[C++]
#using <mscorlib.dll>
#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::Tcp;
int main()
{
ChannelServices::RegisterChannel(new TcpChannel(8082));
RemotingConfiguration::RegisterActivatedServiceType(__typeof(HelloServiceClass));
Console::WriteLine(S"Press enter to stop this process.");
Console::ReadLine();
return 0;
}
[Visual Basic, C#, C++] 上のサンプル コードで登録したサービス オブジェクトを次の例に示します。
Imports System
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 'New
Protected Overrides Sub Finalize()
Console.WriteLine("Destroyed instance {0} of HelloServiceClass.", n_instance)
n_instance -= 1
MyBase.Finalize()
End Sub 'Finalize
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 'HelloServiceClass
[C#]
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 + ".";
}
}
[C++]
#using <mscorlib.dll>
#using <system.dll>
using namespace System;
public __gc class HelloServiceClass : public MarshalByRefObject
{
static int n_instance;
public:
HelloServiceClass()
{
n_instance++;
Console::WriteLine("{0} has been created. Instance # = {1}", this->GetType()->Name, __box(n_instance));
}
~HelloServiceClass()
{
Console::WriteLine(S"Destroyed instance {0} of HelloServiceClass.", __box(n_instance));
n_instance --;
}
public:
String* HelloMethod(String* name)
{
// Reports that the method was called.
Console::WriteLine();
Console::WriteLine(S"Called HelloMethod on instance {0} with the '{1}' parameter.",
__box(n_instance), name);
// Calculates and returns the result to the client.
return String::Format(S"Hi there {0}", name);
}
};
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン
をクリックします。
参照
RemotingConfiguration クラス | RemotingConfiguration メンバ | System.Runtime.Remoting 名前空間