IpcChannel クラス
アセンブリ: System.Runtime.Remoting (system.runtime.remoting.dll 内)
構文
チャネルは、リモート呼び出しを転送するために .NET Framework のリモート処理インフラストラクチャによって使用されます。クライアントがリモート オブジェクトを呼び出すと、この呼び出しは、クライアント チャネルからサーバー チャネルに送信されるメッセージとしてシリアル化されます。メッセージの受信後、このメッセージが逆シリアル化され、処理されます。戻り値は、サーバー チャネルからクライアント チャネルに送信されます。
IpcChannel クラスは、IpcClientChannel クラスと IpcServerChannel クラスの機能を組み合わせた便利なクラスです。
IpcChannel を使用してリモート処理サーバーとそのクライアントを設定する方法を次のコード例に示します。この例は、次の 3 つの部分で構成されます。
using System; using System.Runtime.Remoting.Channels.Ipc; using System.Security.Permissions; public class Server { [SecurityPermission(SecurityAction.Demand)] public static void Main(string[] args) { // Create the server channel. IpcChannel serverChannel = new IpcChannel("localhost:9090"); // Register the server channel. System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel( serverChannel); // Show the name of the channel. Console.WriteLine("The name of the channel is {0}.", serverChannel.ChannelName); // Show the priority of the channel. Console.WriteLine("The priority of the channel is {0}.", serverChannel.ChannelPriority); // Show the URIs associated with the channel. System.Runtime.Remoting.Channels.ChannelDataStore channelData = (System.Runtime.Remoting.Channels.ChannelDataStore) serverChannel.ChannelData; foreach (string uri in channelData.ChannelUris) { Console.WriteLine("The channel URI is {0}.", uri); } // Expose an object for remote calls. System.Runtime.Remoting.RemotingConfiguration. RegisterWellKnownServiceType( typeof(RemoteObject), "RemoteObject.rem", System.Runtime.Remoting.WellKnownObjectMode.Singleton); // Parse the channel's URI. string[] urls = serverChannel.GetUrlsForUri("RemoteObject.rem"); if (urls.Length > 0) { string objectUrl = urls[0]; string objectUri; string channelUri = serverChannel.Parse(objectUrl, out objectUri); Console.WriteLine("The object URI is {0}.", objectUri); Console.WriteLine("The channel URI is {0}.", channelUri); Console.WriteLine("The object URL is {0}.", objectUrl); } // Wait for the user prompt. Console.WriteLine("Press ENTER to exit the server."); Console.ReadLine(); Console.WriteLine("The server is exiting."); } }
#using <System.dll> #using <System.Runtime.Remoting.dll> #using "common.dll" using namespace System; using namespace System::Runtime::Remoting::Channels::Ipc; void main() { // Create the server channel. IpcChannel^ serverChannel = gcnew IpcChannel( L"localhost:9090" ); // Register the server channel. System::Runtime::Remoting::Channels::ChannelServices::RegisterChannel( serverChannel ); // Show the name of the channel. Console::WriteLine( L"The name of the channel is {0}.", serverChannel->ChannelName ); // Show the priority of the channel. Console::WriteLine( L"The priority of the channel is {0}.", serverChannel->ChannelPriority ); // Show the URIs associated with the channel. System::Runtime::Remoting::Channels::ChannelDataStore^ channelData = (System::Runtime::Remoting::Channels::ChannelDataStore^)serverChannel->ChannelData; for each (String^ uri in channelData->ChannelUris) { Console::WriteLine("The channel URI is {0}.", uri); } // Expose an object for remote calls. System::Runtime::Remoting::RemotingConfiguration::RegisterWellKnownServiceType( RemoteObject::typeid,L"RemoteObject.rem", System::Runtime::Remoting::WellKnownObjectMode::Singleton); // Parse the channel's URI. array<String^>^ urls = serverChannel->GetUrlsForUri( L"RemoteObject.rem" ); if ( urls->Length > 0 ) { String^ objectUrl = urls[ 0 ]; String^ objectUri; String^ channelUri = serverChannel->Parse( objectUrl, objectUri ); Console::WriteLine( L"The object URI is {0}.", objectUri ); Console::WriteLine( L"The channel URI is {0}.", channelUri ); Console::WriteLine( L"The object URL is {0}.", objectUrl ); } // Wait for the user prompt. Console::WriteLine( L"Press ENTER to exit the server." ); Console::ReadLine(); Console::WriteLine( L"The server is exiting." ); }
using System; using System.Runtime.Remoting.Channels.Ipc; using System.Security.Permissions; public class Client { [SecurityPermission(SecurityAction.Demand)] public static void Main(string[] args) { // Create the channel. IpcChannel channel = new IpcChannel(); // Register the channel. System.Runtime.Remoting.Channels.ChannelServices. RegisterChannel(channel); // Register as client for remote object. System.Runtime.Remoting.WellKnownClientTypeEntry remoteType = new System.Runtime.Remoting.WellKnownClientTypeEntry( typeof(RemoteObject), "ipc://localhost:9090/RemoteObject.rem"); System.Runtime.Remoting.RemotingConfiguration. RegisterWellKnownClientType(remoteType); // Create a message sink. string objectUri; System.Runtime.Remoting.Messaging.IMessageSink messageSink = channel.CreateMessageSink( "ipc://localhost:9090/RemoteObject.rem", null , out objectUri); Console.WriteLine("The URI of the message sink is {0}.", objectUri); if (messageSink != null) { Console.WriteLine("The type of the message sink is {0}.", messageSink.GetType().ToString()); } // Create an instance of the remote object. RemoteObject service = new RemoteObject(); // Invoke a method on the remote object. Console.WriteLine("The client is invoking the remote object."); Console.WriteLine("The remote object has been called {0} times." , service.GetCount()); } }
#using <System.dll> #using <System.Runtime.Remoting.dll> #using "common.dll" using namespace System; using namespace System::Runtime::Remoting::Channels::Ipc; void main() { // Create the channel. IpcChannel^ channel = gcnew IpcChannel; // Register the channel. System::Runtime::Remoting::Channels::ChannelServices::RegisterChannel(channel); // Register as client for remote object. System::Runtime::Remoting::WellKnownClientTypeEntry^ remoteType = gcnew System::Runtime::Remoting::WellKnownClientTypeEntry( RemoteObject::typeid,L"ipc://localhost:9090/RemoteObject.rem" ); System::Runtime::Remoting::RemotingConfiguration::RegisterWellKnownClientType(remoteType); // Create a message sink. String^ objectUri; System::Runtime::Remoting::Messaging::IMessageSink^ messageSink = channel->CreateMessageSink( L"ipc://localhost:9090/RemoteObject.rem", nullptr, objectUri ); Console::WriteLine( L"The URI of the message sink is {0}.", objectUri ); if ( messageSink != nullptr ) { Console::WriteLine( L"The type of the message sink is {0}.", messageSink->GetType() ); } // Create an instance of the remote object. RemoteObject^ service = gcnew RemoteObject; // Invoke a method on the remote object. Console::WriteLine( L"The client is invoking the remote object." ); Console::WriteLine( L"The remote object has been called {0} times.", service->GetCount() ); }
System.Runtime.Remoting.Channels.Ipc.IpcChannel
プラットフォーム
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
- IpcChannel クラスのページへのリンク