2016-11-29 82 views
0

我有一些Windows服務的使用經驗,並且我只是想起IdentityServer3。我當前的解決方案在IISExpress中工作正常,但我無法讓它在IIS中工作。所以,我認爲在Windows服務中託管它可能會更容易,但我一直無法找到任何樣本來啓動和運行。有沒有人採取這種方法?如何將IdentityServer3作爲Windows服務運行

我的第一個雖然是我需要在我的OnStart方法實例化我的IS3啓動類,然後調用配置方法來創建我的認證服務器,但該方法需要一個IAppBuilder參數,我不知道如何創建此。任何想法,將不勝感激。

+1

Jpaull,在最初的時候,它是這種情況對我來說還有,它能夠更好地解決在IIS上部署,主要是證書和主機名問題的問題在那兒。發佈該錯誤並找到該解決方案。總之,即使您可以將IDS3作爲控制檯應用程序運行(樣本可在Identityserver3 GIT中使用)。從長遠來看,它總是更好地將其託管在IIS中。 – Sivalingaamorthy

+0

只是來到這裏尋找答案的任何人的最終評論。我最終返回並在IIS中運行IdentityServer。我從來沒有完全解決我嘗試在Windows服務中運行時遇到的問題。 – jpaull

回答

1

我在做一些類似的...

public partial class ServiceHost : ServiceBase 
{ 
    private IDisposable _service; 

    public ServiceHost() 
    { 
     InitializeComponent(); 
    } 

    public void Start(string[] args) { OnStart(args); } 

    protected override void OnStart(string[] args) 
    { 
     var options = new StartOptions("https://localhost:44331/"); 

     _service = WebApp.Start(options, Configuration); 
    } 

    protected override void OnStop() 
    { 
     _service?.Dispose(); 
    } 

    private static void Configuration(IAppBuilder app) 
    { 
     var factory = new IdentityServerServiceFactory() 
      .UseInMemoryUsers(Users.Get()) 
      .UseInMemoryClients(Clients.Get()) 
      .UseInMemoryScopes(Scopes.Get()); 

     var idsrvOptions = new IdentityServerOptions 
     { 
      Factory = factory, 
      SigningCertificate = Cert.Load(), 
      AuthenticationOptions = new AuthenticationOptions 
      { 
       // This is where we configure External Identity Providers 
       IdentityProviders = ConfigureIdentityProviders 
      } 
     }; 

     app.UseIdentityServer(idsrvOptions); 
    } 

    private static void ConfigureIdentityProviders(IAppBuilder app, string signInAsType) 
    { 
    } 
} 
+0

我做了類似的事情,雖然現在我正在處理在IdentityServer內彈出的問題。我正在等待發布自己的解決方案,直到我完全正常工作。唯一的區別是我調用了沒有配置參數的WebApp.Start方法,並且配置仍然在IdentityServer啓動類中完成。我很好奇,如果你的解決方案完全正常工作並經過測試?這似乎不太可能,但也許你這樣做會解決我在IS中看到的問題。 – jpaull

+0

@jpaull,是的我的解決方案正在工作。與我上面發佈的唯一真正的區別在於Configuration,ConfigureIdentityProviders和WebApp.Start的東西實際上被包裝在另一個暴露了接受一些自定義參數的公共靜態IDisposable開始方法的類中。我沒有發佈,因爲它看起來太詳細了。 此外,我只是使用這種方法的開發目的,爲生產我們可能會使用IIS(但我還沒有嘗試過)。 –