diff --git a/src/net45/WampSharp/WAMP2/V2/System.Reflection.DispatchProxy/WampCalleeClientProxyFactory.cs b/src/net45/WampSharp/WAMP2/V2/System.Reflection.DispatchProxy/WampCalleeClientProxyFactory.cs index e1e91d292..e66975e8c 100644 --- a/src/net45/WampSharp/WAMP2/V2/System.Reflection.DispatchProxy/WampCalleeClientProxyFactory.cs +++ b/src/net45/WampSharp/WAMP2/V2/System.Reflection.DispatchProxy/WampCalleeClientProxyFactory.cs @@ -1,5 +1,6 @@ #if DISPATCH_PROXY +using System; using System.Reflection; using WampSharp.V2.Client; @@ -8,23 +9,32 @@ namespace WampSharp.V2.CalleeProxy { internal class WampCalleeClientProxyFactory : IWampCalleeProxyFactory { + private readonly IWampRealmProxy mProxy; private readonly WampCalleeProxyInvocationHandler mHandler; public WampCalleeClientProxyFactory(IWampRealmProxy proxy) { + mProxy = proxy; mHandler = new ClientInvocationHandler(proxy); } public virtual TProxy GetProxy(ICalleeProxyInterceptor interceptor) where TProxy : class { - TProxy result = DispatchProxy.Create(); + if (typeof(CalleeProxyBase).IsAssignableFrom(typeof(TProxy))) + { + return (TProxy) Activator.CreateInstance(typeof(TProxy), mProxy, interceptor); + } + else + { + TProxy result = DispatchProxy.Create(); - CalleeProxy casted = result as CalleeProxy; + CalleeProxy casted = result as CalleeProxy; - casted.Handler = mHandler; - casted.CalleeProxyInterceptor = interceptor; + casted.Handler = mHandler; + casted.CalleeProxyInterceptor = interceptor; - return result; + return result; + } } } }