views:

25

answers:

2

If my service encounters an error, I want that thread to return an error and terminate, but later requests should still work fine. How do I do this? If I have an unhandled exception, it will get passed back to the client, but then the service stops.

A: 

What kind of unhandled exception? Unless the exception is a terminating exception (Stack Overflow or the like), the ServiceHost should continue to respond to subsequent requests.

JeffN825
I'm throwing FaultException<MyException>
Xodarap
A: 

By default, each request gets their own instance of your service implementation, and thus, an error in one of those request handlers shouldn't influence the others.

So in WCF's default behavior, each request gets a brand-spanking new instance of your service class, which then handles the request, and terminates - whether an exception occurs or not. The possible problem is with the exception - if you let it pass back to your client "unfiltered", then the channel (the communication link between your client and the server) might be "faulted" and thus unusable.

If you wrap all your service exceptions into FaultException or FaultException<T>, then your channel between client and server should be just fine. In order to catch all possible errors on the server, check into implementing the IErrorHandler interface on your service class.

marc_s
What if I use <serverthrottling maxConcurrentInstances="1">?
Xodarap
In that case, you only ever have one instance concurrently - but each request still gets its own copy of the service class.
marc_s