2010-12-21 9 views
1

私は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がValidateメソッド、例えばを実行したことがないということです検証ロジックが実行されません

これは何が原因ですか?事前に感謝

答えて

0

は、セキュリティモード=「TransportWithMessageCredentialは」大丈夫です

<security mode="TransportWithMessageCredential"> 
    <transport clientCredentialType="Basic" proxyCredentialType="Basic" /> 
    <message clientCredentialType="UserName"/> 
</security> 
0

...これを読むためにあなたの[セキュリティ]セクションを変更してみてください。私たちのトランスポートclientCredentialType = "Basic" proxyCredentialType = "Basic" ...

トランスポートclientCredentialType = "Certificate" protectionLevel = "EncryptAndSign"は私のWindowsサービスでホストされているWCF..working fine..Itそのトリックは正しいセキュリティモードを選択することに実際にあるようだ。

関連する問題