語言

IpcClientChannel 類別

定義

實作一個用戶端通道用於遠端通話,使用 IPC 協定傳送訊息。

public ref class IpcClientChannel : System::Runtime::Remoting::Channels::IChannelSender, System::Runtime::Remoting::Channels::ISecurableChannel
public class IpcClientChannel : System.Runtime.Remoting.Channels.IChannelSender, System.Runtime.Remoting.Channels.ISecurableChannel
type IpcClientChannel = class
    interface IChannelSender
    interface IChannel
    interface ISecurableChannel
Public Class IpcClientChannel
Implements IChannelSender, ISecurableChannel
繼承
IpcClientChannel
實作

範例

以下程式碼範例說明如何使用這個 IpcClientChannel 類別。

#using <System.Runtime.Remoting.dll>
#using <System.dll>
#using <Counter.dll>

using namespace System;
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Channels;
using namespace System::Runtime::Remoting::Channels::Ipc;

public ref class Client
{
public:
   void ClientTest()
   {
      IpcClientChannel^ clientChannel = gcnew IpcClientChannel;
      ChannelServices::RegisterChannel( clientChannel );

      RemotingConfiguration::RegisterWellKnownClientType( Counter::typeid, L"ipc://remote/counter" );
      Counter^ counter = gcnew Counter;
      Console::WriteLine( L"This is call number {0}.", counter->Count );
   }
};

int main()
{
   Client^ c = gcnew Client;
   c->ClientTest();
}
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Ipc;

public class Client
{
    public static void Main ()
    {
        IpcClientChannel clientChannel = new IpcClientChannel();
        ChannelServices.RegisterChannel(clientChannel);

        RemotingConfiguration.RegisterWellKnownClientType( typeof(Counter) , "ipc://remote/counter" );

        Counter counter = new Counter();
        Console.WriteLine("This is call number {0}.", counter.Count);
    }
}

前述程式碼使用以下遠端物件。

using namespace System;
public ref class Counter: public MarshalByRefObject
{
private:
   int count;

public:
   Counter()
   {
      count = 0;
   }

   property int Count 
   {
      int get()
      {
         return (count)++;
      }
   }
};
using System;

public class Counter : MarshalByRefObject {

  private int count = 0;

  public int Count { get {
    return(count++);
  } }
}

關於遠端暴露此物件的伺服器範例,請參見 IpcServerChannel。

備註

Important

從這個類別使用不受信任的數據呼叫方法構成安全性風險。 僅使用信任的數據呼叫來自這個類別的方法。 如需詳細資訊,請參閱 驗證所有輸入。

通道由 .NET 框架遠端基礎設施用於傳輸遠端通話。 當用戶端呼叫遠端物件時,呼叫會序列化成由用戶端通道傳送並由伺服器通道接收的訊息。 收到訊息後,會被解序列化並處理。 任何回傳的值由伺服器通道傳送,並由用戶端通道接收。

IpcClientChannel 類別使用Windows程間通訊(IPC)系統,在同一台電腦上傳輸應用程式域間的訊息。 在同一台電腦上,當應用程式域間通訊時,IPC 通道比 TCP 或 HTTP 通道快得多。

若要在用戶端執行額外訊息處理,你可以指定一個介面實作 IClientChannelSinkProvider ,讓所有物件處理 IpcClientChannel 的訊息都會經過此介面傳遞。

預設情況下,該 IpcClientChannel 類別使用二進位格式化器來序列化所有訊息。

物件IpcClientChannel具有相關的組態屬性,可在執行時設定,無論是在設定檔中(透過呼叫靜態RemotingConfiguration.Configure方法)或程式化(將集合傳給IDictionaryIpcClientChannel建構器)中設定。 關於這些組態屬性的清單,請參閱建構子的文件 IpcClientChannel 。

建構函式

名稱 Description
IpcClientChannel()

初始化 IpcServerChannel 類別的新執行個體。

IpcClientChannel(IDictionary, IClientChannelSinkProvider)

初始化一個新的類別實例 IpcClientChannel ,並具備指定的組態屬性與 sink。

IpcClientChannel(String, IClientChannelSinkProvider)

初始化一個以指定名稱和 sink 的新 IpcClientChannel 類別實例。

屬性

名稱 Description
ChannelName

會得到目前頻道的名稱。

ChannelPriority

獲得當前頻道的優先權。

IsSecured

取得或設定一個布林值,指示目前通道是否安全。

方法

名稱 Description
CreateMessageSink(String, Object, String)

回傳一個通道訊息匯入器,將訊息傳送到指定的 URL 或通道資料物件。

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設哈希函式。

(繼承來源 Object)
GetType()

取得目前實例的 Type。

(繼承來源 Object)
MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
Parse(String, String)

從指定的 URL 中擷取通道 URI 及遠端知名物件 URI。

ToString()

傳回表示目前 物件的字串。

(繼承來源 Object)

適用於