是否可以使用以下代码获取客户端提供的用户名和密码:
myChannelFactory.Credentials.UserName.UserName = "username";
myChannelFactory.Credentials.UserName.Password = "password";
在服务器端代码中?特别是在这种方法中?:
public class MyAuthorizationManager : ServiceAuthorizationManager
{
protected override bool CheckAccessCore(OperationContext operationContext)
{
}
}
答案 0 :(得分:1)
编写一个派生自UserNamePasswordValidator的类,然后将其与WCF服务行为定义一起使用
在您的班级中覆盖“验证(字符串userName,字符串密码)”
然后是web(app).config:
<behaviors>
<serviceBehaviors>
<behavior name="ClearServiceBehaviour">
<serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="true" />
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="MyNamespace.MyCustomUserPassAuthenticator, MyAssembly" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>