使用WCF服务验证移动应用程序功能调用

时间:2014-05-15 08:34:59

标签: asp.net-mvc wcf wcf-security

我刚刚开始为我的移动应用创建WCF服务。目前我在Single Solution中有多个项目。

  • 主要网站项目
  • Edmx项目
  • WCF lib项目

验证功能

     public List<AuthenticateModel> Authenticate(string UserName, string Password)
            {
                SimpleMembershipInitializer _initialized = new SimpleMembershipInitializer();
                bool validate = System.Web.Security.Membership.ValidateUser(UserName, Password);
                AuthenticateModel model = new AuthenticateModel();
                if (validate)
                {
                    model.userID = IDUser
                }
                Return model;
            }

现在我怎么知道同一登录用户正在调用另一个函数。如果在这里以任何方式维护会话为网络?或者传递任何证书或令牌进行验证(如果是,如何传递令牌并实施它)?

    [OperationContract]
    [WebInvoke(UriTemplate = "GetAllrecords/?paramId={paramId}", Method = "GET", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
    List<SomeModel> GetAllrecords(int paramId)
    {
         Return something; // Return requested data
    }

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

如果你有时间,你应该阅读

http://www.codeproject.com/Articles/630986/Cross-Platform-Authentication-With-ASP-NET-Web-API

它专注于web api,但讨论了令牌的使用。

在我们的身份验证方法中,我们返回一个生成的令牌,该令牌持久存储在具有用户和角色的服务器上。

webclient(在我们的例子中使用angularjs构建)使用请求头中的令牌组成请求。然后,我们在web api中检查每个请求,提取令牌并将其与持久令牌进行比较。

有很多解决方案,我们不是很安全,但对我们来说已经足够了。