为 WCF 服务加载 COM 对象的启动代码 [英] Startup Code for Loading COM Object for WCF Service
问题描述
我目前有一个 WCF 服务,它使用 COM DLL 作为其服务.COM 对象仅加载一次并通过单例保存.问题是第一次运行需要大约 1 分钟来加载 COM 对象.WCF 服务通过 Windows 服务托管.我想知道如何通过 Windows 服务的启动加载 COM 对象单例.
I am currently have a WCF service that uses a COM DLL for its service. The COM object is only loaded once and saved via a singleton. The problem is the first run takes about 1 minute to load the COM Object. The WCF service is hosted via a Windows Service. I am wondering how can I load the COM Object singleton via the startup of the Windows Service.
protected override void OnStart(string[] args)
{
if (host != null)
{
host.Close();
}
Type serviceType = typeof(MyService);
host = new ServiceHost(serviceType);
host.Open();
objectConn.getInstance()
}
当我尝试在Windows服务启动的OnStart中添加Singleton的负载时,总是失败.我想问一下这是否是为 objectConn 实例添加启动例程的正确方法.我试图将单例加载放在 MyService 构造函数中,但它仅在第一次调用我调用的 Web 服务操作/方法时被调用,这使得第一次服务调用变得笨拙.
When I try to add the load of the Singleton in the OnStart of the Windows Service startup, it always fails. I would like to ask if this i the proper way to add startup routine for the objectConn instance. I tried to place the singleton loading in the MyService construtor but it is only called with the first call to the web service operation/method that I invoke which makes the first service call awkward.
我阅读了 DependencyInjection,但我认为添加的行为不适用,因为我只想加载一次 COM 对象源.
I read about DependencyInjection but I think the added behavior is not applicable since I just want to load the COM object source once.
推荐答案
你可能可以这样做 - 但我建议在
You can probably do this - but I would recommend doing it before the
host.Open()
打电话.此调用会启动整个 WCF 运行时和所有内容,如果可能的话,我更愿意在此之前完成所有初始化任务.
call. This call spins up the entire WCF runtime and everything, and I would prefer to do all initialization tasks before that, if ever possible.
马克
这篇关于为 WCF 服务加载 COM 对象的启动代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!