| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using CoreWCF.Channels; |
| | | 6 | | using CoreWCF.Runtime; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF.Dispatcher |
| | | 9 | | { |
| | | 10 | | internal class PerSessionInstanceContextProvider : InstanceContextProviderBase |
| | | 11 | | { |
| | | 12 | | internal PerSessionInstanceContextProvider(DispatchRuntime dispatchRuntime) |
| | 526 | 13 | | : base(dispatchRuntime) |
| | | 14 | | { |
| | 526 | 15 | | } |
| | | 16 | | |
| | | 17 | | public override InstanceContext GetExistingInstanceContext(Message message, IContextChannel channel) |
| | | 18 | | { |
| | | 19 | | // Here is the flow for a Sessionful channel |
| | | 20 | | // 1. First request comes in on new channel. |
| | | 21 | | // 2. ServiceChannel.InstanceContext is returned which is null. |
| | | 22 | | // 3. InstanceBehavior.EnsureInstanceContext will create a new InstanceContext. |
| | | 23 | | // 4. this.InitializeInstanceContext is called with the newly created InstanceContext and the channel. |
| | | 24 | | // 5. If the channel is sessionful then its bound to the InstanceContext. |
| | | 25 | | // 6. Bind channel to the InstanceContext. |
| | | 26 | | // 7. For all further requests on the same channel, we will return ServiceChannel.InstanceContext which wil |
| | 2293 | 27 | | ServiceChannel serviceChannel = GetServiceChannelFromProxy(channel); |
| | | 28 | | Fx.Assert((serviceChannel != null), "CoreWCF.Dispatcher.PerSessionInstanceContextProvider.GetExistingInstanc |
| | 2293 | 29 | | return serviceChannel?.InstanceContext; |
| | | 30 | | } |
| | | 31 | | |
| | | 32 | | public override void InitializeInstanceContext(InstanceContext instanceContext, Message message, IContextChannel |
| | | 33 | | { |
| | 2274 | 34 | | ServiceChannel serviceChannel = GetServiceChannelFromProxy(channel); |
| | 2274 | 35 | | if (serviceChannel != null && serviceChannel.HasSession) |
| | | 36 | | { |
| | 36 | 37 | | instanceContext.BindIncomingChannel(serviceChannel); |
| | | 38 | | } |
| | 2274 | 39 | | } |
| | | 40 | | |
| | | 41 | | |
| | | 42 | | public override bool IsIdle(InstanceContext instanceContext) |
| | | 43 | | { |
| | | 44 | | //By default return true |
| | 0 | 45 | | return true; |
| | | 46 | | } |
| | | 47 | | |
| | | 48 | | public override void NotifyIdle(Action<InstanceContext> callback, InstanceContext instanceContext) |
| | | 49 | | { |
| | | 50 | | //no-op |
| | 0 | 51 | | } |
| | | 52 | | } |
| | | 53 | | } |