Search code examples
wcfwcf-client

WCF Faulting forces me to restart both server and client


I use WCF for an ASP.Net MVC 2 Application. And when the service has a fault I need to keep restarting both server and client. The channel is faulted is the error.

Why is that happening? Why do I get this error and what do you recommend me to avoid the habit of restarting, due to the fact that is time consuming.

edit1: I use using block to host a service. I will provide a little program with sample code to reproduce the problem soon.

edit 2: I use a self hosted WCF Service Library

[ServiceContract]  
public interface IAuctionService  
{  
    [OperationContract]  
    [FaultContract(typeof(DatabaseFault))]  
    void SaveCategory(CategoryDTO category);  

    [OperationContract]  
    [FaultContract(typeof(DatabaseFault))]  
    List<CategoryDTO> ListCategories();  

    [OperationContract]  
    [FaultContract(typeof(DatabaseFault))]  
    CategoryDTO GetCategoryById(long id);  
}

And in the client I have added a Service References to this service.

Should I handle all type of exceptions and throw them using faults to client?


Solution

  • You should not wrap ServiceHost in a using block!

    See here for details: http://www.danrigsby.com/blog/index.php/2008/02/26/dont-wrap-wcf-service-hosts-or-clients-in-a-using-statement/

    UPDATE

    Regarding sending faults to your callers: Yes generally speaking you should return exceptions on the service as SOAP faults to the caller. This is what the SOAP fault was designed for.

    However, you should define a fault contract for every type of fault you want to return the caller.

    As guideline you should only send faults which the caller can handle meaningfully and recover from (either by retry or some other action).

    If you have a fault on the service where the channel to your caller has aborted then you don't need to explicitly send faults, WCF will do this for you.