TcpServerChannel 類別

定義

針對遠端呼叫實作使用 TCP 通訊協定傳輸訊息的伺服器通道。

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

範例

下列程式代碼範例示範使用可遠端類型。

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

下列程式代碼範例示範如何使用 TcpServerChannel 類別來公開可遠端類型。

#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 server channel.
   TcpServerChannel^ serverChannel = gcnew TcpServerChannel( 9090 );
   ChannelServices::RegisterChannel( serverChannel );

   // Expose an object for remote calls.
   RemotingConfiguration::RegisterWellKnownServiceType( Remotable::typeid, "Remotable.rem", WellKnownObjectMode::Singleton );

   // Show the name and priority of the channel.
   Console::WriteLine( "Channel Name: {0}", serverChannel->ChannelName );
   Console::WriteLine( "Channel Priority: {0}", serverChannel->ChannelPriority );

   // Show the URIs associated with the channel.
   ChannelDataStore^ data = dynamic_cast<ChannelDataStore^>(serverChannel->ChannelData);
   System::Collections::IEnumerator^ myEnum = data->ChannelUris->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      String^ uri = safe_cast<String^>(myEnum->Current);
      Console::WriteLine( uri );
   }

   // Wait for method calls.
   Console::WriteLine( "Listening..." );
   Console::ReadLine();
}
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

public class Server
{
    public static void Main()
    {

        // Set up a server channel.
        TcpServerChannel serverChannel = new TcpServerChannel(9090);
        ChannelServices.RegisterChannel(serverChannel);

        // Expose an object for remote calls.
        RemotingConfiguration.RegisterWellKnownServiceType(
            typeof(Remotable), "Remotable.rem", WellKnownObjectMode.Singleton
        );

        // Show the name and priority of the channel.
        Console.WriteLine("Channel Name: {0}", serverChannel.ChannelName);
        Console.WriteLine("Channel Priority: {0}", serverChannel.ChannelPriority);

        // Show the URIs associated with the channel.
        ChannelDataStore data = (ChannelDataStore) serverChannel.ChannelData;
        foreach (string uri in data.ChannelUris)
        {
            Console.WriteLine(uri);
        }

        // Wait for method calls.
        Console.WriteLine("Listening...");
        Console.ReadLine();
    }
}

備註

重要

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

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

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

若要在伺服器端執行其他訊息處理,您可以指定介面的 IServerChannelSinkProvider 實作,該介面會透過此實作,傳遞實例所 TcpServerChannel 處理的所有訊息。

TcpServerChannel實例接受以二進位或SOAP格式串行化的訊息。

TcpServerChannel物件具有相關聯的組態屬性,可在組態檔中設定 (,方法是叫用靜態RemotingConfiguration.Configure方法) ,或藉由將集合傳遞IDictionaryTcpServerChannel建構函式) ,以程式設計方式 (。 如需這些組態屬性的清單,請參閱 通道和格式器組態屬性

建構函式

TcpServerChannel(IDictionary, IServerChannelSinkProvider)

使用指定的通道屬性和接收,初始化 TcpServerChannel 類別的新執行個體。

TcpServerChannel(IDictionary, IServerChannelSinkProvider, IAuthorizeRemotingConnection)

使用指定的通道屬性、接收 (Sink) 和授權提供者,初始化 TcpServerChannel 類別的新執行個體。

TcpServerChannel(Int32)

初始化 TcpServerChannel 類別的新執行個體,這個執行個體包含指定的設計工具。

TcpServerChannel(String, Int32)

使用指定的名稱和會接聽指定的連接埠,初始化 TcpServerChannel 類別的新執行個體。

TcpServerChannel(String, Int32, IServerChannelSinkProvider)

使用指定的名稱,初始化 TcpServerChannel 類別的新執行個體,其會接聽指定的連接埠,並使用指定的接收 (Sink)。

屬性

ChannelData

取得通道特定資料。

ChannelName

取得目前通道的名稱。

ChannelPriority

取得目前通道的優先權。

IsSecured

取得或設定指出目前通道是否安全的布林值。

方法

Equals(Object)

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

(繼承來源 Object)
GetChannelUri()

傳回目前通道的 URI。

GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
GetUrlsForUri(String)

傳回具有指定 URI 之物件的所有 URL 陣列,裝載於目前 TcpChannel 執行個體上。

MemberwiseClone()

建立目前 Object 的淺層複製。

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

從指定的 URL 擷取通道 URI 和遠端已知物件 URI。

StartListening(Object)

指示目前的通道在呼叫 StopListening(Object) 方法以停止在通道上接聽之後,開始在通道上接聽。

StopListening(Object)

指示目前通道停止接聽要求。

ToString()

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

(繼承來源 Object)

適用於