Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Closing and Disposing a WCF Service

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?

like image 993
Esteban Araya Avatar asked Aug 23 '08 02:08

Esteban Araya


People also ask

How do I dispose of WCF client?

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.

Can WCF service have multiple endpoints?

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.

What is meant by WCF service?

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.


1 Answers

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

like image 61
aku Avatar answered Sep 22 '22 16:09

aku