WCF in Winforms app - is it always single-threaded?
I have a Winforms application that exposes a WCF service.
From IIS, I try to consume the service. From 2 different computers I try to call test1.aspx
which in turn calls the WCF inside the Winforms app.
test1.aspx => from computer 1 => First Call
test1.aspx => from computer 2 => Second Call
I see that the WCF is single-threaded, and before it starts to process CALL 2 it needs to finish to process CALL 1.
[ServiceBehavior(IncludeExceptionDetailInFaults = true,
ConcurrencyMode=ConcurrencyMode.Multiple,
I开发者_运维技巧nstanceContextMode=InstanceContextMode.PerSession)]
I have Windows Server 2008 R2 and IIS 7.5
Can anyone help me?
WCF behaves differently when service is hosted in UI thread which is probably your case. By default WCF processing joins Windows message loop so request processing will not only become serial but it will also halt all event processing in WinForms UI (application will freeze).
To avoid this behavior you must explicitly say that you don't want to host service in UI thread:
[ServiceBehavior(UseSynchronizationContext = false)]
精彩评论