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框架远程处理基础结构使用通道来传输远程呼叫。 当客户端调用远程对象时,调用将序列化为客户端通道发送并由服务器通道接收的消息。 然后对其进行反序列化和处理。 任何返回的值都由服务器通道传输,并由客户端通道接收。

若要在服务器端执行消息的其他处理,可以指定接口的 IServerChannelSinkProvider 实现,通过该接口传递实例处理 TcpServerChannel 的所有消息。

TcpServerChannel 实例接受以二进制或 SOAP 格式序列化的消息。

对象TcpServerChannel具有可在配置文件(通过调用静态RemotingConfiguration.Configure方法)或以编程方式(将集合传递给IDictionaryTcpServerChannel构造函数)中设置的关联配置属性。

构造函数

名称 说明
TcpServerChannel(IDictionary, IServerChannelSinkProvider, IAuthorizeRemotingConnection)

使用指定的通道属性、接收器和授权提供程序初始化类的新实例 TcpServerChannel

TcpServerChannel(IDictionary, IServerChannelSinkProvider)

使用指定的通道属性和接收器初始化类的新实例 TcpServerChannel

TcpServerChannel(Int32)

初始化在指定端口上侦听的类的新实例 TcpServerChannel

TcpServerChannel(String, Int32, IServerChannelSinkProvider)

使用给定名称初始化类的新实例 TcpServerChannel ,该名称侦听指定端口,并使用指定的接收器。

TcpServerChannel(String, Int32)

使用给定的名称初始化类的新实例 TcpServerChannel ,并侦听指定端口。

属性

名称 说明
ChannelData

获取特定于通道的数据。

ChannelName

获取当前通道的名称。

ChannelPriority

获取当前通道的优先级。

IsSecured

获取或设置一个布尔值,该值指示当前通道是否安全。

方法

名称 说明
Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetChannelUri()

返回当前通道的 URI。

GetHashCode()

用作默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
GetUrlsForUri(String)

返回具有指定 URI 的对象的所有 URL 的数组,这些 URL 托管在当前 TcpChannel 实例上。

MemberwiseClone()

创建当前 Object的浅表副本。

(继承自 Object)
Parse(String, String)

从指定的 URL 中提取通道 URI 和远程已知对象 URI。

StartListening(Object)

指示在调用方法停止侦听通道后 StopListening(Object) ,当前通道开始侦听。

StopListening(Object)

指示当前通道停止侦听请求。

ToString()

返回一个表示当前对象的字符串。

(继承自 Object)

适用于