tags:

views:

1059

answers:

2

I have an asynchronous WCF service using nettcpbinding. And I send a bunch of requests to it and get result by invoking EndDoWork() in my callback. If EndDonWork throw a exception once, all the invocation after that will throw exception said: communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.

I think that's something close the connection because of the first exception. My question is: 1. what decide this behavior? If I use basicHttpBinding, the later invocation of EndDoWork work well. Is it related with keepAlive support? 2. Is there any property of configuration item I can set to ask service reconnect automatically?

+1  A: 

If I remember correctly, you can avoid the channel faulting if you declare the Fault in the operation contract.

For example:

[ServiceContract]
public interface IService
{
    [OperationContract]
    [FaultContract(typeof(MyDefinedFault))]
    void Operation();
}

As you have already declared MyDefinedFault in the Operation contract if you throw that from the service, the channel is not going to fault (unless of course you are using the System.ServiceModel.Description.ServiceDebugBehavior.IncludeExceptionDetailInFaults=true that may fault the channel anyways).

+1  A: 

Where is the MyDefinedFault class. how to define this class.

This is a class you create yourself. Can be very simple such as: [DataContract] public class MyDefinedFault { [DataMember] public string ExceptionString { get; set; } public MyDefinedFault(string exString) { ExceptionString = exString; } }
WillH