2
試圖爲wcf服務實施簡單的「用戶名」/「密碼」身份驗證。但它只是不工作。沒有錯誤/例外。 這裏是web配置代碼:WCF自定義身份驗證不起作用
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<customErrors mode="Off"/>
</system.web>
<system.serviceModel>
<services>
<service name="XYZService"
behaviorConfiguration="XYZBehavior">
<!-- use base address specified above, provide one endpoint -->
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="XYZBinding"
contract="IXYZService" />
<!--<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />-->
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="XYZBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="XYZBinding.LicensingServer.CCustomValidatorClass, XYZBinding.LicensingServer"/>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
驗證碼:
public class CCustomValidatorClass : UserNamePasswordValidator
{
public override void Validate(string userName, string password)
{
if(userName != "Test" || password != "1234567")
{
throw new FaultException("The provided credentials are invalid.");
}
}
}
有沒有錯誤或異常。我可以調用服務並在沒有任何憑據的情況下執行。在本地調試時,驗證方法永遠不會被命中。
我不知道什麼是錯過了。
我不是WCF的專家,但這些場景中的第一個問題總是:「你確定這個配置正在被使用?」。通過更改配置中的某些內容來檢查該問題是否會中斷應用程序,如果該應用程序仍然有效,則使用另一個配置:-) – TToni 2010-12-17 19:22:47
剛剛更新了'customUserNamePasswordValidatorType',並且wcf測試客戶端拋出了錯誤。改回原來的。 WCF測試客戶端運行順利。 – 2010-12-17 19:27:55
你沒有向我們展示你的配置中的重要和有趣的部分 -部分。你甚至有服務,實際上使用這些綁定配置和這些安全設置?從目前爲止發佈的內容來看,它看起來並不是那樣的...... –
2010-12-17 21:31:56