WCF SendTimeout,ReliableSession和异步操作

编程入门 行业动态 更新时间:2024-10-27 19:17:38
本文介绍了WCF SendTimeout,ReliableSession和异步操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我对可靠的会话有点困惑WCF.我有一个启用可靠会话的客户端应用程序,我配置SendTimeout = TimeSpan.FromSeconds(5) (5秒),我调用了长时间运行的服务操作(大于5s).如果长时间运行的操作是同步运行的   ;例外 将在5秒后抛出,但如果运行 同步 超时 错误不会被抛出,客户端将等待它完成.

I am bit confused with reliable session in WCF. I have a client application which enable reliable session, i config SendTimeout = TimeSpan.FromSeconds(5) (5 seconds), i call a long-running service operation (greater than 5s). If the long-running operation is run synchronouslyan exception will be thrown after 5s, but if it run asynchronouslytimeout error will not be thrown and the client will wait until it is completed.

如何在异步情况下捕获错误?

测试程序代码为:

var _bd = new WSHttpBinding(); _bd.Security.Mode = SecurityMode.None; _bd.ReliableSession.Enabled = true; _bd.SendTimeout = TimeSpan.FromSeconds(5); var _factory = new ChannelFactory<IService1>(_bd, "localhost:61228/IService1.svc"); var _conn = _factory.CreateChannel(); var _icc = _conn as IContextChannel; try { _icc.Open(); await _conn.longRunning(); MessageBox.Show("Completed"); } catch { throw; } finnaly { if (_icc.State == CommunicationState.Openned) { try { _icc.Close(); } catch { _icc.Abort(); } } }

等待回复,

谢谢,

中阮

推荐答案

Trung,

>>如果它异步运行,则不会抛出超时错误,客户端将等待它完成.

>> if it run asynchronously timeout error will not be thrown and the client will wait until it is completed.

异步选项是否将完成或引发任何其他异常?我对此进行了简单的测试,可以重现您的问题.无论是否超时,结果都将发送给客户端.我认为它与异步模式有关.实施时 WCF处于异步状态,客户端向服务发送请求,它将不等待服务响应,服务将对客户端作出响应,直到完成请求为止.

Will the async option be completed or throw any other exception? I made a simple test with this, and I could reproduce your issue. The result will be send to client no matter whether it is timeout. I assume it is related with async pattern. When implementing WCF in async, client send a request to service, it would not wait for service to response, and service will response to client until it finished the request.

如果您需要在特定时间内停止它,建议您使用同步选项.

If you need to stop it in a certain time, I would suggest you use sync option.

最好的问候,

爱德华

更多推荐

WCF SendTimeout,ReliableSession和异步操作

本文发布于:2023-10-30 02:59:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1541565.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:操作   WCF   SendTimeout   ReliableSession

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!