TcpServerChannel クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
TCP プロトコルを使用してメッセージを送信するリモート呼び出し用のサーバー チャネルを実装します。
public ref class TcpServerChannel : System::Runtime::Remoting::Channels::IChannelReceiver
public ref class TcpServerChannel : System::Runtime::Remoting::Channels::IChannelReceiver, System::Runtime::Remoting::Channels::ISecurableChannel
public class TcpServerChannel : System.Runtime.Remoting.Channels.IChannelReceiver
public class TcpServerChannel : System.Runtime.Remoting.Channels.IChannelReceiver, System.Runtime.Remoting.Channels.ISecurableChannel
type TcpServerChannel = class
interface IChannelReceiver
interface IChannel
type TcpServerChannel = class
interface IChannelReceiver
interface IChannel
interface ISecurableChannel
Public Class TcpServerChannel
Implements IChannelReceiver
Public Class TcpServerChannel
Implements IChannelReceiver, ISecurableChannel
- 継承
-
TcpServerChannel
- 実装
例
次のコード例は、リモートテーブル型の使用を示しています。
using namespace System;
using namespace System::Runtime::Remoting;
public ref class Remotable: public MarshalByRefObject
{
private:
int callCount;
public:
Remotable()
: callCount( 0 )
{}
int GetCount()
{
callCount++;
return (callCount);
}
};
using System;
using System.Runtime.Remoting;
public class Remotable : MarshalByRefObject
{
private int callCount = 0;
public int GetCount()
{
callCount++;
return(callCount);
}
}
次のコード例は、 TcpServerChannel クラスを使用してリモート処理可能な型を公開する方法を示しています。
#using <System.Runtime.Remoting.dll>
#using <System.dll>
#using <Remotable.dll>
using namespace System;
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Channels;
using namespace System::Runtime::Remoting::Channels::Tcp;
int main()
{
// Set up a server channel.
TcpServerChannel^ serverChannel = gcnew TcpServerChannel( 9090 );
ChannelServices::RegisterChannel( serverChannel );
// Expose an object for remote calls.
RemotingConfiguration::RegisterWellKnownServiceType( Remotable::typeid, "Remotable.rem", WellKnownObjectMode::Singleton );
// Show the name and priority of the channel.
Console::WriteLine( "Channel Name: {0}", serverChannel->ChannelName );
Console::WriteLine( "Channel Priority: {0}", serverChannel->ChannelPriority );
// Show the URIs associated with the channel.
ChannelDataStore^ data = dynamic_cast<ChannelDataStore^>(serverChannel->ChannelData);
System::Collections::IEnumerator^ myEnum = data->ChannelUris->GetEnumerator();
while ( myEnum->MoveNext() )
{
String^ uri = safe_cast<String^>(myEnum->Current);
Console::WriteLine( uri );
}
// Wait for method calls.
Console::WriteLine( "Listening..." );
Console::ReadLine();
}
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
public class Server
{
public static void Main()
{
// Set up a server channel.
TcpServerChannel serverChannel = new TcpServerChannel(9090);
ChannelServices.RegisterChannel(serverChannel);
// Expose an object for remote calls.
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(Remotable), "Remotable.rem", WellKnownObjectMode.Singleton
);
// Show the name and priority of the channel.
Console.WriteLine("Channel Name: {0}", serverChannel.ChannelName);
Console.WriteLine("Channel Priority: {0}", serverChannel.ChannelPriority);
// Show the URIs associated with the channel.
ChannelDataStore data = (ChannelDataStore) serverChannel.ChannelData;
foreach (string uri in data.ChannelUris)
{
Console.WriteLine(uri);
}
// Wait for method calls.
Console.WriteLine("Listening...");
Console.ReadLine();
}
}
注釈
Important
信頼されていないデータを使用してこのクラスからメソッドを呼び出すことは、セキュリティ上のリスクです。 このクラスのメソッドは、信頼できるデータでのみ呼び出します。 詳細については、「すべての入力を検証する」を参照してください。
チャネルは、リモート処理の境界を越えてメッセージを転送します (コンピューターやアプリケーション ドメインなど)。 TcpServerChannel クラスは、TCP プロトコルを使用してメッセージを転送します。
チャネルは、リモート呼び出しを転送するために、.NET Framework リモート処理インフラストラクチャによって使用されます。 クライアントがリモート オブジェクトを呼び出すと、その呼び出しは、クライアント チャネルによって送信され、サーバー チャネルによって受信されるメッセージにシリアル化されます。 その後、逆シリアル化されて処理されます。 返された値はすべて、サーバー チャネルによって送信され、クライアント チャネルによって受信されます。
サーバー側でメッセージの追加処理を実行するには、IServerChannelSinkProvider インスタンスによって処理されたすべてのメッセージが渡されるTcpServerChannel インターフェイスの実装を指定します。
TcpServerChannel インスタンスは、バイナリ形式または SOAP 形式でシリアル化されたメッセージを受け入れます。
TcpServerChannel オブジェクトには関連付けられた構成プロパティがあり、実行時に構成ファイル内で (静的RemotingConfiguration.Configure メソッドを呼び出すことによって) またはプログラムによって (IDictionary コンストラクターにTcpServerChannel コレクションを渡すことによって) 設定できます。 これらの構成プロパティの一覧については、「 チャネルとフォーマッタの構成プロパティ」を参照してください。
コンストラクター
| 名前 | 説明 |
|---|---|
| TcpServerChannel(IDictionary, IServerChannelSinkProvider, IAuthorizeRemotingConnection) |
指定したチャネル プロパティ、シンク、および承認プロバイダーを使用して、 TcpServerChannel クラスの新しいインスタンスを初期化します。 |
| TcpServerChannel(IDictionary, IServerChannelSinkProvider) |
指定したチャネル プロパティとシンクを使用して、 TcpServerChannel クラスの新しいインスタンスを初期化します。 |
| TcpServerChannel(Int32) |
指定したポートでリッスンする TcpServerChannel クラスの新しいインスタンスを初期化します。 |
| TcpServerChannel(String, Int32, IServerChannelSinkProvider) |
指定したポートでリッスンし、指定したシンクを使用する、指定した名前を使用して、 TcpServerChannel クラスの新しいインスタンスを初期化します。 |
| TcpServerChannel(String, Int32) |
指定した名前で TcpServerChannel クラスの新しいインスタンスを初期化し、指定したポートでリッスンします。 |
プロパティ
| 名前 | 説明 |
|---|---|
| ChannelData |
チャネル固有のデータを取得します。 |
| ChannelName |
現在のチャネルの名前を取得します。 |
| ChannelPriority |
現在のチャネルの優先順位を取得します。 |
| IsSecured |
現在のチャネルがセキュリティで保護されているかどうかを示すブール値を取得または設定します。 |
メソッド
| 名前 | 説明 |
|---|---|
| Equals(Object) |
指定したオブジェクトが現在のオブジェクトと等しいかどうかを判断します。 (継承元 Object) |
| GetChannelUri() |
現在のチャネルの URI を返します。 |
| GetHashCode() |
既定のハッシュ関数として機能します。 (継承元 Object) |
| GetType() |
現在のインスタンスの Type を取得します。 (継承元 Object) |
| GetUrlsForUri(String) |
現在の TcpChannel インスタンスでホストされている、指定した URI を持つオブジェクトのすべての URL の配列を返します。 |
| MemberwiseClone() |
現在の Objectの簡易コピーを作成します。 (継承元 Object) |
| Parse(String, String) |
指定した URL からチャネル URI とリモートの既知のオブジェクト URI を抽出します。 |
| StartListening(Object) |
チャネルのリッスンを停止するために StopListening(Object) メソッドが呼び出された後、チャネルのリッスンを開始するように現在のチャネルに指示します。 |
| StopListening(Object) |
要求のリッスンを停止するように現在のチャネルに指示します。 |
| ToString() |
現在のオブジェクトを表す文字列を返します。 (継承元 Object) |