简体   繁体   English

双工服务冻结客户端的呼叫请求/答复方法,直到发生超时

[英]Call request/reply method of duplex service freeze client until timeout occur

I have create a duplex WCF service tha return data from an external device to the client and allow also request/reply calls. 我已经创建了一个双工WCF服务,可以将数据从外部设备返回到客户端,并且还允许请求/答复呼叫。

My problem is that the request/reply calls sometime freeze the client until timeout occurs. 我的问题是请求/答复调用有时会冻结客户端,直到发生超时。

These are the interfaces: 这些是接口:

[ServiceContract(CallbackContract = typeof(ITimerServiceCallback), SessionMode = SessionMode.Required)]
public interface ITimerService
{
    [OperationContract]
    void StartTimer();

    [OperationContract]
    void StopTimer();

    [OperationContract]
    void DoOp();
}

public interface ITimerServiceCallback
{
    [OperationContract(IsOneWay = true)]
    void ReportTick(string now);
}

This is the implementation: 这是实现:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
    public class TimerService : ITimerService
    {
        public TimerService()
        {
            _timer = new System.Timers.Timer() { Interval = 500 };
            _timer.Elapsed += Timer_Elapsed;
        }

        private void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            _context.GetCallbackChannel<ITimerServiceCallback>().ReportTick(DateTime.Now.ToString());
        }

        private readonly System.Timers.Timer _timer;
        private OperationContext _context;

        public void StartTimer()
        {
            _context = OperationContext.Current;
            _timer.Start();
        }

        public void StopTimer()
        {
            _timer.Stop();
        }

        public void DoOp()
        {
            System.Threading.Thread.Sleep(200);
        }
    }

Step to reproduce the problem: * call StartTimer * call DoOp (one or more time until the client freeze) 重现此问题的步骤:*调用StartTimer *调用DoOp(一个或多个时间直到客户端冻结)

After one minute I have an timeout exception. 一分钟后,我有一个超时异常。

If I use the async/await from the client side all work fine. 如果我从客户端使用异步/等待,一切正常。

ex: the DoOp method is called in this way: 例如:DoOp方法以这种方式调用:

private async void _btnDoOp_Click(object sender, EventArgs e)
{
    _btnNoOp.Enabled = false;
    try {
        Task task = Task.Run(() => _client.DoOperation());
        await task;
    } catch (Exception ex) {
        MessageBox.Show(ex.Message);
    } finally {
        _btnNoOp.Enabled = true;
    }
}

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

相关问题 WCF双工服务是否可以在该服务尝试调用之前确定客户端的回调通道是否已实现特定方法? - Can a WCF duplex service determine if the callback channel of a client has implemented a specific method before the service tries to call it? WCF - 双工通道 - 请求-回复操作中的回调方法是否会出现在线程池线程中? - WCF - Duplex channel - Will the callback method within request-reply operation come in thread pool thread? 设置轮询双工WCF服务中的回调超时 - Set the Timeout of a Callback in a Polling Duplex WCF Service 带有Apache ActiveMQ WCF绑定的双工或请求-答复配置问题 - Duplex or request-reply with Apache ActiveMQ WCF Binding configuration question 获得合同需要TwoWay(请求答复或双工)错误 - getting Contract requires TwoWay (either request-reply or duplex) error 强制客户端在服务上调用方法? - Force a client to call a method on the service? 处理双工WCF服务中的客户端断开连接 - Handling client disconnect in duplex WCF service Android / iOS客户端使用WCF双工服务 - Android/iOS client consumes WCF Duplex service wcf双工服务失去与客户端的耦合 - wcf duplex service lose coupling with client WCF双工服务和Android客户端? 任何可能性 - WCF Duplex service and Android client? Any possibilities
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM