【问题标题】:How is this WCF ChannelFactory type weirdness possible?这种 WCF ChannelFactory 类型的怪异怎么可能?
【发布时间】: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服务。

标签: c# wcf types interface


【解决方案1】:

阿法伊克

channel 是接口的实例,而不是类。至少代码看到它的方式。虽然那里大概有一个实际的类,但在这段代码中,它被认为是一个接口的实例。

那个接口没有实现其他接口,所以GetInterfaces()是空的。

关于如何获取接口背后的实际类 - 这应该是一个单独的问题。 (而且,我不知道该怎么做。)但请先检查一下 - 好像之前在这里被问过。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2014-05-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多