2011-08-20 67 views
1

我已經開發了REST WCF並設置在web.config中問題在REST WCF認證

<bindings> 
    <webHttpBinding> 
    <binding name="secureBasic"> 
     <security mode="TransportCredentialOnly"> 
     <transport clientCredentialType="None" /> 
     </security> 
    </binding> 
    </webHttpBinding> 
</bindings> 

<serviceBehaviors> 
    <behavior name="ServiceBehaviour" > 
     <serviceCredentials> 
     <userNameAuthentication customUserNamePasswordValidatorType="RestService.CustomUsernamePasswordValidator, RestService" 
          userNamePasswordValidationMode="Custom" /> 
     </serviceCredentials> 
     <serviceMetadata httpGetEnabled="true" /> 
     <serviceDebug includeExceptionDetailInFaults="false" /> 
    </behavior> 

    </serviceBehaviors> 

而且在CustomUsernamePasswordValidator.cs文件我有以下方式

namespace RestService 
{ 
public class CustomUsernamePasswordValidator : UserNamePasswordValidator 
{ 
    public override void Validate(string userName, string password) 
    { 
     if (!AuthenticateUser(userName, password)) 
      throw new SecurityTokenValidationException("Invalid Username or Password"); 
    } 

    private bool AuthenticateUser(string userName, string password) 
    { 
     if (userName == "myaddon" && password == "mypassword") 
     { 
      return true; 
     } 
     else 
      return false; 
    } 
} 
} 

驗證用戶綁定以下方式現在的問題是,它運行的很好,當我將從同一個項目使用此服務,但困惑,爲什麼這個調用不會發生驗證?

另外,當我測試從ruby commnad預測我的heroku清單插件文件它會給我錯誤 失敗的身份驗證!我認爲這是我的REST WCF應用程序的問題。

請任何人都可以幫我解決這個問題,如果任何人都非常瞭解WCF和認證。

感謝 阿倫。

+0

你得到任何錯誤訊息?在這裏張貼後,您或許應該更改您的密碼:) –

+0

驗證失敗Ruby的命令提示符..感謝您的建議。 –

+0

請讓你的問題的標題更多的信息:http://meta.stackexchange.com/questions/10647/writing-good-titles/10648#10648 –

回答

0

最後我一直在使用WebOperationContext直接處理自定義驗證和跳過web.config設置。