How can I get WCF FaultException when server returns an HTTP 401?

依然范特西╮ 提交于 2019-12-04 15:21:57

You cannot. You will only get a FaultException if a .NET exception occured in the server side code and has been caught.

HTTP 401 is "Access in unauthorized" - you'll get that exception before you even reach the server code --> this will always be a MessageSecurityException - never a FaultException (and there's no way to magically turn that into a FaultException, either).

Any exception that occurs before the execution even reaches the server code (things like EndpointNotFoundException or TimeoutException) are never fault exceptions.

All the WCF specific exceptions descend from a common base class, however - CommunicationException. So maybe you can handle that as a fallback.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!