Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF in Winforms app - is it always single-threaded?

Tags:

winforms

wcf

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, 
                 InstanceContextMode=InstanceContextMode.PerSession)]

I have Windows Server 2008 R2 and IIS 7.5

Can anyone help me?

like image 669
darez Avatar asked Dec 21 '22 19:12

darez


1 Answers

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)]
like image 191
Ladislav Mrnka Avatar answered Jan 04 '23 23:01

Ladislav Mrnka