Closing WCF connection

Viewed 32072

We are using WCF service

on the client side we are planning to explicitly close the connection It seems there are more then one way of closing

Sample1: In the finally block of the WCF service consumption use

if (client.State == CommunicationState.Faulted)
{
  client.Abort();
}
client.Close();

Since if the service is in fault state we will not be able to call close()

Sample2:

using(ClientProxy proxy = new ClientProxy())
{   
  //call your service methods
}

in sample2 i am not sure what will happen if the service is in fault state, will it throw error closing the connection?

4 Answers
Related