希望你们大家可以为我澄清一些。我有一个使用Sql Membership Provider的Web应用程序,它通过WCF服务与第二个Web应用程序通信。这两个应用程序共享相同的Sql成员资格提供程序数据存储...但我需要每个WCF服务调用来认证用户。使用SQL成员资格提供程序的WCF身份验证
现在,我已经看了很多样本,但我觉得我看到的样本要么遗漏了某些代码,因为它“应该”对我很明显,或者我不明白WCF如何处理请求(请参阅下面的预期代码)。
我感谢任何帮助......
这里是我已经知道该怎么做
- 我知道如何在两端配置SQL成员资格。
- 我知道的wsHttpBinding
- 如何设置我知道如何安装在运输安全
这里使用的服务的证书是我很困惑ON
- 如何通过会员密码(...您不能)
- 我是否通过身份验证Cookie?如果是这样,怎么样?
- 我是否创建与用户(他们自己)无关的“已知”用户名和密码?
Web客户端我希望看到CODE像这样
protected void btnLogin_Click(object sender, EventArgs e)
{
// Logging into the web-application is known and easy.
if (Membership.ValidateUser("MyUserName", "MyPassword"))
{
FormsAuthentication.SetAuthCookie("MyUserName", true);
FormsAuthentication.RedirectFromLoginPage("MyUserName", false);
}
}
protected ServiceReference1.Contractor getContractor(Int32 key)
{
// I expect something "like" this on the client call.
MembershipUser user = Membership.GetUser("MyUserName");
ServiceReference1.FishDataClient wcfService = new ServiceReference1.FishDataClient();
// You can't retreive the users password directly,
// nor can you get the hash from the SqlMembershipProvider.
wcfService.ChannelFactory.Credentials.UserName.UserName = user.UserName;
// So doing something like this would not be possible.
wcfService.ChannelFactory.Credentials.UserName.Password = "??????";
// So how is the web service going to authenticate the user from it's
// references to the same SqlMembershipProvider (database).
ServiceReference1.Contractor contractor = wcfService.GetContractor(key);
wcfService.Close();
wcfService = null;
return contractor;
}
在WCF服务我希望看到CODE像这样
[PrincipalPermission(SecurityAction.Demand, Role = "User")]
public Contractor GetContractor(Int32 key)
{
ServiceSecurityContext context = ServiceSecurityContext.Current;
Contractor contractor = new Contractor();
// What goes here? I would expect something like this...
if (Membership.ValidateUser("???????", "???????"))
contractor.Get(key);
return contractor;
}
你好,我在这里回答类似的问题:http://stackoverflow.com/questions/3460435/asp-net-to-wcf-passthrough-security – 2010-08-11 20:50:45