0

我有一个 asp.net mvc 4 Web 应用程序,我在其中创建了一个自定义成员资格提供程序(从 MembershipProvider 基类继承)。在同一个解决方案中,但在另一个项目中,我有一个 wcf 服务,我想使用我的成员资格提供程序(称为 KinematMembershipProvider)的 ValidateUser 方法对用户进行身份验证

这是我的服务界面

[ServiceContract]
public interface IKinematService
{
    [OperationContract]
    bool AuthenticateUser(string username, string password);
}

和实际的服务

public class KinematService : IKinematService
{
    public bool AuthenticateUser(string username, string password)
    {
        KinematMembershipProvider membershipProvider = (KinematMembershipProvider)Membership.Providers["KinematMembershipProvider"];
        return membershipProvider.ValidateUser(username, password);
    }
}

这是我的 app.config 文件

    <?xml version="1.0" encoding="utf-8"?>
<configuration>
  <!--configSections-->
  <configSections>
    <section name="entityFramework"
             type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <!--appSettings-->
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <!--connectionStrings-->
  <connectionStrings>
    <add name="KinematDbContext" providerName="System.Data.SqlClient"
         connectionString="Data Source=.;Initial Catalog=KinematDatabase;Integrated Security=SSPI;" />
  </connectionStrings>
  <!--system.web-->
  <system.web>
    <!--compilation-->
    <compilation debug="true" />
    <!--membership-->
    <membership defaultProvider="KinematMembershipProvider">
      <!--providers-->
      <providers>
        <add name="KinematMembershipProvider" type="Kinemat.Web.Infrastructure.KinematMembershipProvider"
             connectionStringName="KinematDbContext" enablePasswordRetrieval="true" enablePasswordReset="true"
             requiresQuestionAndAnswer="false" requiresUniqueEmail="true" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6"
             minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" passwordFormat="Encrypted" />
      </providers>
    </membership>
  </system.web>
  <!--system.serviceModel-->
  <system.serviceModel>
    <!--services-->
    <services>
      <service name="Kinemat.WebServices.KinematService" behaviorConfiguration="ProviderServiceBehavior">
        <endpoint address="http://localhost:52174/WcfServices/Kinemat" binding="wsHttpBinding" bindingConfiguration="MembershipBinding" 
                  contract="Kinemat.WebServices.IKinematService">
        </endpoint>
      </service>
    </services>
    <!--bindings-->
    <bindings>
      <wsHttpBinding>
        <binding name="MembershipBinding">
          <security mode ="Message">
            <message clientCredentialType ="UserName" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <!--behaviors-->
    <behaviors>
      <!--serviceBehaviors-->
      <serviceBehaviors>
        <behavior name="ProviderServiceBehavior">
          <serviceCredentials>
            <userNameAuthentication userNamePasswordValidationMode="MembershipProvider"
                                    membershipProviderName="KinematMembershipProvider" />
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
  <!--entityFramework-->
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>
</configuration>

当我运行我的服务时,我收到以下错误System.TypeLoadException:无法从程序集“System.Web,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a”加载类型“Kinemat.Web.Infrastructure.KinematMembershipProvider”。

我不知道为什么它试图在 System.Web 程序集中搜索。请问您有什么建议吗?如果您需要,请询问任何其他信息。谢谢你。

4

1 回答 1

1

它试图在System.Web程序集中找到它,因为您没有在配置中指定它应该实际搜索您的提供程序的位置。尝试修改您的配置以包含程序集名称,如下所示:

<providers>
    <add name="KinematMembershipProvider" type="Kinemat.Web.Infrastructure.KinematMembershipProvider, Assembly.Name.Where.Provider.Resides" .../>
</providers>
于 2013-06-09T10:34:52.673 回答