处理断开连接的 WCF 通道上的 ObjectDisposeExceptions
当在由于某种原因已断开连接的 WCF 通道上调用方法时,它会引发 ObjectDisposeException。
现在是正常操作,这不应该发生,但如果由于某种原因发生了,我希望能够通过向用户显示错误(例如“由于服务未连接而操作失败”)来很好地处理异常。
问题是我只是在我的应用程序范围异常处理程序中得到一个通用的已处理异常,因此我无法确定 WCF 是否抛出它。
为了解决这个问题,我目前有一个包装类,它简单地使用 try/catch 包装所有服务方法调用,并重新抛出任何 ObjectDisposeException 作为我的全局处理程序可以处理的自定义通信异常。不过,这是一堆我可以不用的样板文件。
有没有办法确定WCF是否抛出异常?
干杯
When a method is called on a WCF channel that has been disconnected for some reason, it raises an ObjectDisposedException.
Now is normal operation this should not happen, but if for some reason it did, I would like to be able to handle the exception nicely by showing an error to the user like "An operation failed because the service is not connected".
The problem is I just get a generic disposed exception in my appwide exception handler, so I have no way of determining whether WCF threw it.
to get around this I currently have a wrapper class that simply wraps all service method calls with try/catch and rethrows any ObjectDisposedException's as a custom comms exception that my global handler can deal with. this is a load of boilerplate stuff I could do without though.
Is there any way of determining whether WCF threw the exception?
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我曾经遇到过这样的问题,似乎很难确定WCF是否抛出异常。您不能使用 CommunicationObject.Status 来解决此问题,只有当您尝试使用该通道时,它才会抛出异常,告诉您该通道出现故障。
所以我就用了和你一样的方法。
I used to encounter such problem, it seems it's difficult to determine whether the WCF throws exception. You can't use the CommunicationObject.Status for this problem, only when you try to use that channel, it throws exception to tell you that the channel is faulted.
Therefore, I used the way like yours.