当前位置: 动力学知识库 > 问答 > 编程问答 >

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,

InstanceContextMode=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)]
分享给朋友:
您可能感兴趣的文章:
随机阅读: