locked
WCF services in faulted state. RRS feed

  • Question

  • I wonder what are the consequences of not calling Abort on the client. Our services are accesible to many users globally and I cannot be sure if they propely close/abort connections.

    Does WCF host recycle/kill faulted service instances after certain time or the only way is to recycle app pool on IIS which we do once a day?

    Friday, September 9, 2011 3:17 AM

Answers

  • I think you are talking about Service Channel Fault state. 

    When your service operation throws an exception you need to catch this exception in the service operation and gracefully return something to your client. Otherwise you need to implement and fault contract and return it to client. Then your client should be capable of handling this fault contract. If you dont do this, if there is any exception, the communication channel between your service and client will be in a faulted state. Any subsequent call through this channel will let your Service Fault or Communication Fault exception. 

    A channel can be faulted due to some protocol exception, network issue or binding issue like timeout etc. 

    If you dont close or abort the channel in your client, you wont be able to call the service operation unless your reestablished a new communication channel between your service and client. 

    WCF host is uneffected by channel fault. 

     


    Tanvir Huda Application Architect/Consultant
    • Marked as answer by Yi-Lun Luo Friday, September 16, 2011 9:16 AM
    Friday, September 9, 2011 4:05 AM
  • It is sugested to use Abort() on the client. But if any of client do not call Abort() function and your service is in faulted state, WCF service handles this based on type of your service.

     

    This is the defult behaviours of WCF service with Fault state.

     

    For per-call services:

    The service instance is disposed and the proxy throws a FaultException on the client side. All exceptions of this type will fault the channel so that the same proxy can no longer be uses. In fact, attempting to reuse or even dispose the proxy may throw the following:

     

    An exception of type 'CommunicationObjectFaultedException' was caught...

    Message: The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.

     

    For sessionful services:

    The session is terminated, the service instance is disposed and the channel will be in the faulted state, thus the proxy cannot be reused.

     

    For singleton services:

    The channel is faulted and the same proxy cannot be used. However the singleton instance will live on.

     

    In all cases mentioned above, the channel moves to the Faulted state. This is however not the case when a FaultException or a FaultException<T> is used. Therefore it is strongly recommended to throw a FaultException or one of its derivatives.


    Lingaraj Mishra
    • Proposed as answer by Cecil du Toit Friday, September 9, 2011 10:04 AM
    • Marked as answer by Yi-Lun Luo Friday, September 16, 2011 9:16 AM
    Friday, September 9, 2011 8:38 AM

All replies

  • I think you are talking about Service Channel Fault state. 

    When your service operation throws an exception you need to catch this exception in the service operation and gracefully return something to your client. Otherwise you need to implement and fault contract and return it to client. Then your client should be capable of handling this fault contract. If you dont do this, if there is any exception, the communication channel between your service and client will be in a faulted state. Any subsequent call through this channel will let your Service Fault or Communication Fault exception. 

    A channel can be faulted due to some protocol exception, network issue or binding issue like timeout etc. 

    If you dont close or abort the channel in your client, you wont be able to call the service operation unless your reestablished a new communication channel between your service and client. 

    WCF host is uneffected by channel fault. 

     


    Tanvir Huda Application Architect/Consultant
    • Marked as answer by Yi-Lun Luo Friday, September 16, 2011 9:16 AM
    Friday, September 9, 2011 4:05 AM
  • It is sugested to use Abort() on the client. But if any of client do not call Abort() function and your service is in faulted state, WCF service handles this based on type of your service.

     

    This is the defult behaviours of WCF service with Fault state.

     

    For per-call services:

    The service instance is disposed and the proxy throws a FaultException on the client side. All exceptions of this type will fault the channel so that the same proxy can no longer be uses. In fact, attempting to reuse or even dispose the proxy may throw the following:

     

    An exception of type 'CommunicationObjectFaultedException' was caught...

    Message: The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.

     

    For sessionful services:

    The session is terminated, the service instance is disposed and the channel will be in the faulted state, thus the proxy cannot be reused.

     

    For singleton services:

    The channel is faulted and the same proxy cannot be used. However the singleton instance will live on.

     

    In all cases mentioned above, the channel moves to the Faulted state. This is however not the case when a FaultException or a FaultException<T> is used. Therefore it is strongly recommended to throw a FaultException or one of its derivatives.


    Lingaraj Mishra
    • Proposed as answer by Cecil du Toit Friday, September 9, 2011 10:04 AM
    • Marked as answer by Yi-Lun Luo Friday, September 16, 2011 9:16 AM
    Friday, September 9, 2011 8:38 AM
  • "WCF host is uneffected by channel fault. "

    Thank You Tanvir. This what I was looking for. Somehow my client have to recycle our WCF services more than once a day, because they become unaccesible/faulted. I was thinking that could be because they don't call Abort if the timeout occurs, but also Close is never called, so I thought that they could hanging there for a while. They always create establish new communication channel for every call they do (they use proxy ServiceContractClient).

    As I understand I don't have to call Close() either, because ContractClient will be disposed anyway once I exit method scope.

    It will make our code simpler then, because I always followed:

    try

    {

        ...

        client.Close();

    }

    catch (Exception e)

    {

        ...

        client.Abort();

        throw;

    }

    and then in outside method display error to user, but in this point try/catch is useless adding unecessary code. 

     

    Tuesday, December 13, 2011 10:40 PM
  • For sessionful services:

    The session is terminated, the service instance is disposed and the channel will be in the faulted state, thus the proxy cannot be reused.Exception is following:


    An exception of type 'CommunicationObjectFaultedException' was caught...

    Message: The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.

     

    Can I re-initialize the variable of client and reconnect to the service.What will be the way of doing this.

    Plz give solution fast.


    SaiVaibhav@Acumen

    Tuesday, November 20, 2012 12:40 PM