0

I want a duplex service, and I want to know if a client has entered correctly her user name and password, because I only want to let to use the methods of the service if the user previously send her user name and her password correctly.

For the duplex, for this post, I know that I can use a duplex service per call, using an static list for store the callback between calls. But I have doubts how to do the user control with the per call method.

I am thinking in this cases:

1.- A user call method login() and send the user name and the password. In this case is correct.

2.- The user now can call the rest of methods of the service. For example method1(). Here I have a question. How it is per call, it is created a new instance in each method call, but, from the same client, each callback has a different code or is the same? If is the same, when the client has a different callback, when it restarts the application?

If the callback is different in every call, how can I know if the client previously has send her user name and password? I need to send the log and password as method parameter?

If the callback is the same, is it possible to know when the client close the connection to delete the callback from my static list? Perhaps this would be connection control?

Thanks.

EDIT: I have done some probes and I see that the callback, the ID of the client, is the same for each call to the methods, so it's possible to create a class where save the information that is needed, such the username, if this user has entered the login and the password in this callback... etc.

Community
  • 1
  • 1
Álvaro García
  • 18,114
  • 30
  • 102
  • 193

1 Answers1

0

If you use PerCall, you can still have SessionMode = SessionMode.Required. Then you can simply decorate your login method operation contract attribute with IsInitiating = true wich tells wcf that the operation starts a session. All other operations should be set to IsInitiating = false. If the client calls a method that does not start a session before calling login an exception will be thrown.

I.e

 [ServiceContract(Namespace = "Services", SessionMode = SessionMode.Required, CallbackContract =          typeof(SVIMyCallback))]

 [OperationContract(Name = "login", IsInitiating = true)]
 [OperationContract(Name = "doSomething", IsInitiating = false)]
keft
  • 266
  • 1
  • 8