WCF: how do I know when a session ends?

I have a WCF application that uses sessions.

Is there any central event that needs to be reset when the session ends? How can I find out when the session WITHOUT (!) The method call ends (the network is disconnected, the client crashes - therefore the call to the "logout" method is not performed)?

The server is hosted as:

[ServiceBehavior(
    InstanceContextMode = InstanceContextMode.PerSession,
    ConcurrencyMode = ConcurrencyMode.Reentrant,
    UseSynchronizationContext = false,
    IncludeExceptionDetailInFaults = true
)]

Mostly because it uses a callback interface.

Now I basically need to undo the instance created from the backend store when the session ends;)

Any ideas?

+5
source share
3 answers
[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
    }
}

Code will not work for Single / PerCall InstanceContextMode.

+8
source
+4

- PingService(), , reset .

-, , , SendTimeout ( - 1 , ), -, .

( , .. .. ..)

-1
source

All Articles