views:

69

answers:

1

if an administrator logs on to my service, he may wish to disconnect sessions which meet (or don't meet) certain requirements, be it automated or manual. throwing exceptions seems like a simple and effective solution, as all resources are released.

i could use a local bool field which, if true, would disconnect this user the next time he calls any of the methods, but that doesn't seem like an elegant solution.

and, it doesn't have to be throwing exception, as i've already noticed you can use OperationContext.Current.Channel.Close(), or abort, to disable access to that session.

is there a "standard" way to do this in wcf?

+1  A: 

From within a given 'session', I do not think there is an out-of-the-box way to do anything with another session (i.e. instance context).

You can however track clients that connect to your service by utilizing the IChannelInitializer interface in conjunction with a service or contract behavior. This would give you access to each clients' associated channel which you could then close if you wanted to, although this would not necessarily produce a very informative fault on the client end as it would look like a communication issue.

Another option is to look at callbacks if you have control over the clients that are accessing the service. By utilizing the above mentioned client tracking in conjunction with callbacks you can actually cause the client to more gracefully close its own channel and potentially inform the user of what happened.

MattK
yes, forgot about that one, thanks :D -- to explain the solution a bit more, i just added: SessionMode=SessionMode.Required on the service, and [OperationContract(IsTerminating=true)] on the callback disconnect method.
avance70