How does WAS/IIS manage ServiceHost instances?
It appears that WAS will call ServiceHostFactory.CreateHost() once per each service implementation. How does WAS manage the lifetime of the ServiceHost/ServiceHostFactory? We have a custom factory/host that is 开发者_StackOverflowoccasionally being re-initialized. I'm wondering if WAS is recycling itself or it has some other reason to re-create the ServiceHostFactory/ServiceHost. I'm guessing the ServiceHostFactory gets fired up for the AppDomain and is a singleton, can someone confirm?
After instrumenting WCF, it appears that IIS/WAS will create a ServiceHostFactory per endpoint. From there it will spin up ServiceHosts as it sees fit, as this depends on your configuration.
The WAS manages the activation and lifetime of the worker processes. It manages the message-based activation and worker process recycling, to maintain the app resources. Reading your case, this affirmative is true.
You can use the Single InstanceContext, to handle all client request. Add the following attribute in the contract implementation:
[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]
Also, take a look at the ServiceHost start operation, if is under a static method.
精彩评论