次の方法で共有


RemotingConfiguration.RegisterWellKnownServiceType メソッド

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

オーバーロードの一覧

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

[Visual Basic] Overloads Public Shared Sub RegisterWellKnownServiceType(WellKnownServiceTypeEntry)

[C#] public static void RegisterWellKnownServiceType(WellKnownServiceTypeEntry);

[C++] public: static void RegisterWellKnownServiceType(WellKnownServiceTypeEntry*);

[JScript] public static function RegisterWellKnownServiceType(WellKnownServiceTypeEntry);

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

[Visual Basic] Overloads Public Shared Sub RegisterWellKnownServiceType(Type, String, WellKnownObjectMode)

[C#] public static void RegisterWellKnownServiceType(Type, string, WellKnownObjectMode);

[C++] public: static void RegisterWellKnownServiceType(Type*, String*, WellKnownObjectMode);

[JScript] public static function RegisterWellKnownServiceType(Type, String, WellKnownObjectMode);

使用例

[Visual Basic, C#, C++] 既知のオブジェクト型としてサーバーでオブジェクト型を登録する例を次に示します。ここで示すサーバー コードに対応するクライアント コードについては、 RegisterWellKnownClientType メソッドのトピックの例を参照してください。

[Visual Basic, C#, C++] メモ   ここでは、RegisterWellKnownServiceType のオーバーロード形式のうちの 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.ApplicationName = "HelloServiceApplication"
      
      RemotingConfiguration.RegisterWellKnownServiceType(GetType(HelloService), "MyUri", WellKnownObjectMode.SingleCall)
    . . . 

      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.ApplicationName = "HelloServiceApplication";

        RemotingConfiguration.RegisterWellKnownServiceType( typeof(HelloService),
                                                            "MyUri",
                                                            WellKnownObjectMode.SingleCall 
                                                          );
    . . . 

        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::ApplicationName = S"HelloServiceApplication";

    RemotingConfiguration::RegisterWellKnownServiceType(__typeof(HelloService),
        S"MyUri",
        WellKnownObjectMode::SingleCall);
    . . . 

    Console::WriteLine(S"Press enter to stop this process.");
    Console::ReadLine();
    return 0;
}

[Visual Basic, C#, C++] 上のサンプル コードで登録したサービス オブジェクトを次の例に示します。

 
Imports System


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 'New
   
   
   Protected Overrides Sub Finalize()
      Console.WriteLine("HelloService instance {0} destroyed.", n_instances)
      n_instances -= 1
      MyBase.Finalize()
   End Sub 'Finalize
   
   
   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 'HelloService

[C#] 
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 + ".";
    }
}

[C++] 
#using <mscorlib.dll>
#using <system.dll>

using namespace System;

public __gc class HelloService : public MarshalByRefObject 
{
    static int n_instances;

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

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

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

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

参照

RemotingConfiguration クラス | RemotingConfiguration メンバ | System.Runtime.Remoting 名前空間