简体   繁体   English

处理WCF服务中的超时

[英]Handle timeouts in WCF service

I would like to know what is a proper way to handle timeouts in a WCF service. 我想知道在WCF服务中处理超时的正确方法是什么。

I have a service that uses sessions. 我有使用会话的服务。 The client does a Connect, various calls (as the user interacts with the client app) and then, at some point, does a Disconnect. 客户端执行Connect,进行各种调用(当用户与客户端应用进行交互时),然后在某个时候进行Disconnect。 The Disconnect operation performs a clean-up on the server (such as releasing COM objects). 断开连接操作在服务器上执行清理操作(例如释放COM对象)。 However, the client can (abnormally) terminate (for various reasons) without calling Disconnect. 但是,客户端可以(出于各种原因)终止(异常)而无需调用Disconnect。 After the receiveTimeout expires, the services is aborted. receiveTimeout过期后,服务将中止。 I need to handle this in a way that allows me to proper clean-up the session. 我需要以允许我正确清理会话的方式来处理此问题。 How can I do that? 我怎样才能做到这一点?

Is there an event I can handle? 有什么事我可以处理吗? An interface that I can implement and customize the service with it? 我可以实现和定制服务的接口吗? I have looked, but did not find something. 我已经看了,但是没找到东西。 IErrorHandler does not help with the timeouts. IErrorHandler不能帮助超时。

I have thought of a timer on the service that is reset every time a call is made to the service. 我想到了服务上的计时器,每次调用该服务时都会重置该计时器。 When the timer elapses, the client is considered disconnected and the service can clean-up the session. 当计时器过去时,客户端被视为已断开连接,该服务可以清理会话。 Is this appropriate? 这样合适吗 (This interval should be always smaller than the receiveTimeout of the binding.) (此间隔应始终小于绑定的receiveTimeout 。)

As per http://msdn.microsoft.com/en-us/library/ff183865.aspx , WCF sessions timeout by default after 10 minutes or whatever the receiveTimeout specifies. 按照http://msdn.microsoft.com/zh-cn/library/ff183865.aspx的规定 ,默认情况下,WCF会话超时时间为10分钟或任何receiveTimeout指定的时间。 If your service class implements IDisposable, I believe the Dispose() call should come in at this time, which would give you a second/last chance to clean up any outstanding resources. 如果您的服务类实现了IDisposable,那么我相信此时应该进行Dispose()调用,这将给您第二次/最后一次清理所有未清资源的机会。

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

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