The Close
method on an ICommunicationObject
can throw two types of exceptions as MSDN outlines here. I understand why the Close
method can throw those exceptions, but what I don't understand is why the Dispose
method on a service proxy calls the Close
method without a try
around it. Isn't your Dispose
method the one place where you want make sure you don't throw any exceptions?
Anyone utilizing the client can wrap it into an ordinary using block. If the client is in a clean state a graceful close is done. If the client is in a faulted state a hard abort is done. If an exception is thrown by a service method the client is placed in the faulted state.
Sometimes in our mind the question arise; can we implement multiple service contract in WCF service? And the answer is, Yes we can. Service class implement multiple service interfaces, and then expose each service using a different endpoint.
Windows Communication Foundation (WCF) is a framework for building service-oriented applications. Using WCF, you can send data as asynchronous messages from one service endpoint to another. A service endpoint can be part of a continuously available service hosted by IIS, or it can be a service hosted in an application.
It seems to be a common design pattern in .NET code. Here is a citation from Framework design guidelines
Consider providing method Close(), in addition to the Dispose(), if close is standard terminology in the area. When doing so, it is important that you make the Close implementation identical to Dispose ...
Here is a blog post in which you can find workaround for this System.ServiceModel.ClientBase design problem
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With