I keep getting WCF service is in faulted state on the client side. How should I catch WCF exceptions, without breaking my WCF service?

前端 未结 3 1862
故里飘歌
故里飘歌 2021-02-04 15:48

I have a WCF service multiple UIs consume. When the user is unable to access the database, I get Unauthorised exception from the DB. I don\'t catch the exception on the server

3条回答
  •  灰色年华
    2021-02-04 16:11

    Unhandled exceptions will fault the communication channel. As others have pointed out, a faulted channel must be aborted by calling Abort() - it can't be closed and it can't be used again.

    To address the other part of your question, the "best way to catch the exceptions, log the exception on server side, send the exception details back to the client without breaking the service?", you need to use FaultException Class.

    Additionally, you can use the IErrorHandler Interface to wire up your service host to catch any exceptions that were not otherwise caught (i.e., a global error handler). There are many examples of how to do this on the net - just google for WCF IErrorHandler.

    Here's a couple:

    WCF Exception Handling with IErrorHandler

    WCF Extensibility – IErrorHandler

提交回复
热议问题