【发布时间】:2010-11-08 17:27:37
【问题描述】:
我正在(拼命地)尝试让客户身份验证提供商为我的 WCF 服务工作。到目前为止,我有以下代码;
web.config
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="MyNamespace.CustomUserNameValidator, MyNamespace" />
</serviceCredentials>
<wsHttpBinding>
<binding name="wsHttpBindingConfig" >
<security mode="Message">
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
自定义身份验证器类;
public class CustomUserNameValidator : UserNamePasswordValidator
{
public override void Validate(string userName, string password)
{
// have security details been provided?
if (null == userName || null == password)
{
throw new ArgumentNullException();
}
// authenticate user
if (!(userName == "test" && password == "test"))
{
// This throws an informative fault to the client.
throw new FaultException("SecurityFailed");
}
}
}
一切编译正常,但是当我使用 Visual Studio 中的 WCF 测试客户端调用称为 Ping 的方法(如下)时,自定义身份验证器永远不会被使用。 Ping 方法和我在 CustomUserNameValidator 类中的任何断点都会执行。
为什么会这样?感谢所有帮助。
【问题讨论】:
标签: .net wcf wcf-security wshttpbinding