WCF: Cannot find my custom validator specified in web.config - customUserNamePasswordValidatorType - - Could not load file or assembly ... - help?

customvalidator, wcf

Solution

I decided to give it another stab, and didn't like having my custom validator in another lib.

So I created a new class in App_Code, and went at it...

The following is what actually fixed it,

="CustomValidator.CustomUserNameValidator, App_Code"

Problem

So I've basically got everything up and running with wsHttpBindings and my WCF service using custom authentication over HTTPS. The issue I'm having is with the customUserNamePasswordValidatorType: ``` <serviceCredentials> <!-- Use our own custom validation --> <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="CustomValidator.CustomUserNameValidator, CustomValidator"/> </serviceCredentials> ``` Following directions found here I've created my custom class as well: ``` namespace CustomValidator { public class CustomUserNameValidator : UserNamePasswordValidator { public override void Validate(string userName, string password) { if (null == userName || null == password) { throw new ArgumentNullException(); } if (!AuthenticateUser(userName, password)) throw new SecurityTokenValidationException("Invalid Credentials"); ``` The error is "Could not load file or assembly 'CustomValidator' or one of its dependencies. The system cannot find the file specified.", and refers to the tail end of customUserNamePasswordValidatorType - "..., CustomValidator". I didn't think it was a problem having my custom validator in its own namespace and class, but I can't see what else to do to make this work. I've tried with/without the namespace at the beginning, swapping, etc - nothing. Hoping another pair of eyes can pick this out. Thanks. EDIT system.serviceModel ``` <system.serviceModel> <bindings> <!-- wsHttpBinding --> <wsHttpBinding> <binding name="wsHttpEndpointBinding"> <security mode="TransportWithMessageCredential"> <transport clientCredentialType="None" /> <message clientCredentialType="UserName" /> </security> </binding> </wsHttpBinding> <!-- webHttpBinding --> <webHttpBinding> <binding name="wsHttps" > <security mode="Transport"/> </binding> </webHttpBinding> <!-- Basic binding --> <basicHttpBinding> <binding name="TransportSecurity"> <security mode="Transport"> <message clientCredentialType="UserName"/> <!-- transport clientCredentialType="None"/--> </security> </binding> </basicHttpBinding> <!-- customBinding> <binding name="WebHttpBinding_IService"> textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16" messageVersion="Soap12" writeEncoding="utf-8"> <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> </textMessageEncoding> <httpsTransport manualAddressing="false"/> </binding> </customBinding --> <!-- Another custom binding --> <customBinding> <binding name="CustomMapper"> <webMessageEncoding webContentTypeMapperType= "IndexingService.CustomContentTypeMapper, IndexingService" /> <httpTransport manualAddressing="true" /> </binding> </customBinding> </bindings> <serviceHostingEnvironment aspNetCompatibilityEnabled="false" /> <services> <service behaviorConfiguration="ServiceBehavior" name="Service"> <!-- Service Endpoints --> <!-- since we're hosting in IIS, baseAddress is not required <host> <baseAddresses> <add baseAddress="https://mysslserver.com/Service.svc"/> </baseAddresses> </host> --> <endpoint address="https://mysslserver.com/Service.svc" binding="wsHttpBinding" bindingConfiguration="wsHttpEndpointBinding" contract="IService" name="wsHttpEndpoint"> <!-- Upon deployment, the following identity element should be removed or replaced to reflect the identity under which the deployed service runs. If removed, WCF will infer an appropriate identity automatically. --> <!--identity> <dns value="https://mysslserver.com"/> </identity--> </endpoint> <!-- endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/ --> </service> </services> <behaviors> <endpointBehaviors> <behavior name="webBehavior"> <webHttp /> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior name="ServiceBehavior"> <!-- Setup Security/Error Auditing --> <serviceSecurityAudit auditLogLocation="Application" suppressAuditFailure="false" serviceAuthorizationAuditLevel="Failure" messageAuthenticationAuditLevel="Failure" /> <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" httpsGetUrl="https://mysslserver.com/Service.svc"/> <serviceDebug includeExceptionDetailInFaults="false" /> <serviceCredentials> <!-- Use our own custom validation --> <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="CustomValidator.CustomUserNameValidator, CustomValidator"/> </serviceCredentials> </behavior> </serviceBehaviors> <!-- serviceBehaviors> <behavior name="ServiceBehavior"> <serviceMetadata httpsGetEnabled="true" httpsGetUrl="https://mysslserver.com/Service.svc" /> 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"/> </behavior--> </behaviors> </system.serviceModel> ```

Original source