Pregunta

Tengo un servicio de WCF auto-organizada con la InstanceContextMode establecido en PerSession.
¿Cómo puedo detectar nuevas conexiones de cliente (sesiones) a mi servicio de la aplicación host y utilizar ese nuevo contexto de sesión para observar mi servicio a través de sus eventos?

Algo así como:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
public class MyService : IMyService {
    public event EventHandler ClientRegistered;
    public event EventHandler FileUploaded;
}

y desde mi aplicación host para ser capaz de hacer:

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();
}
¿Fue útil?

Solución

Puede utilizar IsInitiating en el contrato de servicio

[OperationContract(IsInitiating = true)]
   void FirstMethod();

Vea el siguiente enlace:

http: / /social.msdn.microsoft.com/Forums/en-US/wcf/thread/8137553a-8657-475e-b9ca-5914d9c9d57a

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top