TcpClientChannel 类  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
为远程调用实现使用 TCP 协议传输消息的客户端信道。
public ref class TcpClientChannel : System::Runtime::Remoting::Channels::IChannelSenderpublic ref class TcpClientChannel : System::Runtime::Remoting::Channels::IChannelSender, System::Runtime::Remoting::Channels::ISecurableChannelpublic class TcpClientChannel : System.Runtime.Remoting.Channels.IChannelSenderpublic class TcpClientChannel : System.Runtime.Remoting.Channels.IChannelSender, System.Runtime.Remoting.Channels.ISecurableChanneltype TcpClientChannel = class
    interface IChannelSender
    interface IChanneltype TcpClientChannel = class
    interface IChannelSender
    interface IChannel
    interface ISecurableChannelPublic Class TcpClientChannel
Implements IChannelSenderPublic 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) |