WCF Custom Authentication not working
Trying to implement a simple 'username'/'password' authentication for wcf service. But its just not working. No errors/exceptions. Here is the web config code:
<?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>
Validate Code:
public class CCustomValidatorClass : UserNa开发者_高级运维mePasswordValidator
{
public override void Validate(string userName, string password)
{
if(userName != "Test" || password != "1234567")
{
throw new FaultException("The provided credentials are invalid.");
}
}
}
There are no errors or exceptions. I am able to call the service and execute without any credentials. On local debugging the validate method is never hit.
I have no idea what is getting missed out.
Is the service hosted in IIS? If so this might not be supported since IIS does the tranport auth. http://msdn.microsoft.com/en-us/library/aa702565.aspx
精彩评论