Question

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.

Was it helpful?

Solution

You can probably do this - but I would recommend doing it before the

host.Open()

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top