tags:

views:

26

answers:

1
+1  Q: 

WCF OnNewSession?

Im having a self-hosted WCF service in a WPF-app with a textbox for logging activity on the host.

First I used a Singleton-model, created my service-instance and attached a handler to a custom Message-event on my service-class so that activity on the service is logged to my textbox.

But now I need to use the PerSession-model so Im using the constructor with the Type-parameter instead. My question is how to get hold of any new sessions/service instances so that I can attach a handler to my Message-event in my service-class? Also I would like to list all active sessions on the host. How do I do any of this?

I found an example by Dan Rigsby (ObservableServiceHost) and I tried it out. But the problem Im having with this is that I cant get the service-instance in this event-handler beacuse the context is in a Opening-state and not Opened which seem to be required.

Any recommendations?

A: 

You might want to implement your own InstanceContext provider then. There is a sample on MSDN for that : http://msdn.microsoft.com/en-us/library/aa354514.aspx

Johann Blais
Thats what Dan Rigsby did in his example and there I cant get the service-instance because the context is in state Opening and not Opened. Maybee there is a work-around for that Ive missed.
Andreas Zita