As marc_s notes, you create the WCF PerCall / PerSession service, and each request / first request of each session is created by a new instance.
You can build such plumbing around it so that the instance can notify the service host when it receives a new request, but this will not be an easy exercise, and you need to remember about a potential memory leak if you decide to use events for this - without implementation the weak event pattern, your WCF service instances may be left out, because event handlers still contain a link to them IF you do not want to notify the host that you are unsuccessful when hosting WCF service instances.
Instead, there are two ideas that could help you achieve your goal:
Use the Single InstanceContextMode if your service can be made singleton, in which case you will create a new instance that implements your service contract and places it:
this way you will gain access to the instance that will receive client requests.
Alternatively, you could have all hosted instances as dummy βfacadesβ that share a static class that actually handles requests:
[ServiceContract] interface IMyService { ... } interface IMyServiceFascade : IMyService { ... }
I would say that you should go with the first approach, if possible, make life easier!
theburningmonk
source share