【发布时间】:2021-04-19 13:16:23
【问题描述】:
ChannelFactory<T> factory = ...;
var channel = factory.CreateChannel();
channel.GetType().IsInterface; // true -> what? an instance of interface?
channel is IClientChannel; // true
channel.GetType().GetInterfaces(); // empty array -> so does it really implement IClientChannel or does it not?
请查看提供的代码示例。
我知道 WCF 动态编译 __TransparentProxy 但它如何隐藏 channel 的类型,使对象看起来像接口的实例?
如何获得channel 的真实类型及其实际实现的接口列表?
【问题讨论】:
-
channel.GetType() 返回什么?
-
Channel确实是一个接口,它是WCF服务的接口。在我看来,如果创建了通道,此时客户端应该有WCF端的基地址和一些配置信息,然后可以通过通道接口中定义的一些方法远程调用WCF服务。