views:

36

answers:

1

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?

A: 

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.

Krzysztof Koźmic
This doesn't appear to help with my issue. Am I missing something? This looks like it's for the service side, not the client side.
Max Schmeling
It's for both..
Krzysztof Koźmic