Close and Abort in custom service channel

1.2k views Asked by At

My client is using one WCF service which is throwing an exception (EXCEPTION: The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state). All subsequent calls throwing an same exception.

I read on internet that client need to close()/Abort() channel, this will solve the problem. is it completely right?

Also I am using customer serviceChannel factory provided by service developers. When I create channel it does not show the close and abort methods. So how do I get these close and abort methods when I create custom service channel instance on client side?

1

There are 1 answers

1
Yiğit Yener On BEST ANSWER

Assuming that you have a proxy instance that implements the IClientChannel interface, here is a way (hopefully the right way) to use it.

IClientChannel clientChannel = (IClientChannel)proxy;
bool success = false;

try
{
    // do something with the proxy
    clientChannel.Close();
    success = true;
}
finally
{
    if (!success)
    {
        clientChannel.Abort();
    }
}

You may also want to check this. You can wrap your operations using a shared class or function.