这几天我一直在为此苦苦挣扎-我无法正确配置此 WCF 服务以使用自定义成员资格提供程序。当我启动测试客户端时,我收到此错误:
配置中指定的用户名/密码成员资格提供商 MidlandsCoop.MembersWcfService.Business.UserAuthentication 无效。在 system.web/membership/providers 下找不到此类提供商。
我一直在关注这个MSDN 链接,但无济于事。谁能告诉我哪里出错了?
这是我的 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>
我的用户认证类如下:
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);
}
}
任何建议将不胜感激。