語言

TcpClientChannel 類別

定義

對於遠端通話,實作了一個使用 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 框架遠端基礎設施用於傳輸遠端通話。 當用戶端呼叫遠端物件時,該呼叫會序列化成由用戶端通道傳送並由伺服器通道接收的訊息。 接著被解序並處理。 任何回傳的值由伺服器通道傳送,並由用戶端通道接收。

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

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

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

建構函式

名稱 Description
TcpClientChannel()

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

TcpClientChannel(IDictionary, IClientChannelSinkProvider)

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

TcpClientChannel(String, IClientChannelSinkProvider)

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

屬性

名稱 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)

適用於