PerSessionInstanceContextProvider.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //-----------------------------------------------------------------------------
  4. namespace System.ServiceModel.Dispatcher
  5. {
  6. using System.Runtime;
  7. using System.ServiceModel;
  8. using System.ServiceModel.Channels;
  9. class PerSessionInstanceContextProvider : InstanceContextProviderBase
  10. {
  11. internal PerSessionInstanceContextProvider(DispatchRuntime dispatchRuntime)
  12. : base(dispatchRuntime)
  13. {
  14. }
  15. public override InstanceContext GetExistingInstanceContext(Message message, IContextChannel channel)
  16. {
  17. // Here is the flow for a Sessionful channel
  18. // 1. First request comes in on new channel.
  19. // 2. ServiceChannel.InstanceContext is returned which is null.
  20. // 3. InstanceBehavior.EnsureInstanceContext will create a new InstanceContext.
  21. // 4. this.InitializeInstanceContext is called with the newly created InstanceContext and the channel.
  22. // 5. If the channel is sessionful then its bound to the InstanceContext.
  23. // 6. Bind channel to the InstanceContext.
  24. // 7. For all further requests on the same channel, we will return ServiceChannel.InstanceContext which will be non null.
  25. ServiceChannel serviceChannel = this.GetServiceChannelFromProxy(channel);
  26. Fx.Assert((serviceChannel != null), "System.ServiceModel.Dispatcher.PerSessionInstanceContextProvider.GetExistingInstanceContext(), serviceChannel != null");
  27. return (serviceChannel != null) ? serviceChannel.InstanceContext : null;
  28. }
  29. public override void InitializeInstanceContext(InstanceContext instanceContext, Message message, IContextChannel channel)
  30. {
  31. ServiceChannel serviceChannel = GetServiceChannelFromProxy(channel);
  32. if (serviceChannel != null && serviceChannel.HasSession)
  33. {
  34. instanceContext.BindIncomingChannel(serviceChannel);
  35. }
  36. }
  37. public override bool IsIdle(InstanceContext instanceContext)
  38. {
  39. //By default return true
  40. return true;
  41. }
  42. public override void NotifyIdle(InstanceContextIdleCallback callback, InstanceContext instanceContext)
  43. {
  44. //no-op
  45. }
  46. }
  47. }