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); } }
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); }
public InstanceContext GetExistingInstanceContext(Message message, IContextChannel channel) { //No OperationContext here! try { m_InstanceAccess.WaitOne(); //Remove the instance id context if it exists. Treat each message as an activation request so that we can reassign the InstanceId on the service-side. bool found = RemoveInstanceIdFromMessage(message); ActorId actorId = ActorIdHelper.Get(message.Headers); Guid instanceId = ActorManager.GetInstance(actorId); ActorManager.UpdateIdleTime(actorId); if ((instanceId.Equals(Guid.Empty)) && (message.Headers.Action.Contains("Activate") == false)) { //Message received after actor instance completed. Can only occur when a client improperly caches an ActorProxy after completing the instance. //Clear context and reset InstanceId so that InitializeInstanceContext can handle the message as an initiating request. message.Properties.Remove(ContextMessageProperty.Name); } else if (instanceId.Equals(Guid.Empty) == false) { //Always use the managed InstanceId. It may differ from the InstanceId in the ActorId context after an Actor completion. SetInstanceIdInMessage(message, instanceId.ToString()); } InstanceContext context = m_PreviousProvider.GetExistingInstanceContext(message, channel); if (context != null) { m_InstanceAccess.ReleaseMutex(); } return(context); } catch (Exception exception) { m_InstanceAccess.ReleaseMutex(); throw exception; } }