Errors and Exceptions
In raw .NET programming, any unhandled exception immediately terminates the process it took place in. That is not the WCF behavior, however. If a service call on behalf of one client causes an exception, it must not be allowed to take down the hosting process. Other clients accessing the service, or other services hosted by the same process, should not be affected. As a result, when an unhandled exception leaves the service scope, the dispatcher silently catches and handles it by serializing it in the returned message to the client. When the returned message reaches the proxy, the proxy throws an exception on the client side.
The client can actually encounter three types of errors when trying to invoke the service. The first type of error is communication errors such as network availability, wrong address, host process not running, and so on. Communication exceptions are manifested on the client side by the CommunicationException
.
The second type of error the client might encounter is related to the state of the proxy and the channels, such as trying to access an already closed proxy, resulting in an ObjectDisposedException
, or a mismatch in the contract and the binding security protection level.
The third type of error is the one that originated in the service call, either by the service throwing an exception or as a result of the service calling another object or resource and having that internal call throw an exception. These errors are the subject of this ...
Get Programming WCF Services now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.