简体   繁体   English

C# WCF NetTCPBinding阻塞应用

[英]C# WCF NetTCPBinding Blocking Application

I have a basic buddylist type application which is a pub/sub deal in WCF.我有一个基本的好友类型应用程序,它是 WCF 中的 pub/sub 交易。 My problem is one or two of the calls are long running and this blocks up the entire server application (gui updates etc).我的问题是一两个调用长时间运行,这阻塞了整个服务器应用程序(gui 更新等)。

Here's my code:这是我的代码:

[ServiceContract(SessionMode = SessionMode.Required,
CallbackContract = typeof(IBuddyListContract))]
public interface IBuddyListPubSubContract
{
    [OperationContract]
    string GetABunchOfDataZipped(String sessionId); // this can take > 20 seconds

    ....
}

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, 
    ConcurrencyMode = ConcurrencyMode.Multiple)]
public class BuddyListPubSubContract : IBuddyListPubSubContract
{
    string GetABunchOfDataZipped(String sessionId)
    {
        // do some calculations and data retrival
        return  result;
    }
}

So far I have an idea on how to go about it but is there a simpler way?到目前为止,我对如何 go 有一个想法,但有没有更简单的方法?

Idea 1 : Have GetABunchOfDataZipped(String sessionId) be a void, when it finishes have another endpoint which on my duplex contract which I hit.想法 1 :让 GetABunchOfDataZipped(String sessionId) 成为无效,当它完成时在我命中的双工合同上有另一个端点。 I don't like this as ifs a fundamental change in my architecture and if the string is a large block of text over a slow internet connection it will still suffer from the same issue?我不喜欢这样,因为如果我的架构发生了根本性的变化,如果字符串是通过慢速互联网连接的一大块文本,它仍然会遇到同样的问题吗?

My problem is one or two of the calls are long running and this blocks up the entire server application (gui updates etc).我的问题是一两个调用长时间运行,这阻塞了整个服务器应用程序(gui 更新等)。

You're not clear on where you're seeing the blocking behavior, but it sounds like it would be on the client side.您不清楚您在哪里看到阻塞行为,但听起来它会在客户端。 You should be making your call to your WCF service from a background thread, not the UI thread.您应该从后台线程而不是 UI 线程调用 WCF 服务。 Then when you handle the result, you won't be able to interact with your UI elements directly, you will need to use each control's Invoke method.然后当您处理结果时,您将无法直接与您的 UI 元素交互,您将需要使用每个控件的Invoke方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM