views:

215

answers:

1

Based on documentation and articles it is recommended to call Abort() on a client proxy if an unexpected exception/fault is encountered. See the following (simplified):

MyServiceClient proxy = null;
try {
    proxy = new MyServiceClient();
    proxy.DoSomething();
    proxy.Close();
} catch (Exception ex) {
    if (proxy != null)
        proxy.Abort();
}

Is there any possibility of the call to Abort() throwing an exception itself? Should the call to Abort() be within its own try/catch?

+2  A: 

No, Abort will not fail (but .Close() or .Dispose() might). Calling .Abort() is the "sledgehammer" approach to terminating a channel - it's just torn down, regardless of an ongoing message handling.

Use it only carefully - e.g. in a exception catch case when calling .Close() failed. That's it's real purpose and proper use.

Marc

marc_s
What would happen if you didn't call abort on the channel in the above catch block?
Drew Noakes
The channel between the client and server wouldn't be properly closed and disposed of, so you would potentially have an unused channel lingering around in your system. Eventually, it'll be garbage-collected - but that take some time, and until then, it's using up system resources for no useful purpose.
marc_s