开发者

C# WCF NetTCPBinding Blocking Application

开发者 https://www.devze.com 2023-03-09 07:45 出处:网络
I have a basic buddylist type application which is a pub/sub deal in WCF. My problem is one or two of the calls are long running and this blocks up the entire server application (gui updates etc).

I have a basic buddylist type application which is a pub/sub deal in WCF. My problem is one or two of the calls are long running and this blocks up the entire server application (gui updates etc).

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?

Idea 1: Have GetABunch开发者_运维知识库OfDataZipped(String sessionId) be a void, when it finishes have another endpoint which on my duplex contract which I hit. 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).

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. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消