为 WCF 服务加载 COM 对象的启动代码
我目前有一个 WCF 服务,它使用 COM DLL 作为其服务。 COM 对象仅加载一次并通过单例保存。问题是第一次运行需要大约 1 分钟来加载 COM 对象。 WCF 服务通过 Windows 服务托管。我想知道如何通过 Windows 服务的启动加载 COM 对象单例。
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 服务操作/方法时调用它,这使得第一次服务调用很尴尬。
我读过有关 DependencyInjection 的内容,但我认为添加的行为不适用,因为我只想加载 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()
}
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.
I read about DependencyInjection but I think the added behavior is not applicable since I just want to load the COM object source once.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您也许可以这样做 - 但我建议在
通话之前这样做。此调用会启动整个 WCF 运行时和所有内容,如果可能的话,我更愿意在此之前完成所有初始化任务。
马克
You can probably do this - but I would recommend doing it before the
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.
Marc