如何为 ChannelFactory生成的 WCF 代理创建 DynamicProxy?

发布于 2024-09-10 23:18:52 字数 471 浏览 0 评论 0原文

我正在使用 ChannelFactory 在运行时为 WCF 服务创建代理。我想使用 DynamicProxy Castle 项目在 WCF 代理之上创建一个动态代理,以便我可以拦截调用并进行模拟。

当我尝试此操作时,我收到错误...错误消息是:

“此”类型本身不能是接口。

我的代码是这样的(其中T是服务契约接口):

var generator = new ProxyGenerator();

return (T)generator.CreateInterfaceProxyWithTarget(typeof(T), channel, 
    new[] { new ImpersonationInterceptor() } );

这个问题肯定与ChannelFactory生成的服务代理是在运行时生成的事实有关,但是有什么办法可以解决这个问题吗?

I am using ChannelFactory to create a proxy at run-time for a WCF service. I would like to use the DynamicProxy Castle project to create a dynamic proxy on top of the WCF proxy so that I can intercept calls and do impersonation.

I'm getting an error when I try this though... the error message is:

'this' type cannot be an interface itself.

My code is this (where T is a service contract interface):

var generator = new ProxyGenerator();

return (T)generator.CreateInterfaceProxyWithTarget(typeof(T), channel, 
    new[] { new ImpersonationInterceptor() } );

The problem must have to do with the fact that the service proxy generated by ChannelFactory is generated at runtime, but is there any way around this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七禾 2024-09-17 23:18:52

是的 - 有 - 使用 WCF 工具,它用 Castle 的 DynamicProxy 替换 WCF 代理。

这里的问题是,您试图在代理之上构建代理,而远程代理有一些......特定的行为,其结果就是您收到的错误。

Yes - there is - use WCF Facility, it is replacing WCF proxy with Castle's DynamicProxy.

The problem here, is that you're trying to build a proxy on top of a proxy, and remoting proxies have some... specific behaviors, result of which is the error you're getting.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文