TcpClientChannel 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
对于远程调用,实现使用 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);
}
}
注解
Important
使用不受信任的数据调用此类中的方法存在安全风险。 仅在确保数据受信任的情况下,再从该类调用方法。 有关详细信息,请参阅验证所有输入。
通道跨远程处理边界传输消息(例如计算机或应用程序域)。 类 TcpClientChannel 使用 TCP 协议传输消息。
.NET框架远程处理基础结构使用通道来传输远程呼叫。 当客户端调用远程对象时,调用将序列化为客户端通道发送并由服务器通道接收的消息。 然后对其进行反序列化和处理。 任何返回的值都由服务器通道传输,并由客户端通道接收。
若要在客户端执行其他消息处理,可以指定接口的 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) |