public IInterceptor CreateInterceptor(IServiceContext sourceBeanContext, Type syncLocalInterface, Type syncRemoteInterface, Type asyncRemoteInterface)
        {
            ParamChecker.AssertParamNotNull(sourceBeanContext, "sourceBeanContext");
            if (syncRemoteInterface == null)
            {
                syncRemoteInterface = syncLocalInterface;
            }
            Type clientProviderType = ClientServiceFactory.GetTargetProviderType(syncRemoteInterface);

            String serviceName = ClientServiceFactory.GetServiceName(syncRemoteInterface);

            String logInterceptorName       = "logInterceptor";
            String remoteTargetProviderName = "remoteTargetProvider";
            String interceptorName          = "interceptor";

            IServiceContext childContext = sourceBeanContext.CreateService(delegate(IBeanContextFactory bcf)
            {
                if (typeof(IRemoteTargetProvider).IsAssignableFrom(clientProviderType))
                {
                    bcf.RegisterBean(remoteTargetProviderName, clientProviderType).PropertyValue("ServiceName", serviceName);
                    ClientServiceFactory.PostProcessTargetProviderBean(remoteTargetProviderName, bcf);

                    bcf.RegisterBean <TargetingInterceptor>(interceptorName).PropertyRef("TargetProvider", remoteTargetProviderName);
                }
                else if (typeof(IRemoteInterceptor).IsAssignableFrom(clientProviderType))
                {
                    bcf.RegisterBean(interceptorName, clientProviderType).PropertyValue("ServiceName", serviceName);
                    ClientServiceFactory.PostProcessTargetProviderBean(interceptorName, bcf);
                }
                else
                {
                    throw new Exception("ProviderType '" + clientProviderType + "' is not supported here");
                }
                bcf.RegisterBean <LogInterceptor>(logInterceptorName).PropertyRef("Target", interceptorName);
            });

            return(childContext.GetService <IInterceptor>(logInterceptorName));
        }
        public IInterceptor CreateInterceptor(IServiceContext sourceBeanContext, Type syncLocalInterface, Type syncRemoteInterface, Type asyncRemoteInterface)
        {
            ParamChecker.AssertParamNotNull(sourceBeanContext, "sourceBeanContext");
            Type syncInterceptorType = null;

            if (syncRemoteInterface == null)
            {
                syncRemoteInterface = syncLocalInterface;
            }
            else
            {
                syncInterceptorType = ClientServiceFactory.GetSyncInterceptorType(syncRemoteInterface);
            }

            if (asyncRemoteInterface == null)
            {
                asyncRemoteInterface = syncRemoteInterface;
            }

            Type clientProviderType = ClientServiceFactory.GetTargetProviderType(asyncRemoteInterface);

            String serviceName = ClientServiceFactory.GetServiceName(syncRemoteInterface);

            String syncRemoteInterceptorName = "syncRemoteInterceptor";
            String syncCallInterceptorName   = "syncCallInterceptor";
            String targetProviderName        = "targetProvider";
            String targetingInterceptorName  = "targetingInterceptor";
            String asyncProxyName            = "asyncProxy";

            IServiceContext childContext = sourceBeanContext.CreateService(delegate(IBeanContextFactory bcf)
            {
                if (typeof(IRemoteTargetProvider).IsAssignableFrom(clientProviderType))
                {
                    bcf.RegisterBean(targetProviderName, clientProviderType).PropertyValue("ServiceName", serviceName);
                    ClientServiceFactory.PostProcessTargetProviderBean(targetProviderName, bcf);

                    //TargetProvider and target have to be set up manually here
                    bcf.RegisterBean <TargetingInterceptor>(targetingInterceptorName).PropertyRef("TargetProvider", targetProviderName);

                    LogInterceptor logInterceptor = (LogInterceptor)bcf.RegisterBean <LogInterceptor>("logInterceptor").PropertyRef("Target", targetingInterceptorName).GetInstance();

                    Object asyncProxy = ProxyFactory.CreateProxy(asyncRemoteInterface, logInterceptor);
                    bcf.RegisterExternalBean(asyncProxyName, asyncProxy);

                    bcf.RegisterBean <SyncCallInterceptor>(syncCallInterceptorName).PropertyRef("AsyncService", asyncProxyName).PropertyValue("AsyncServiceInterface", asyncRemoteInterface);

                    if (syncRemoteInterface != syncLocalInterface)
                    {
                        bcf.RegisterBean(syncRemoteInterceptorName, syncInterceptorType).PropertyValue("WCFInterfaceType", syncRemoteInterface);
                    }
                    else
                    {
                        bcf.RegisterAlias(syncRemoteInterceptorName, syncCallInterceptorName);
                    }
                }
                else
                {
                    throw new Exception("ProviderType '" + clientProviderType + "' is not supported here");
                }
            });

            return(childContext.GetService <IInterceptor>(syncRemoteInterceptorName));
        }