![](/img/trans.png)
[英]The service did not respond to the start or control request in a timely fashion when using Topshelf
[英]Can't start topshelf service locally: The service did not respond in a timely fashion
我無法使用以下設置啟動我的服務。
static void Main(string[] args)
{
var builder = new ContainerBuilder();
builder.RegisterModule<FixAcceptorModule>();
var container = builder.Build();
var rc = HostFactory.Run(c =>
{
c.UseAutofacContainer(container);
c.Service<IServiceManager>(svc =>
{
svc.ConstructUsingAutofacContainer();
svc.WhenStarted(sm => sm.Start()).BeforeStartingService(a => a.RequestAdditionalTime(TimeSpan.FromSeconds(30)));
svc.WhenStopped(sm => sm.Stop());
});
c.SetDescription("");
c.SetDisplayName("FIX Acceptor Service");
c.SetServiceName("FixAcceptorSvc");
c.RunAsLocalService();
c.StartManually();
});
}
這是啟動動作myservice.exe start
的 output :
Topshelf.Hosts.StartHost Error: 0 : The service failed to start., System.InvalidOperationException: Cannot start service FixAcceptorSvc on computer '.'. ---> System.ComponentModel.Win32Exception: The service did not respond to the start or control request in a timely fashion
--- End of inner exception stack trace ---
at System.ServiceProcess.ServiceController.Start(String[] args)
at System.ServiceProcess.ServiceController.Start()
at Topshelf.Runtime.Windows.WindowsHostEnvironment.StartService(String serviceName, TimeSpan startTimeOut)
at Topshelf.Hosts.StartHost.Run()
盡管異常指向超時,但我認為這與時間問題無關,因為此異常會立即拋出。 我想這更像是權限或配置問題。
注意事項:
Windows 10 Pro - 1909
myservice.exe install --localservice
(和c.RunAsLocalSystem()
在HostFactory
)=>相同的結果myservice.exe install --localsystem
(和 HostFactory 中的HostFactory
c.RunAsLocalSystem()
)=>相同的結果myservice.exe install -username myaduser -password myadpassword
沒有幫助(仔細檢查組策略並且我的用戶被允許作為服務登錄)那么我在這里做錯了什么?
提到的例外完全是誤導性的。 我找到了罪魁禍首。 要獲取更多詳細信息,我添加了以下操作:
c.OnException(ex =>
{
File.AppendAllText(@"C:\Temp\Service.txt", ex.ToString());
});
現在這終於讓我走上了正軌。 由於異常顯示我的服務有問題,它正在查找錯誤的文件夾( C:\Windows\System32
),用於 FIX 字典......問題已解決!
Topshelf.ServiceBuilderException: An exception occurred creating the service: IServiceManager ---> Autofac.Core.DependencyResolutionException: An exception was thrown while activating StrukiApp.FixAcceptor.Infrastructure.ServiceManager -> StrukiApp.FixAcceptor.Acceptor. ---> Autofac.Core.DependencyResolutionException: An exception was thrown while invoking the constructor 'Void .ctor(QuickFix.IApplication, QuickFix.IMessageStoreFactory, QuickFix.SessionSettings, QuickFix.ILogFactory)' on type 'Acceptor'. ---> QuickFix.ConfigError: Configuration failed: Could not find file 'C:\WINDOWS\system32\FIX44.xml'. ---> System.IO.FileNotFoundException: Could not find file 'C:\WINDOWS\system32\FIX44.xml'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
at QuickFix.SessionFactory.createDataDictionary(SessionID sessionID, Dictionary settings, String settingsKey, String beginString)
at QuickFix.SessionFactory.ProcessFixDataDictionary(SessionID sessionID, Dictionary settings, DataDictionaryProvider provider)
at QuickFix.SessionFactory.Create(SessionID sessionID, Dictionary settings)
at QuickFix.ThreadedSocketAcceptor.CreateSession(SessionID sessionID, Dictionary dict)
at QuickFix.ThreadedSocketAcceptor.CreateSessions(SessionSettings settings, SessionFactory sessionFactory)
at QuickFix.ThreadedSocketAcceptor..ctor(SessionFactory sessionFactory, SessionSettings settings)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.