简体   繁体   English

这个 WCF ChannelFactory 类型的怪异怎么可能?

[英]How is this WCF ChannelFactory type weirdness possible?

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?

Please take a look at the provided code sample.请查看提供的代码示例。
I know that WCF dynamically compiles __TransparentProxy but how can it hide a type of channel so that object looks like an instance of an interface?我知道 WCF 动态编译__TransparentProxy但它如何隐藏一种类型的channel ,以便 object 看起来像一个接口的实例?
How could one obtain real type of channel and list of interfaces it actually implements?如何获得真实的channel类型和它实际实现的接口列表?

AFAIK AFAIK

channel is an instance of an interface, not a class. At least the way the code sees it. channel是接口的实例,而不是 class。至少代码看到它的方式。 Though there is, presumably, an actual class there, in this code it's considered something like an instance of an interface.虽然可能有一个实际的 class,但在这段代码中,它被认为是类似于接口实例的东西。

That interface doesn't implement other interfaces so GetInterfaces() is empty.接口不实现其他接口,因此GetInterfaces()为空。

About how to get the actual class behind the interface - that should be a separate question.关于如何在接口后面获取实际的 class - 这应该是一个单独的问题。 (And, I don't know how to do it.) But check first - it looks like it's been asked before here. (而且,我不知道该怎么做。)但是先检查一下 - 看起来之前在这里已经被问过。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM