Reputation: 19396
I have a service that required a session. The reason of that is that the client starts a session, the service query to the database if the username and password is correct and if it is correct, then the service allow to use the service to this session.
I have read that the proxy would be closed after the method call has finished, to release the resources, but I have a doubt. If I close the proxy when the method is finished, the session is closed too, so when I will call another method, I have to query to the database again to check if the credentials are correct before allow to consume the service.
So, wouldn't it be better to keep open the session while the application in the client is open and close the proxy when the client close the application? In this way I keep the connection alive, and the session, but I don't have to get the credentials from the database each time a method is called.
Perhaps I am wrong in the way that I check the credentials to allow or not to the session to use the service.
Thanks.
Upvotes: 1
Views: 35
Reputation: 3448
If your intent is to authenticate user you cane leverage of following option:
Set client's credential to UserName. In this case, before any call gets executed client's username and password are validated against data stored in database. You define custom class deriving from UsernamePasswordValidator where you query DB so as to find out whether caller is allowed to use service. I refer you to this post.
I have readed that the proxy would be closed after the method call has finished
Not proxy but instance would be destroyed and responsible for that is ReleaseInstanceMode property of OperationBehavior. You would not benefit of such a solution since destroying instance does not deprive user of accessing service. Another instance could be created instead. Of course ReleaseInstanceMode applies to situation when InstanceContextMode is set to PerSession.
Upvotes: 3