Share via


IpcChannel Sınıf

Tanım

İletileri iletmek için IPC protokollerini kullanan bir kanal uygulaması sağlar.

public ref class IpcChannel : System::Runtime::Remoting::Channels::IChannelReceiver, System::Runtime::Remoting::Channels::IChannelSender, System::Runtime::Remoting::Channels::ISecurableChannel
public class IpcChannel : System.Runtime.Remoting.Channels.IChannelReceiver, System.Runtime.Remoting.Channels.IChannelSender, System.Runtime.Remoting.Channels.ISecurableChannel
type IpcChannel = class
    interface IChannelReceiver
    interface IChannelSender
    interface IChannel
    interface ISecurableChannel
type IpcChannel = class
    interface IChannelReceiver
    interface IChannel
    interface IChannelSender
    interface ISecurableChannel
Public Class IpcChannel
Implements IChannelReceiver, IChannelSender, ISecurableChannel
Devralma
IpcChannel
Uygulamalar

Örnekler

Aşağıdaki kod örneğinde uzaktan iletişim sunucusunu ve istemcisini ayarlamak için 'nin nasıl kullanılacağı IpcChannel gösterilmektedir. Örnekte üç bölüm bulunur:

  • Sunucu

  • İstemci

  • Sunucu ve istemci tarafından kullanılan uzak nesne.

Aşağıdaki kod örneğinde bir sunucu gösterilmektedir.

#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;

public class Server
{
    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.");
    }
}

Aşağıdaki kod örneğinde bu sunucu için bir istemci gösterilmektedir.

#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() );
}
using System;
using System.Runtime.Remoting.Channels.Ipc;

public class Client
{
    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());
    }
}

Aşağıdaki kod örneği, sunucu ve istemci tarafından kullanılan uzak nesneyi gösterir.

using namespace System;

// Remote object.
public ref class RemoteObject: public MarshalByRefObject
{
private:
   static int callCount = 0;

public:
   int GetCount()
   {
      Console::WriteLine( L"GetCount has been called." );
      callCount++;
      return (callCount);
   }

};
using System;

// Remote object.
public class RemoteObject : MarshalByRefObject
{
    private int callCount = 0;

    public int GetCount()
    {
        Console.WriteLine("GetCount has been called.");
        callCount++;
        return(callCount);
    }
}

Açıklamalar

Önemli

Güvenilmeyen verilerle bu sınıftan yöntemleri çağırmak bir güvenlik riskidir. Bu sınıftaki yöntemleri yalnızca güvenilen verilerle çağırın. Daha fazla bilgi için bkz. Tüm Girişleri Doğrulama.

Kanallar, uzaktan çağrıları taşımak için the.NET Framework uzaktan iletişim altyapısı tarafından kullanılır. İstemci uzak bir nesneyi çağırdığında, çağrı bir istemci kanalı tarafından gönderilen ve bir sunucu kanalı tarafından alınan bir iletide seri hale getirilir. İleti alındıktan sonra seri durumdan çıkarılır ve işlenir. Döndürülen tüm değerler sunucu kanalı tarafından iletilir ve istemci kanalı tarafından alınır.

IpcChannel sınıfı, sınıfın ve sınıfının işlevselliğini IpcClientChannel birleştiren bir kolaylık sınıfıdırIpcServerChannel.

Dikkat

bağımsız değişkeninde properties özelliğini olarak false ayarlarkenexclusiveAddressUse, aynı adlandırılmış kanal için birkaç IpcServerChannel nesne kaydedilebilir. Böyle bir durumda istekler kayıtlı kanallardan herhangi birine gidebilir. Bu ayar yalnızca ALC'ler de kullanılıyorsa güvenli olarak kabul edilir.

Oluşturucular

IpcChannel()

Sınıfın IpcChannel yeni bir örneğini başlatır ve sunucu kanalını değil yalnızca istemci kanalını etkinleştirir.

IpcChannel(IDictionary, IClientChannelSinkProvider, IServerChannelSinkProvider)

Belirtilen yapılandırma özellikleri ve havuzları ile sınıfının yeni bir örneğini IpcChannel başlatır.

IpcChannel(IDictionary, IClientChannelSinkProvider, IServerChannelSinkProvider, CommonSecurityDescriptor)

Belirtilen yapılandırma özellikleri ve havuzları ile sınıfının yeni bir örneğini IpcChannel başlatır.

IpcChannel(String)

Belirtilen IPC bağlantı noktasını dinleyen bir sunucu kanalıyla sınıfının yeni bir örneğini IpcChannel başlatır.

Özellikler

ChannelData

Kanala özgü verileri alır.

ChannelName

Geçerli kanalın adını alır.

ChannelPriority

Geçerli kanalın önceliğini alır.

IsSecured

Geçerli kanalın güvenli olup olmadığını belirten bir Boole değeri alır veya ayarlar.

Yöntemler

CreateMessageSink(String, Object, String)

İletileri belirtilen URL'ye veya kanal veri nesnesine teslim eden bir kanal ileti havuzu döndürür.

Equals(Object)

Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler.

(Devralındığı yer: Object)
GetHashCode()

Varsayılan karma işlevi işlevi görür.

(Devralındığı yer: Object)
GetType()

Type Geçerli örneğini alır.

(Devralındığı yer: Object)
GetUrlsForUri(String)

Geçerli IpcChannelüzerinde barındırılan belirtilen URI'ye sahip bir nesnenin tüm URL'lerinden oluşan bir dizi döndürür.

MemberwiseClone()

Geçerli Objectöğesinin sığ bir kopyasını oluşturur.

(Devralındığı yer: Object)
Parse(String, String)

Kanal URI'sini ve uzak iyi bilinen nesne URI'sini belirtilen URL'den ayıklar.

StartListening(Object)

Geçerli kanala istekleri dinlemeye başlamasını emreder.

StopListening(Object)

Geçerli kanala istekleri dinlemeyi durdurmasını emreder.

ToString()

Geçerli nesneyi temsil eden dizeyi döndürür.

(Devralındığı yer: Object)

Şunlara uygulanır