2011-03-23 85 views
1

我试图用https和用户名&密码来保护WCF服务。我正在使用TransportWithMessageCredentials安全模式和wsHttpBinding。 现在我在与定制UserNamePasswordValidator麻烦,当我比较喜欢这个WCF服务与自定义用户名密码验证问题

if (userName == "user" && password == "pass") 
    return; 

一切硬编码值工作正常,但是当我试图从数据库中我收到错误消息

从其他 方收到一个不安全或不正确安全的 错误。见内的FaultException 的故障代码和详细

这里是我的web.config部分,

<bindings> 
      <wsHttpBinding> 
       <binding name="TestAuthConf" maxReceivedMessageSize="65536"> 
        <security mode="TransportWithMessageCredential"> 
         <message clientCredentialType="UserName"/> 
        </security> 
        <readerQuotas maxArrayLength="65536" maxBytesPerRead="65536" maxStringContentLength="65536"/> 
       </binding> 
      </wsHttpBinding> 
     </bindings> 
     <services> 
      <service behaviorConfiguration="TestAuthWCFService.TestAuthBehavior" name="TestAuthLibrary.App_Code.TestAuth"> 
       <endpoint address="" binding="wsHttpBinding" bindingConfiguration="TestAuthConf" contract="TestAuthLibrary.App_Code.ITestAuth"> 
        <identity> 
         <dns value="localhost" /> 
        </identity> 
       </endpoint> 
       <endpoint address="mex" binding="mexHttpsBinding" contract="TestAuthLibrary.App_Code.ITestAuth"/> 
      </service> 
     </services> 
     <behaviors> 
      <serviceBehaviors> 
       <behavior name="TestAuthWCFService.TestAuthBehavior"> 
        <serviceMetadata httpsGetEnabled="true"/> 
        <serviceDebug includeExceptionDetailInFaults="true"/> 
        <serviceCredentials> 
         <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="App_Code.CustomUserNameValidator, App_Code.CustomUserNameValidator"/> 
        </serviceCredentials> 
       </behavior> 
      </serviceBehaviors> 
     </behaviors> 

我使用IIS7,自我生成数字证书,我设置了SSL接受客户端证书...

任何帮助将appriciated ...

+0

可能在您的代码访问数据库中存在异常。例如,可能没有足够的权限来从数据库读取数据。什么是内部例外?打开服务上的WCF跟踪:http://msdn.microsoft.com/en-us/library/ms733025.aspx – 2011-03-23 14:15:49

+0

内部例外:“验证邮件的安全性时发生错误”,我没有检查权限,一切正常,WCF跟踪打开了,我测试了访问数据库的方法,没有问题... – 2011-03-23 14:37:06

回答

1

好消息:如果你的自定义用户名/密码验证执行时,证书已通过验证,所以消除了很多可能性。

听起来像是有一个从WCF的线程上下文访问数据库的bug。在你的验证器中设置一个断点并逐步完成。

+0

omg ...跟踪内部异常:登录失败的用户...我应该只是添加一个用户... :)感谢您的帮助John&Ladislav ...最好的问候... – 2011-03-24 09:19:01

相关问题