我有一個wcf服務和客戶端,並希望通過檢查用戶名和密碼來提供額外的保護。我具有以下validatir類wcf中的自定義用戶名驗證
public class UserCredentialsValidator : UserNamePasswordValidator
{
public override void Validate(string userName, string password)
{
if (!string.Equals(userName, Config.Login, StringComparison.InvariantCultureIgnoreCase)
&& !String.Equals(password, Config.Password))
{
throw new FaultException("Invalid user credentials. Access denied.");
}
}
}
和以下服務器配置
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceDebug includeExceptionDetailInFaults="true"/> <serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="FileStorage.Core.ServiceModel.UserCredentialsValidator, FileStorage.Core"/>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="FileStorage.Core.ServiceModel.FileStorageService" behaviorConfiguration="serviceBehavior">
<endpoint address="" contract="FileStorage.IFileStorage" binding="wsHttpBinding" bindingConfiguration="bindingConfig"/>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="bindingConfig" maxBufferPoolSize="104857600" maxReceivedMessageSize="104857600" openTimeout="00:10:00"
closeTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00">
<readerQuotas maxDepth="32" maxStringContentLength="104857600" maxArrayLength="104857600"
maxBytesPerRead="104857600" maxNameTableCharCount="1024"/> <security mode="Message">
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
</bindings>
問題是,CustomValidatir從未執行驗證方法,例如驗證邏輯不執行
什麼會導致這種情況?在此先感謝