WCF ConcurrencyMode Single and InstanceContextMode PerCall

后端 未结 2 1718
情话喂你
情话喂你 2020-12-05 14:25

I have an issue with my wcf service config. I would like every call to my service create a new instance of the service. For the concurrency I would like to one call is fini

2条回答
  •  孤街浪徒
    2020-12-05 15:11

    I know this question was marked as answered, but there is a better alternative:

    If you use a InstanceContextMode.Single then you will reuse the same instance for all calls. If your service is long running this requires your code to manage resources perfectly, since it will never be garbage collected without a service restart.

    Instead keep the InstanceContextMode.PerCall for “every call to my service creates a new instance” and then use throttling: Set the max concurrent instances to 1. The MSDN documentation does exactly this as one of the examples.

提交回复
热议问题