[英]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.