TcpClientChannel クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
リモート呼び出しの場合は、TCP プロトコルを使用してメッセージを送信するクライアント チャネルを実装します。
public ref class TcpClientChannel : System::Runtime::Remoting::Channels::IChannelSender
public ref class TcpClientChannel : System::Runtime::Remoting::Channels::IChannelSender, System::Runtime::Remoting::Channels::ISecurableChannel
public class TcpClientChannel : System.Runtime.Remoting.Channels.IChannelSender
public class TcpClientChannel : System.Runtime.Remoting.Channels.IChannelSender, System.Runtime.Remoting.Channels.ISecurableChannel
type TcpClientChannel = class
interface IChannelSender
interface IChannel
type TcpClientChannel = class
interface IChannelSender
interface IChannel
interface ISecurableChannel
Public Class TcpClientChannel
Implements IChannelSender
Public Class TcpClientChannel
Implements IChannelSender, ISecurableChannel
- 継承
-
TcpClientChannel
- 実装
例
次のコード例は、 TcpClientChannel クラスを使用してリモート型を呼び出す方法を示しています。
#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 client channel.
TcpClientChannel^ clientChannel = gcnew TcpClientChannel;
ChannelServices::RegisterChannel( clientChannel );
// Show the name and priority of the channel.
Console::WriteLine( "Channel Name: {0}", clientChannel->ChannelName );
Console::WriteLine( "Channel Priority: {0}", clientChannel->ChannelPriority );
// Obtain a proxy for a remote object.
RemotingConfiguration::RegisterWellKnownClientType( Remotable::typeid, "tcp://localhost:9090/Remotable.rem" );
// Call a method on the object.
Remotable ^ remoteObject = gcnew Remotable;
Console::WriteLine( remoteObject->GetCount() );
}
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
public class Client
{
public static void Main()
{
// Set up a client channel.
TcpClientChannel clientChannel = new TcpClientChannel();
ChannelServices.RegisterChannel(clientChannel);
// Show the name and priority of the channel.
Console.WriteLine("Channel Name: {0}", clientChannel.ChannelName);
Console.WriteLine("Channel Priority: {0}", clientChannel.ChannelPriority);
// Obtain a proxy for a remote object.
RemotingConfiguration.RegisterWellKnownClientType(
typeof(Remotable), "tcp://localhost:9090/Remotable.rem"
);
// Call a method on the object.
Remotable remoteObject = new Remotable();
Console.WriteLine( remoteObject.GetCount() );
}
}
上記の例で呼び出されたリモート型は、次のコードによって定義されています。
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);
}
}
注釈
Important
信頼されていないデータを使用してこのクラスからメソッドを呼び出すことは、セキュリティ上のリスクです。 このクラスのメソッドは、信頼できるデータでのみ呼び出します。 詳細については、「すべての入力を検証する」を参照してください。
チャネルは、リモート処理の境界を越えてメッセージを転送します (コンピューターやアプリケーション ドメインなど)。 TcpClientChannel クラスは、TCP プロトコルを使用してメッセージを転送します。
チャネルは、リモート呼び出しを転送するために、.NET Framework リモート処理インフラストラクチャによって使用されます。 クライアントがリモート オブジェクトを呼び出すと、その呼び出しは、クライアント チャネルによって送信され、サーバー チャネルによって受信されるメッセージにシリアル化されます。 その後、逆シリアル化されて処理されます。 返された値はすべて、サーバー チャネルによって送信され、クライアント チャネルによって受信されます。
クライアント側でメッセージの追加処理を実行するには、IClientChannelSinkProviderによって処理されたすべてのメッセージが渡されるTcpClientChannel インターフェイスの実装を指定します。
既定では、 TcpClientChannel クラスはバイナリ フォーマッタを使用してすべてのメッセージをシリアル化します。
TcpClientChannel オブジェクトには関連付けられた構成プロパティがあり、実行時に構成ファイル内で (静的RemotingConfiguration.Configure メソッドを呼び出すことによって) またはプログラムによって (IDictionary コンストラクターにTcpClientChannel コレクションを渡すことによって) 設定できます。 これらの構成プロパティの一覧については、 TcpClientChannelのドキュメントを参照してください。
コンストラクター
| 名前 | 説明 |
|---|---|
| TcpClientChannel() |
TcpClientChannel クラスの新しいインスタンスを初期化します。 |
| TcpClientChannel(IDictionary, IClientChannelSinkProvider) |
指定した構成プロパティとシンクを使用して、 TcpClientChannel クラスの新しいインスタンスを初期化します。 |
| TcpClientChannel(String, IClientChannelSinkProvider) |
指定した名前とシンクを使用して、 TcpClientChannel クラスの新しいインスタンスを初期化します。 |
プロパティ
| 名前 | 説明 |
|---|---|
| ChannelName |
現在のチャネルの名前を取得します。 |
| ChannelPriority |
現在のチャネルの優先順位を取得します。 |
| IsSecured |
現在のチャネルがセキュリティで保護されているかどうかを示すブール値を取得または設定します。 |
メソッド
| 名前 | 説明 |
|---|---|
| CreateMessageSink(String, Object, String) |
指定した URL またはチャネル データ オブジェクトにメッセージを配信するチャネル メッセージ シンクを返します。 |
| Equals(Object) |
指定したオブジェクトが現在のオブジェクトと等しいかどうかを判断します。 (継承元 Object) |
| GetHashCode() |
既定のハッシュ関数として機能します。 (継承元 Object) |
| GetType() |
現在のインスタンスの Type を取得します。 (継承元 Object) |
| MemberwiseClone() |
現在の Objectの簡易コピーを作成します。 (継承元 Object) |
| Parse(String, String) |
指定した URL からチャネル URI とリモートの既知のオブジェクト URI を抽出します。 |
| ToString() |
現在のオブジェクトを表す文字列を返します。 (継承元 Object) |