开发者

WCF - possible to switch between single-thread and multi-thread purely through config?

开发者 https://www.devze.com 2023-03-17 19:42 出处:网络
I have developed a WCF service (which happens to 开发者_C百科listen on an MSMQ queue). I haven\'t put any specific threading-related code in, so it runs by default in a multi-threaded manner. This wil

I have developed a WCF service (which happens to 开发者_C百科listen on an MSMQ queue). I haven't put any specific threading-related code in, so it runs by default in a multi-threaded manner. This will be fine (and most probably desirable) for a live environment, however right now this service is still being tested. I don't have total control over when messages appear on the test queue, so I'm in a situation where many could appear at once.

The service does a lot of diagnostic logging, but the logging mechanism I am obliged to use (the "company standard") is not thread-aware. So the upshot is that then several threads run at once my logging becomes a total mess. What I would like to do is to throttle the number of threads back to 1 while I am testing.

I have seen various ways of achieving single-threadedness in code, but I really don't fancy releasing one binary to Test and a different binary to Live.

I know that WCF is pretty hot on the use of config files so I was wondering whether there was some way, based purely in config, of telling a WCF service whether to listen in a single-threaded or multi-threaded mode?

TIA, Pete


See this question: WCF MSMQ consumer thread count

Glad this helped!


You could place all of the code within the service, inside a wrapper class that a Dependency Injection framework could inject at runtime.

With Dependency Injection you can configure whether to implement the dependency as a singleton, or as a per request instance.

However, testing the app in "single threaded mode" will not be sufficient.

Alternatively, why not include the current executing threadid in the logging info - then filter the logfile by threadid as required?

0

精彩评论

暂无评论...
验证码 换一张
取 消