tags:

views:

120

answers:

2

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?

A: 

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.

Shiraz Bhaiji
A: 

Set you're timeout values and create a PingService() method that fires just before the timeout elapses, this will reset the Send and Receive timeouts.

if you want to catch the timeout simply attempt a callback, if the attempt takes longer than the binding SendTimeout value (default is 1 min i think), then you'll throw a time-out error and you can process the disconnect.

There's no way to gracefully catch a disconnected user (browser crashes, power goes out, etc., etc., etc.)

DavyMac23
bad answer - I already have that (ping per second etc.) - does not stop a client from going DEAD because of timeout on the network or power loss or something, and that is exactly what I want / need to catch (I.e. I need to know when the connection is dead / session is ended).THere is also no browser involved (why the heck does everyone think a web service is a stupid boring website?). THere is no client side involved here at all - my question is 100% server side. -1.
TomTom
You can try this: callbackClient.opContext.Channel.State.
DavyMac23

related questions