WCF: How to detect new connections to WCF PerSession services ?
Posted
by Christian Toma
on Stack Overflow
See other posts from Stack Overflow
or by Christian Toma
Published on 2010-03-14T11:37:08Z
Indexed on
2010/03/14
11:45 UTC
Read the original article
Hit count: 507
I have a self-hosted WCF service with the InstanceContextMode set to PerSession.
How can I detect new client connections (sessions) to my service from the host application and use that new session context to observe my service trough its events?
Something like:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
public class MyService : IMyService {
public event EventHandler ClientRegistered;
public event EventHandler FileUploaded;
}
and from my host application to be able to do:
ServiceHost svc = new ServiceHost(typeof(MyService));
svc.Open();
// something like:
svc.NewSession += new EventHandler(...)
//...
public void SessionHandler(InstanceContext SessionContext) {
MySessionHandler NewSessionHandler = new MySessionHandler(SessionContext);
// From MySessionHandler I handle the service's events (FileUploaded, ClientRegistered)
// for this session and notify the UI of any changes.
NewSessionHandler.Handle();
}
© Stack Overflow or respective owner