强大的 WCF 服务
确保服务稳健性以防止服务不可用的最佳方法是什么?如果服务确实不可用,是否有办法重新启动服务?
提前致谢。
What is the best way to ensure service robustness to prevent a service becoming unavailable, if it does become unavaliable is there a way of restarting the service?
thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用托管技术。 您可以自行托管在 Windows 服务中,并放置故障事件来触发服务关闭。 然后您可以使用 Windows 重新启动您的服务。
或者,如果您有 Windows 2008,您可以使用 WAS 来托管您的服务,这将自动重新启动它。
重要的是要认识到您的服务可能有状态,但其中没有运行“线程”,因此它不是这样运行的,对象只是存在。 您基本上是向微软付费,让其向您提供 .net 和 WCF,它们负责托管方面的工作,他们向您保证您的服务将保持可用。
方法中的崩溃会使服务出现故障,但是您可以处理任何可以优雅处理的异常,并让操作系统处理您无法处理的事情(例如内存不足异常等)。请注意,这是您的责任处理服务故障。 但除此之外,WCF 还非常强大。
Use a hosting technique. You can self host in a windows service, and place the faulted event to trigger the service to close. You can then use windows to restart your service.
Or if you have windows 2008 you can use WAS to host your service, which will automatically restart it.
It's important to realise that your service may have state, but there is no "thread" that is running in it, so it's not running as such, the object merely exists. You are basically paying microsoft to provide .net and WCF to you which looks after the hosting side of things, they guarantee to you that your service will remain available.
A crash in a method would fault the service, but you can handle any exceptions which you can deal with gracefully and let the operating system deal with things that you can't (such as out of memory exceptions etc.) Note it is your responsibility to deal with the service faulting. Beyond that however WCF is extremely robust.
这取决于您托管服务的方式。
可以在此处找到不同可用选项的说明和比较:http:// msdn.microsoft.com/en-us/library/ms730158.aspx
That depends on the way you host your service.
An explanation and comparison of the different available options can be found here: http://msdn.microsoft.com/en-us/library/ms730158.aspx
为了清楚起见,如果出于某种原因我没有处理异常并且这触发了服务终止,则在 IIS 7.0 下,服务应该以新状态重新启动。
Just for clarity, If for whatever reason I didn't handle an exception and this triggered the service to terminate, under IIS 7.0 the service should restart in a new state.