2010-12-19 142 views
1

WCF服務WebConfig(部分)。WCF自定義身份驗證 - HTTP狀態401:未授權

<services> 
      <service name="Bricks99.LicensingServer.LicensingService" 
        behaviorConfiguration="Bricks99ServiceBehavior">   
      <!-- use base address specified above, provide one endpoint --> 
      <endpoint address="" 
         binding="basicHttpBinding" 
         bindingConfiguration="Bricks99Binding" 
         contract="Bricks99.LicensingServer.ILicensingService" /> 
      <!--<endpoint address="mex" 
         binding="mexHttpBinding" 
         contract="IMetadataExchange" />--> 
      </service> 
    </services> 
    <basicHttpBinding> 
      <binding name="Bricks99Binding"> 
       <security mode="TransportCredentialOnly"> 
       <transport clientCredentialType="Basic" /> 
       </security> 
      </binding> 
    </basicHttpBinding> 
<serviceCredentials> 
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Bricks99.LicensingServer.CCustomValidatorClass, Bricks99.LicensingServer"/> 
</serviceCredentials> 

客戶端是ASP.NET 2.0

LicensingService service = new LicensingService(); 
      //Authentication    
CredentialCache credCache = new CredentialCache(); 
      credCache.Add(new Uri(service.Url), "Basic", new NetworkCredential("Test", "1234567")); 
service.Credentials = credCache; 
service.PreAuthenticate = true; 
service.UseDefaultCredentials = false; 
result = service.VerifyLicenseKey(licenseKey, string.Empty); 

結果總是請求,HTTP狀態401失敗:未經授權。我也關閉了文件夾上的匿名訪問。它仍然沒有工作。 關於如何正確設置憑據的任何想法?

編輯:好像重寫的方法

public override void Validate(string userName, string password) 
     { 
      try 
      { 
       if(userName != "Test" || password != "1234567") 
       { 
        throw new FaultException("The provided credentials are invalid."); 
       } 
      } 
      catch(FaultException ex) 
      { 
       LicensingData.Operations.LogError(ex);     
      } 
     } 

是從來沒有擊中。

回答

1

經過數小時的研究後,我發現託管服務提供商默認情況下不允許基本身份驗證。要使自定義身份驗證正常工作,有必要在IIS中啓用基本身份驗證。

相關問題