开发者

Best practices for storing information from login across multiple WCF calls

I'm looking for the best practices for storing information gotten during the the login process for WCF开发者_如何学JAVA and make it available to any subsequent service calls (that belong to the same session).

Basically I wrote my own login provider:

public class CustomAuthenticator : UserNamePasswordValidator
  {
    public override void Validate(string userName, string password)
    {
        if (username == "test" && password == "test")
        {
          int id_I_want_to_use = getUserID(username);
        }
    }
  }

And I have a service that needs to use the ID later on

public void someService(int itemID)
{
    getSomeInfo(id_I_want_to_use, itemID);
}

The problem I'm having is I haven't been able to find any good information on how to properly store this. I looked at instanceContext, but I was hoping to do all of this server side. I saw some information on using asp legacy support for using HTTP sessions to store data, but that wasn't really what I wanted. I'm trying to keep everything using current technologies, and I don't want to be tied to a http binding if I can help it.

I might be approaching this completely incorrectly, but that's basically why I'm asking.


The way to do this is to use the instance context, you just mark your contract with per session

 [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)] 
 class MyService : IMyContract {...}

This is all server side. The only thing that you need to do on the client is to keep the proxy open in order to keep the session alive.

For more details see: http://msdn.microsoft.com/en-us/magazine/cc163590.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜