public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
        {
            Debug.Assert((m_PreviousProvider == null) || ((m_PreviousProvider != null) && (m_PreviousProvider.Equals(endpointDispatcher.DispatchRuntime.InstanceContextProvider))));

            m_PreviousProvider = endpointDispatcher.DispatchRuntime.InstanceContextProvider;
            endpointDispatcher.DispatchRuntime.InstanceContextProvider = this;
        }
Esempio n. 2
0
        InstanceContext CreateInstanceContext(MessageProcessingContext mrc)
        {
            InstanceContext          iCtx            = null;
            DispatchRuntime          dispatchRuntime = mrc.OperationContext.EndpointDispatcher.DispatchRuntime;
            IInstanceContextProvider p = dispatchRuntime.InstanceContextProvider;

            if (p != null)
            {
                iCtx = p.GetExistingInstanceContext(mrc.IncomingMessage, mrc.OperationContext.Channel);
            }
            if (iCtx == null)
            {
                ServiceHostBase host = dispatchRuntime.ChannelDispatcher.Host;
                iCtx = new InstanceContext(dispatchRuntime.ChannelDispatcher.Host, null, false);
                // FIXME: could be easier way to identify session channel
                if ((mrc.Channel is ISessionChannel <IInputSession> || mrc.Channel is ISessionChannel <IDuplexSession>) && host.Description.Behaviors.Find <ServiceBehaviorAttribute> ().InstanceContextMode == InstanceContextMode.PerSession)
                {
                    mrc.Channel.Closed += delegate { iCtx.Close(); }
                }
                ;
            }

            iCtx.InstanceManager = new InstanceManager(dispatchRuntime);
            return(iCtx);
        }
    }
Esempio n. 3
0
 internal DispatchRuntime(ClientRuntime proxyRuntime, SharedRuntimeState shared)
     : this(shared)
 {
     ClientRuntime            = proxyRuntime ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(proxyRuntime));
     _instanceProvider        = new CallbackInstanceProvider();
     _channelDispatcher       = new ChannelDispatcher(shared);
     _instanceContextProvider = InstanceContextProviderBase.GetProviderForMode(InstanceContextMode.PerSession, this);
     Fx.Assert(!shared.IsOnServer, "Client constructor called on server?");
 }
Esempio n. 4
0
 internal DispatchRuntime(System.ServiceModel.Dispatcher.ClientRuntime proxyRuntime, SharedRuntimeState shared) : this(shared)
 {
     if (proxyRuntime == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("proxyRuntime");
     }
     this.proxyRuntime            = proxyRuntime;
     this.instanceProvider        = new CallbackInstanceProvider();
     this.channelDispatcher       = new System.ServiceModel.Dispatcher.ChannelDispatcher(shared);
     this.instanceContextProvider = InstanceContextProviderBase.GetProviderForMode(InstanceContextMode.PerSession, this);
 }
Esempio n. 5
0
        internal InstanceBehavior(DispatchRuntime dispatch, ImmutableDispatchRuntime immutableRuntime)
        {
            this.useSession       = dispatch.ChannelDispatcher.Session;
            this.immutableRuntime = immutableRuntime;
            this.host             = (dispatch.ChannelDispatcher == null) ? null : dispatch.ChannelDispatcher.Host;
            this.initializers     = EmptyArray <IInstanceContextInitializer> .ToArray(dispatch.InstanceContextInitializers);

            this.provider  = dispatch.InstanceProvider;
            this.singleton = dispatch.SingletonInstanceContext;
            this.transactionAutoCompleteOnSessionClose       = dispatch.TransactionAutoCompleteOnSessionClose;
            this.releaseServiceInstanceOnTransactionComplete = dispatch.ReleaseServiceInstanceOnTransactionComplete;
            this.isSynchronized          = (dispatch.ConcurrencyMode != ConcurrencyMode.Multiple);
            this.instanceContextProvider = dispatch.InstanceContextProvider;

            if (this.provider == null)
            {
                ConstructorInfo constructor = null;
                if (dispatch.Type != null)
                {
                    constructor = InstanceBehavior.GetConstructor(dispatch.Type);
                }

                if (this.singleton == null)
                {
                    if (dispatch.Type != null && (dispatch.Type.IsAbstract || dispatch.Type.IsInterface))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxServiceTypeNotCreatable)));
                    }

                    if (constructor == null)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxNoDefaultConstructor)));
                    }
                }

                if (constructor != null)
                {
                    if (this.singleton == null || !this.singleton.IsWellKnown)
                    {
                        InvokerUtil            util    = new InvokerUtil();
                        CreateInstanceDelegate creator = util.GenerateCreateInstanceDelegate(dispatch.Type, constructor);
                        this.provider = new InstanceProvider(creator);
                    }
                }
            }

            if (this.singleton != null)
            {
                this.singleton.Behavior = this;
            }
        }
        internal InstanceBehavior(DispatchRuntime dispatch, ImmutableDispatchRuntime immutableRuntime)
        {
            this.useSession = dispatch.ChannelDispatcher.Session;
            this.immutableRuntime = immutableRuntime;
            this.host = (dispatch.ChannelDispatcher == null) ? null : dispatch.ChannelDispatcher.Host;
            this.initializers = EmptyArray<IInstanceContextInitializer>.ToArray(dispatch.InstanceContextInitializers);
            this.provider = dispatch.InstanceProvider;
            this.singleton = dispatch.SingletonInstanceContext;
            this.transactionAutoCompleteOnSessionClose = dispatch.TransactionAutoCompleteOnSessionClose;
            this.releaseServiceInstanceOnTransactionComplete = dispatch.ReleaseServiceInstanceOnTransactionComplete;
            this.isSynchronized = (dispatch.ConcurrencyMode != ConcurrencyMode.Multiple);
            this.instanceContextProvider = dispatch.InstanceContextProvider;

            if (this.provider == null)
            {
                ConstructorInfo constructor = null;
                if (dispatch.Type != null)
                {
                    constructor = InstanceBehavior.GetConstructor(dispatch.Type);
                }

                if (this.singleton == null)
                {
                    if (dispatch.Type != null && (dispatch.Type.IsAbstract || dispatch.Type.IsInterface))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxServiceTypeNotCreatable)));
                    }

                    if (constructor == null)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxNoDefaultConstructor)));
                    }
                }

                if (constructor != null)
                {
                    if (this.singleton == null || !this.singleton.IsWellKnown)
                    {
                        InvokerUtil util = new InvokerUtil();
                        CreateInstanceDelegate creator = util.GenerateCreateInstanceDelegate(dispatch.Type, constructor);
                        this.provider = new InstanceProvider(creator);
                    }
                }
            }

            if (this.singleton != null)
            {
                this.singleton.Behavior = this;
            }
        }
Esempio n. 7
0
        internal InstanceBehavior(DispatchRuntime dispatch, ImmutableDispatchRuntime immutableRuntime)
        {
            this.immutableRuntime = immutableRuntime;
            initializers          = EmptyArray <IInstanceContextInitializer> .ToArray(dispatch.InstanceContextInitializers);

            provider                = dispatch.InstanceProvider;
            singleton               = dispatch.SingletonInstanceContext;
            isSynchronized          = (dispatch.ConcurrencyMode != ConcurrencyMode.Multiple);
            instanceContextProvider = dispatch.InstanceContextProvider;

            if (provider == null)
            {
                ConstructorInfo constructor = null;
                if (dispatch.Type != null)
                {
                    constructor = InstanceBehavior.GetConstructor(dispatch.Type);
                }

                if (singleton == null)
                {
                    if (dispatch.Type != null && (dispatch.Type.GetTypeInfo().IsAbstract || dispatch.Type.GetTypeInfo().IsInterface))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxServiceTypeNotCreatable));
                    }

                    if (constructor == null)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxNoDefaultConstructor));
                    }
                }

                if (constructor != null)
                {
                    if (singleton == null || !singleton.IsWellKnown)
                    {
                        InvokerUtil            util    = new InvokerUtil();
                        CreateInstanceDelegate creator = util.GenerateCreateInstanceDelegate(dispatch.Type, constructor);
                        provider = new InstanceProvider(creator);
                    }
                }
            }

            if (singleton != null)
            {
                singleton.Behavior = this;
            }
        }
Esempio n. 8
0
        InstanceContext CreateInstanceContext(MessageProcessingContext mrc)
        {
            InstanceContext          iCtx            = null;
            DispatchRuntime          dispatchRuntime = mrc.OperationContext.EndpointDispatcher.DispatchRuntime;
            IInstanceContextProvider p = dispatchRuntime.InstanceContextProvider;

            if (p != null)
            {
                iCtx = p.GetExistingInstanceContext(mrc.IncomingMessage, mrc.OperationContext.Channel);
            }
            if (iCtx == null)
            {
                ServiceHostBase host = dispatchRuntime.ChannelDispatcher.Host;
                iCtx = new InstanceContext(dispatchRuntime.ChannelDispatcher.Host, null, false);
            }

            iCtx.InstanceManager = new InstanceManager(dispatchRuntime);
            return(iCtx);
        }
        private void TransferChannelFromPendingList(ref MessageRpc rpc)
        {
            if (rpc.Channel.IsPending)
            {
                rpc.Channel.IsPending = false;

                ChannelDispatcher        channelDispatcher = rpc.Channel.ChannelDispatcher;
                IInstanceContextProvider provider          = _instance.InstanceContextProvider;

                if (!InstanceContextProviderBase.IsProviderSessionful(provider) &&
                    !InstanceContextProviderBase.IsProviderSingleton(provider))
                {
                    IChannel proxy = rpc.Channel.Proxy as IChannel;
                    if (!rpc.InstanceContext.IncomingChannels.Contains(proxy))
                    {
                        channelDispatcher.Channels.Add(proxy);
                    }
                }

                channelDispatcher.PendingChannels.Remove(rpc.Channel.Binder.Channel);
            }
        }
        void TransferChannelFromPendingList(MessageRpc rpc)
        {
            if (rpc.Channel.IsPending)
            {
                rpc.Channel.IsPending = false;

                ChannelDispatcher        channelDispatcher = rpc.Channel.ChannelDispatcher;
                IInstanceContextProvider provider          = InstanceBehavior.InstanceContextProvider;

                if (!InstanceContextProviderBase.IsProviderSessionful(provider) &&
                    !InstanceContextProviderBase.IsProviderSingleton(provider))
                {
                    IChannel proxy = rpc.Channel.Proxy as IChannel;
                    if (!rpc.InstanceContext.IncomingChannels.Contains(proxy))
                    {
                        channelDispatcher.Channels.Add(proxy);
                    }
                }

                // TODO: Do we need to keep track of pending channels with the new hosting model?
                //channelDispatcher.PendingChannels.Remove(rpc.Channel.Binder.Channel);
            }
        }
 internal static bool IsProviderPerCall(IInstanceContextProvider provider)
 {
     return (provider is PerCallInstanceContextProvider);
 }
 internal static bool IsProviderSessionful(IInstanceContextProvider provider)
 {
     return (provider is PerSessionInstanceContextProvider);
 }
 internal static bool IsProviderPerCall(IInstanceContextProvider provider)
 {
     return(provider is PerCallInstanceContextProvider);
 }
 public MyInstanceContextProvider(IInstanceContextProvider inner)
 {
     this.inner = inner;
 }
 internal InstanceBehavior(DispatchRuntime dispatch, ImmutableDispatchRuntime immutableRuntime)
 {
     _provider = dispatch.InstanceProvider;
     _instanceContextProvider = dispatch.InstanceContextProvider;
 }
Esempio n. 16
0
 internal InstanceBehavior(DispatchRuntime dispatch, ImmutableDispatchRuntime immutableRuntime)
 {
     _provider = dispatch.InstanceProvider;
     _instanceContextProvider = dispatch.InstanceContextProvider;
 }
 internal static bool IsProviderSingleton(IInstanceContextProvider provider)
 {
     return(false);
 }
 internal static bool IsProviderSessionful(IInstanceContextProvider provider)
 {
     return(provider is PerSessionInstanceContextProvider);
 }
 internal static bool IsProviderSingleton(IInstanceContextProvider provider)
 {
     return (provider is SingletonInstanceContextProvider);
 }
Esempio n. 20
0
 public MyInstanceContextProvider(IInstanceContextProvider inner)
 {
     this.inner = inner;
 }
 internal static bool IsProviderSingleton(IInstanceContextProvider provider)
 {
     return false;
 }