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);
    }
}

備註

重要

使用不信任的資料呼叫此類別的方法,會造成安全性上的風險。 呼叫此類別的方法時,請一律使用信任的資料。 如需詳細資訊,請參閱 驗證所有輸入

通道會跨遠端界限傳輸訊息 (,例如電腦或應用程式域) 。 類別 TcpClientChannel 會使用 TCP 通訊協定傳輸訊息。

.NET Framework 遠端基礎結構會使用通道來傳輸遠端呼叫。 當用戶端呼叫遠端物件時,呼叫會串行化為用戶端通道所傳送且由伺服器通道接收的訊息。 然後,它會還原串行化和處理。 任何傳回的值都是由伺服器通道傳輸,並由用戶端通道接收。

若要在用戶端執行其他訊息處理,您可以指定介面的 IClientChannelSinkProvider 實作,透過該介面傳遞所有訊息 TcpClientChannel

根據預設,類別 TcpClientChannel 會使用二進位格式器來串行化所有訊息。

TcpClientChannel物件具有相關聯的組態屬性,可在組態檔中設定 (,方法是叫用靜態RemotingConfiguration.Configure方法) ,或藉由將集合傳遞IDictionaryTcpClientChannel建構函式) ,以程式設計方式 (。 如需這些組態屬性的清單,請參閱 的檔 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)

適用於