开发者

C# WCF service throws an error but continues

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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜