1

I've been struggling with this for a couple of days now - I cannot get this WCF service configured correctly to use a custom membership provider. When I fire up the test client I get this error:

The username/password Membership provider MidlandsCoop.MembersWcfService.Business.UserAuthentication specified in the configuration is invalid. No such provider was found registered under system.web/membership/providers.

I have been following this MSDN link to no avail. Can anyone tell me where I'm going wrong?

Here's my web.config:

<?xml version="1.0"?> <configuration> <connectionStrings> <add name="MyCS" connectionString="Data Source=my server;Initial Catalog=MyDB;Integrated Security=True" providerName="System.Data.SqlClient"/> </connectionStrings> <system.web> <compilation debug="true" targetFramework="4.0" /> </system.web> <system.serviceModel> <bindings> <wsHttpBinding> <binding name="wsHttpBinding"> <security> <message clientCredentialType="UserName" /> </security> </binding> </wsHttpBinding> </bindings> <services> <service name="MidlandsCoop.MembersWcfService.MembersService" behaviorConfiguration="Service_Behaviour"> <endpoint address="" binding="basicHttpBinding" bindingConfiguration="" name="basicHttpBinding" contract="MidlandsCoop.MembersWcfService.IMembersService" /> <endpoint binding="wsHttpBinding" bindingConfiguration="wsHttpBinding" name="wsHttpBinding" contract="MidlandsCoop.MembersWcfService.IMembersService" /> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> <behaviors> <serviceBehaviors> <behavior name="Service_Behaviour"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> <serviceCredentials> <userNameAuthentication userNamePasswordValidationMode="Custom" membershipProviderName="MidlandsCoop.MembersWcfService.Business.UserAuthentication" /> </serviceCredentials> </behavior> </serviceBehaviors> </behaviors> <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" /> </system.serviceModel> <system.webServer> <modules runAllManagedModulesForAllRequests="true" /> </system.webServer> </configuration> 

My user authentication class is as follows:

public class UserAuthentication : UserNamePasswordValidator { public override void Validate(string userName, string password) { if (null == userName || null == password) { throw new ArgumentNullException(); } var db = new PetaPoco.Database("MyDB"); db.Fetch<dynamic>("SELECT Username, Password FROM MyTable WHERE Username=@0 AND Password =@1", userName, password); } } 

Any suggestions would be greatly appreciated.

1 Answer 1

2

the link that you have provided mentions customUserNamePasswordValidatorType to specify custom authentication type, UserAuthentication in your case. I think MembershipProviderName should be a class derived from MembershipProvider Class.

Sign up to request clarification or add additional context in comments.

4 Comments

try to change membershipProviderName="MidlandsCoop.MembersWcfService.Business.UserAuthentication" to customUserNamePasswordValidatorType ="MidlandsCoop.MembersWcfService.Business.UserAuthentication"
this link msdn.microsoft.com/en-us/library/ms731315.aspx mentions attributes of <userNameAuthentication> element. See if you have not already.
Thanks for the response - I now get this error: Could not load type 'MidlandsCoop.MembersWcfService.Business.UserAuthentication' from assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Solved! Just needed to add the namespace after the type name. Thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.