Search code examples
c#wcffaultself-hosting

How to throw FaultException from self hosting wcf service?


I'm planning to host the service in windows service, but I'm thinking about the problem described in the title. Anyone had similar issue? Thanks

Update

The problem is that when you throw an exception in WinForms/WPF/Win Service app, the program crashes and you'll have to restart it.


Solution

  • An exception does not always crash your server. Even an unexpected server-side exception will be transferred to the client. It is considered more severe than an expected one though, faulting the channel.

    The basic idea is to include the expected exceptions (faults) in you interface contracts . There are many ways to do that, here is an introduction article.

    And of course you need decent exception handling at the server.