Why should the WCF service have status information? Could you save it in the database and access it when necessary?
WCF allows Singleton instances for services, but it is usually not recommended to use this unless you absolutely must. This is usually simpler and scales much better if you can store status information, for example. database table and allow clients to access it using the regular WCF service for each call.
UPDATE:
Ok, another idea: you will always have only one ServiceHost. If you select the instanciation mode for each call (as recommended by all leading experts), ServiceHost will allocate a pool of workflow threads, which will then serve incoming requests.
Why should the WCF service be single? Could you use the "per call" and still receive status information in the NT service?
A request comes in and an instance of your service object is created (a class of service that implements the service interface). How do you access status information in the NT service right now? Could you do this from a newly created instance of the service - when do you really need it?
If you have status information stored in the NT service, you need to make sure that any concurrent access is handled appropriately - it does not depend on whether your WCF service class is single or not.
UPDATE 2:
Using "OperationContext.Current.Host", you can access the ServiceHost that hosts the given instance of the service inside the executable method of the service - not sure if you can access the actual instance of the NT service. But if you create your own descendant ServiceHost, which has the additional property "ListOfClients", you can access this list at any time from any instance of the service.
EXIT YOU: since it is possible that any number of service requests is processed at any given time, reading the list should be thread safe, and updating the list from Windows NT is even more risky and you need to consider these concurrency problems! Block the list if you need to update it, otherwise you will get unpredictable results.
Mark
source share