added samples
[windows-sources.git] / sdk / samples / WCFSamples / TechnologySamples / Extensibility / Instancing / Durable / CS / extensions / DurableInstanceContextRequestSessionChannel.cs
blobcb2c3577edadd24438631eb2f39efb02683b042a
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.ServiceModel;
5 using System.ServiceModel.Channels;
7 namespace Microsoft.ServiceModel.Samples
9 class DurableInstanceContextRequestSessionChannel : DurableInstanceContextChannelBase,
10 IRequestSessionChannel
12 IRequestSessionChannel innerRequestSessionChannel;
14 // Indicates whether the current message is the first
15 // message in a session or not.
16 bool isFirstMessage;
18 // Lock should be acquired on this object before changing the
19 // state of this channel.
20 object stateLock;
22 public DurableInstanceContextRequestSessionChannel(ChannelManagerBase channelManager,
23 ContextType contextType,
24 IRequestSessionChannel innerChannel,
25 string contextStoreLocation)
26 : base(channelManager, innerChannel)
28 this.contextType = contextType;
29 this.innerRequestSessionChannel = innerChannel;
30 this.contextStoreLocation = contextStoreLocation;
31 this.endpointAddress = innerChannel.RemoteAddress;
32 this.stateLock = new object();
33 this.isFirstMessage = true;
36 public IOutputSession Session
38 get
40 return innerRequestSessionChannel.Session;
44 public IAsyncResult BeginRequest(Message message, TimeSpan timeout,
45 AsyncCallback callback, object state)
47 lock (stateLock)
49 // Apply the context if the message is the first message.
50 if (isFirstMessage)
52 ApplyContext(message);
53 isFirstMessage = false;
57 return innerRequestSessionChannel.BeginRequest(message, timeout,
58 callback, state);
61 public IAsyncResult BeginRequest(Message message,
62 AsyncCallback callback, object state)
64 return BeginRequest(message, DefaultSendTimeout, callback, state);
67 public Message EndRequest(IAsyncResult result)
69 return innerRequestSessionChannel.EndRequest(result);
72 public EndpointAddress RemoteAddress
74 get
76 return innerRequestSessionChannel.RemoteAddress;
80 public Message Request(Message message, TimeSpan timeout)
82 lock (stateLock)
84 // Apply the context if the message is the first message.
85 if (isFirstMessage)
87 ApplyContext(message);
88 isFirstMessage = false;
92 return innerRequestSessionChannel.Request(message, timeout);
95 public Message Request(Message message)
97 return Request(message, DefaultSendTimeout);
100 public Uri Via
102 get
104 return innerRequestSessionChannel.Via;