2015-07-20 126 views
1

我正在适应ASP身份验证功能从WCF Web服务调用。我使用ninject进行跨项目的依赖项注入,所以我有一个自定义类(UserProfilManager)用于实现标识函数,方法是注入我的构造函数所需的依赖项。依赖注入'SignInManager'(身份2.0)与Ninject

public class UserProfilManager 
{ 
    private readonly UserStore _userStore; 
    private readonly UserManager<IdentityUser, Guid> _userManager; 
    private readonly SignInManager<IdentityUser, Guid> _signInManager; 

    public UserProfilManager(UserStore userStore, 
     UserManager<IdentityUser, Guid> userManager, 
     SignInManager<IdentityUser, Guid> signInManager) 
    { 
     _userStore = userStore; 
     _userManager = userManager; 
     _signInManager = signInManager; 
    } 

    //here I call Identity functionality (PasswordSignInAsync), GetByLogin is a function ment to be called from WCF 
    public async Task<SignInStatus> GetByLogin(string login, string password, bool RememberMe, bool shouldLockout) 
    { 
     return await _signInManager.PasswordSignInAsync(login, password, RememberMe, shouldLockout); 
    } 

    //FindByNameAsync function works fine, UserStore binding : OK 
    public User GetByName(string login) 
    { 
     var user = _userStore.FindByNameAsync(login); 
     return new User 
     { 
      //... 
     }; 
    } 
} 

的“UserStore”和“的UserManager”绑定完成不错,但“SignInManager”抛出ActivationException: 错误激活IAuthenticationManager,没有匹配的绑定是可用的,并且该类型不是自可绑定。 我固定它通过添加此:

public class UserModule : NinjectModule 
    { 
     public override void Load() 
     { 
      Bind<IDbContext>().To<DbContext>(); 

      Bind<IUserProfilManager>().To<UserProfilManager>(); 
      Bind<IUserStore<IdentityUser, Guid>>().To<UserStore>(); 

      Bind<IAuthenticationManager>(). 
       ToMethod(c => HttpContext.Current.GetOwinContext().Authentication).InRequestScope(); 

     } 
    } 

现在,它给我这个错误:尝试加载应用程序发生

以下错误。 - 找不到包含OwinStartupAttribute的程序集。 - 找不到包含启动或[AssemblyName] .Startup类的程序集。 要禁用OWIN启动发现,请在web.config中添加值为“false”的appSetting owin:AutomaticAppStartup。 要指定OWIN启动程序集,类或方法,请在web.config中将appSetting owin:AppStartup与完全限定的启动类或配置方法名称相加。

我没有启动类,我并不需要它,我试图从我的WCF的web.config添加<add key="owin:AutomaticAppStartup" value="false" />搜索该类全髋关节,但它抛出一个内部服务器错误: 失败添加服务。服务的元数据可能不可用。确保您的服务正在运行并显示元数据。

有人可以告诉我我做错了什么,或者建议一个基于我的代码的解决方案。

回答

2

您在这里看到的是OWIN试图围绕Web服务器启动自己。但是因为您运行WCF,它无法执行任何操作。 Bascially OWIN说它不能在当前配置的WCF中运行。 IAuthenticationManager在HTTP请求上设置cookie,但由于WCF不仅是HTTP,所以OWIN的cookie不能应用。

因此,您需要检查您的体系结构WCF服务如何进行身份验证以及它的进展情况。

看在other questions and answers,我不think you can makeOWIN work with WCFBut you can try...

+0

您是否知道在WCF运行时如何配置OWIN?在一个简单的Web应用程序中,有一个启动类调用一个方法配置(IAppBuilder应用程序)来完成这项工作。你认为我可以在WCF中做同样的事吗? – Idham

+0

我不认为你可以在OWIN中使用WCF。请参阅编辑链接到其他类似的问题。 – trailmax