如何确定用户在WCF服务中已通过身份验证 [英] How to determine user is authenticated in WCF service

查看:86
本文介绍了如何确定用户在WCF服务中已通过身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我是wcf的新手,所以一个问题困扰着我,例如wcf和用户身份验证.通常在asp.net中,我发送用户名和密码,并在服务器端根据数据库对它进行验证,如果用户有效,则我在会话和每个页面中存储一些数据, 检查会话,如果会话存在并且在该会话中为该用户存储了true,则我让页面执行,否则我将用户重定向到登录页面.所以我想知道如何在wcf中实现这种用户身份验证.我想第一次 用户将调用我的服务的任何方法,那么他将通过凭据,如果凭据合适,则可以调用我的服务的任何方法.请指导我如何在wcf中做到这一点.在wcf中,我如何为将呼叫我的服务的每个用户在会话中存储任何数据.... is 有什么办法吗?

我搜索了google,发现了一个类似于http://blog.adnanmasood.com/2010/04/29/step-by-step-guide-for-authenticating-wcf-service-with-username-and-password-over-ssl的邮件/

但是在这里,任何人都会注意到呼叫者通过用户名&密码,但代码看起来像是用户名,而密码却两次出现,就像

私有静态void Main(string [] args)
  {
    ServicePointManager.ServerCertificateValidationCallback =新的RemoteCertificateValidationCallback(
       委托{return true; });

    var client = new WcfServiceClient();
    GetCredentials();
    client.ClientCredentials.UserName.UserName =用户名;
    client.ClientCredentials.UserName.Password =密码;
    Console.Write(client.GetData(1));
    client.Close();
    Console.Read();
 }

...但是为什么会有两个用户名和密码UserName.UserName看起来很丑陋.给我最好的主意,当他们第一次调用我的服务时,如何对用户进行身份验证,一旦通过身份验证,然后从下一次他可以调用我的任何方法 服务而不提供凭据.

有人告诉我开发用于身份验证用户的服务.用户身份验证后,服务将为每个wcf客户端提供一些唯一的令牌ID,并且在调用任何方法时客户端都会将该令牌作为消息头传递......我不知道该怎么做实施它 甚至我都不知道那是不是最好.因此寻求指导和建议.谢谢.



i am new in wcf so one question bugging me like wcf and user authentication. generally in asp.net i send user name and password and at the server end it is validated against database and if user is valid then i store some data in session and in every page i check the session and if the session exist and true is stored for that user in that session then i let the page execute otherwise i redirect user to login page. so i want to know how to implement this kind of user authentication in wcf. i want when first time user will call any method of my service then he will pass credential and if credential is fine then he can call any method of my service. please guide me how could i do it in wcf. in wcf how i can store any data in session for each user who will call my service....is there any way??

i search google and found one like http://blog.adnanmasood.com/2010/04/29/step-by-step-guide-for-authenticating-wcf-service-with-username-and-password-over-ssl/

but here anyone notice caller pass user name & password but code look like user name and password comes twice like

private static void Main(string[] args)
 {
    ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(
         delegate { return true; });

     var client = new WcfServiceClient();
     GetCredentials();
     client.ClientCredentials.UserName.UserName = username;
     client.ClientCredentials.UserName.Password = password;
     Console.Write(client.GetData(1));
     client.Close();
     Console.Read();
 }

...but why two user name and password is coming UserName.UserName it looks very ugly. give me the best idea how to authenticate users against DB when they first time call my service and once authenticated then from the next time he can call any method of my service without giving credentials.

some one told me to develop service for authenticate user.once user authenticate then service will provide some unique token id to each wcf client and client will pass that token as message header when call any method......i have no idea how to implement it and even i do not know would it be best or not. so looking for guidance and suggestion. thanks

推荐答案

.但是为什么会有两个用户名和密码UserName.UserName看起来很丑.
proxy.ClientCredentials.UserName.UserName =用户名;
proxy.ClientCredentials.UserName.Password =密码;

这用于在代理服务器上设置用户的凭据(用户名和密码).它将用户名和密码与您在数据库中创建的用户进行比较.如果数据库中存在用户名& password,则可以访问该服务.
有关如何的MSDN文档: 使用用户名和密码进行身份验证
".but why two user name and password is coming UserName.UserName it looks very ugly."

proxy.ClientCredentials.UserName.UserName = username;
proxy.ClientCredentials.UserName.Password = password;

This used to set the user's credentials on the proxy(username&password). It will compare the username and password with users you have created in the database. If the username &password is exists in database, it can access the service.
MSDN document for How to: Authenticate with a User Name and Password


这篇关于如何确定用户在WCF服务中已通过身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆