I have a WCF application that is using sessions.
Is there any central event to get thrown when a session ends? How can I find out when a session is ending WITHOUT (!) calling a method (network disconnect, client crashing - so no "logout" method call)?
The server is hosted as:
[ServiceBehavior(
InstanceContextMode = InstanceContextMode.PerSession,
ConcurrencyMode = ConcurrencyMode.Reentrant,
UseSynchronizationContext = false,
IncludeExceptionDetailInFaults = true
)]
Basically because it is using a callback interface.
Now, I basically need to decoubple the instance created from the backend store when the session terminates ;)
Any ideas?
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
class MyService : IService
{
public MyService()
{
// Session opened here
OperationContext.Current.InstanceContext.Closed += InstanceContext_Closed;
// get the callback instance here if needed
// OperationContext.Current.GetCallbackChannel<IServiceCallback>()
}
private void InstanceContext_Closed(object sender, EventArgs e)
{
// Session closed here
}
}
The code won't work for Single/PerCall InstanceContextMode.
There is a good description of instance context here
Instance context derives from CommunicationObject
Communication object has a closing event.
I have not done this myself, but in theory it should be possible to use this event to decouple from the backend store when the session closes, by hooking into this event.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With