【问题标题】:WCF configuration - Custom authentication on the hostWCF 配置 - 主机上的自定义身份验证
【发布时间】:2013-07-29 10:05:07
【问题描述】:

我已经为此苦苦挣扎了几天 - 我无法正确配置此 WCF 服务以使用自定义成员资格提供程序。当我启动测试客户端时,我收到此错误:

配置中指定的用户名/密码成员资格提供商 MidlandsCoop.MembersWcfService.Business.UserAuthentication 无效。在 system.web/membership/providers 下找不到此类提供商。

我一直关注这个MSDN link 无济于事。谁能告诉我哪里出错了?

这是我的 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);
    }
}

任何建议将不胜感激。

【问题讨论】:

    标签: wcf web-config wcf-security


    【解决方案1】:

    您提供的链接提到 customUserNamePasswordValidatorType 以指定自定义身份验证类型,在您的情况下为 UserAuthentication。我认为 MembershipProviderName 应该是从 MembershipProvider 类派生的类。

    【讨论】:

    • 尝试将 membersProviderName="MidlandsCoop.MembersWcfService.Business.UserAuthentication" 更改为 customUserNamePasswordValidatorType ="MidlandsCoop.MembersWcfService.Business.UserAuthentication"
    • 这个链接msdn.microsoft.com/en-us/library/ms731315.aspx 提到了 元素的属性。看看你是否还没有。
    • 感谢您的回复 - 我现在收到此错误:无法从程序集 'System.ServiceModel、Version=4.0.0.0、Culture=neutral、PublicKeyToken 加载类型 'MidlandsCoop.MembersWcfService.Business.UserAuthentication' =b77a5c561934e089'.
    • 解决了!只需在类型名称后添加命名空间。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-18
    • 2016-02-03
    相关资源
    最近更新 更多