0

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

4

1 回答 1

1

我曾经遇到过这样的问题,似乎很难确定WCF是否抛出异常。您不能将 CommunicationObject.Status 用于此问题,只有当您尝试使用该通道时,它才会抛出异常来告诉您该通道出现故障。

因此,我使用了像你这样的方式。

于 2011-08-05T01:36:15.440 回答