如何在简单WCF发布订阅中使用身份验证。 [英] How do I use Authentication in simple WCF publish subscribe.

查看:74
本文介绍了如何在简单WCF发布订阅中使用身份验证。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用NetTCpBinding(会话模式)的发布 - 订阅WCF双工模型。当用户订阅时 - 我想通过NetworkCredential - 但我不能,因为它不会发送密码,而是我看到''(BLANK - Nada - 没有),但用户名当然是那里..当然(MS!aargh)。



我有一个简单的登录和授权我想这样做他们必须是存储在WCF服务主机专用数据库中的有效用户。 (不是Windows用户等..)我不打算明确发送此信息,但我确定喜欢漂亮的凭证对象 - 我应该只使用字符串用户名,字符串密码,字符串域并创建凭证,如果我需要以后再用我的用户名和密码数据将如何加密 - 我的NetTCpBinidng包含在这里,因为我不知道如何配置 - 主机和客户端可以在不同的机器上 - 也可以在不同的网络上。

任何对此的帮助都是赞赏的。谢谢。



I have a publish - subscribe WCF Duplex model using NetTCpBinding (session mode). When a user is subscribing - I would like to pass in NetworkCredential - but I can't as it will not send the password and instead I see a '' (BLANK - Nada - nothing), but the username of course is there.. of course (MS! aargh).

I have a Simple Login and Authorization I want to do so they must be a valid user stored in the WCF Service Hosts private Database. (NOT a windows user etc..) I am not intending to send this info in the clear but I sure like the nice Credential Object - should I just simply use string Username, string Password, string Domain and create the Credential if I need to use it later. How will my Username and Password Data be encrypted - my NetTCpBinidng is included here as I am not sure how to configure that - the Host and the Client can be on different machines - and also can be on different networks.
Any help with this is Appreciated. Thank you.

public void Subscribe(NetworkCredential credential)
{
    IGenericDataRepository<Users> repositorySingle = new GenericDataRepository<Users>(RepositoryConnection);
    Users UserList = repositorySingle.GetSingle(d => d.Name == credential.UserName && d.Password == credential.Password);
}

public NetTcpBinding SetNetTCPBinding()
{
    NetTcpBinding binding = new NetTcpBinding(SecurityMode.Transport);
    binding.Security.Mode = SecurityMode.Transport;
    binding.Security.Message.ClientCredentialType = MessageCredentialType.None;
    binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None;
    binding.Security.Transport.ProtectionLevel = ProtectionLevel.None;
}

推荐答案

由于我无法传递凭据,因此我使用了渠道工厂ClientCredential Users字段 - 我的intellisense显示它是{get; set;}所以我试着用它并立即得到一个例外,声明该字段是readonly(我说hogwash!)。所以我最终得到了这样的代码来设置它:



Since I could not pass in the Credential, I used the channel factory ClientCredential Users field - my intellisense showed it was {get; set;} so I tried to use it and immediately got an exception declaring the field was readonly (and I said hogwash!). So I ended up with code like this in order to set it:

ClientCredentials credentialBehaviour = NetPipeFactory.Endpoint.Behaviors.Find<ClientCredentials>();
credentialBehaviour.UserName.UserName = credentials.UserName;
credentialBehaviour.UserName.Password = credentials.Password;
// I found I could also do this..
credentialBehaviour.Windows.ClientCredential = Credential;


这篇关于如何在简单WCF发布订阅中使用身份验证。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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