tags:

views:

1806

answers:

2

We get

"""The communication object, System.ServiceModel.Channels.ServiceChanne, cannot be used for communication because it is in the Faulted state."""

message when we close the application. Can anyone tell me how to fix it? We know it is communication channel trying to close but it is not able to close due to service not available or in faulted state.

All I can say is, when the service is not available, but the Garbage collector trying to destroy the object, the communication objects is calling its service Close function. There we get exception.

A: 

Take a look at the proxies project here.

We had a similar problem and this technique fixed it. It basically involves inheriting from a class which will automatically recreate the channel if it faults.

Codebrain
+2  A: 

When you ask a question about an exception, you should post the entire exception, including all InnerException instances. You should catch the exception, display ex.ToString(), then rethrow the exception with "throw":

try {
    // Do whatever causes the exception
} catch (Exception ex) {
    Console.WriteLine(ex.ToString());  // Or Debug.Print, or whatever
    throw; // So exception propagation will continue
}

In this case, I wonder if you have a using block around your proxy instantiation:

using (var proxy = new WcfProxyClient())
{
    // Use of proxy
}

There is a design flaw in WCF that makes this about the only place in .NET where you should not use a using block. Instead, you need to do it by hand. See http://www.iserviceoriented.com/blog/post/Indisposable+-+WCF+Gotcha+1.aspx.

John Saunders