2
试图为wcf服务实施简单的“用户名”/“密码”身份验证。但它只是不工作。没有错误/例外。 这里是web配置代码:WCF自定义身份验证不起作用
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<customErrors mode="Off"/>
</system.web>
<system.serviceModel>
<services>
<service name="XYZService"
behaviorConfiguration="XYZBehavior">
<!-- use base address specified above, provide one endpoint -->
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="XYZBinding"
contract="IXYZService" />
<!--<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />-->
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="XYZBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="XYZBinding.LicensingServer.CCustomValidatorClass, XYZBinding.LicensingServer"/>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
验证码:
public class CCustomValidatorClass : UserNamePasswordValidator
{
public override void Validate(string userName, string password)
{
if(userName != "Test" || password != "1234567")
{
throw new FaultException("The provided credentials are invalid.");
}
}
}
有没有错误或异常。我可以调用服务并在没有任何凭据的情况下执行。在本地调试时,验证方法永远不会被命中。
我不知道什么是错过了。
我不是WCF的专家,但这些场景中的第一个问题总是:“你确定这个配置正在被使用?”。通过更改配置中的某些内容来检查该问题是否会中断应用程序,如果该应用程序仍然有效,则使用另一个配置:-) – TToni 2010-12-17 19:22:47
刚刚更新了'customUserNamePasswordValidatorType',并且wcf测试客户端抛出了错误。改回原来的。 WCF测试客户端运行顺利。 – 2010-12-17 19:27:55
你没有向我们展示你的配置中的重要和有趣的部分 -部分。你甚至有服务,实际上使用这些绑定配置和这些安全设置?从目前为止发布的内容来看,它看起来并不是那样的...... –
2010-12-17 21:31:56