TcpServerChannel 类  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
为远程调用实现使用 TCP 协议传输消息的服务器信道。
public ref class TcpServerChannel : System::Runtime::Remoting::Channels::IChannelReceiverpublic ref class TcpServerChannel : System::Runtime::Remoting::Channels::IChannelReceiver, System::Runtime::Remoting::Channels::ISecurableChannelpublic class TcpServerChannel : System.Runtime.Remoting.Channels.IChannelReceiverpublic class TcpServerChannel : System.Runtime.Remoting.Channels.IChannelReceiver, System.Runtime.Remoting.Channels.ISecurableChanneltype TcpServerChannel = class
    interface IChannelReceiver
    interface IChanneltype TcpServerChannel = class
    interface IChannelReceiver
    interface IChannel
    interface ISecurableChannelPublic Class TcpServerChannel
Implements IChannelReceiverPublic 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) | 使用指定的信道属性、接收器和授权提供程序初始化 TcpServerChannel 类的新实例。 | 
| TcpServerChannel(Int32) | 初始化在指定端口上侦听的 TcpServerChannel 类的新实例。 | 
| TcpServerChannel(String, Int32) | 使用给定名称初始化 TcpServerChannel 类的新实例,该实例侦听指定的端口。 | 
| TcpServerChannel(String, Int32, IServerChannelSinkProvider) | 以给定的名称初始化 TcpServerChannel 类的新实例,该实例侦听指定的端口并使用指定的接收器。 | 
属性
| 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) |