gpt4 book ai didi

winforms - Winforms 应用程序中的 WCF - 它始终是单线程的吗?

转载 作者:行者123 更新时间:2023-12-02 19:32:29 26 4
gpt4 key购买 nike

我有一个公开 WCF 服务的 Winforms 应用程序。

我尝试从 IIS 中使用该服务。我尝试从两台不同的计算机调用 test1.aspx ,后者又调用 Winforms 应用程序内的 WCF。

test1.aspx => from computer 1 => First Call
test1.aspx => from computer 2 => Second Call

我看到 WCF 是单线程的,在开始处理 CALL 2 之前,它需要完成处理 CALL 1。

[ServiceBehavior(IncludeExceptionDetailInFaults = true, 
ConcurrencyMode=ConcurrencyMode.Multiple,
InstanceContextMode=InstanceContextMode.PerSession)]

我有 Windows Server 2008 R2 和 IIS 7.5

有人可以帮助我吗?

最佳答案

当服务托管在 UI 线程中时,WCF 的行为会有所不同,这可能就是您的情况。默认情况下,WCF 处理加入 Windows 消息循环,因此请求处理不仅会变成串行,而且还会停止 WinForms UI 中的所有事件处理(应用程序将卡住)。

要避免这种行为,您必须明确表示您不想在 UI 线程中托管服务:

[ServiceBehavior(UseSynchronizationContext = false)]

关于winforms - Winforms 应用程序中的 WCF - 它始终是单线程的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4718244/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com