https://docs.microsoft.com/en-us/dotnet/framework/wcf/wcf-error-handling

The errors encountered by a WCF application belong to one of three groups:

  1. Communication Errors

  2. Proxy/Channel Errors

  3. Application Errors

Communication errors occur when a network is unavailable, a client uses an incorrect address, or the service host is not listening for incoming messages. Errors of this type are returned to the client as CommunicationException or CommunicationException-derived classes.

Proxy/Channel errors are errors that occur within the channel or proxy itself. Errors of this type include: attempting to use a proxy or channel that has been closed, a contract mismatch exists between the client and service, or the client’s credentials are rejected by the service. There are many different types of errors in this category, too many to list here. Errors of this type are returned to the client as-is (no transformation is performed on the exception objects).

Application errors occur during the execution of a service operation. Errors of this kind are sent to the client as FaultException or FaultException<TDetail>.

Error handling in WCF is performed by one or more of the following:

  • Directly handling the exception thrown. This is only done for communication and proxy/channel errors.

  • Using fault contracts

  • Implementing the IErrorHandler interface

  • Handling ServiceHost events

Fault Contracts

Fault contracts allow you to define the errors that can occur during service operation in a platform independent way. By default all exceptions thrown from within a service operation will be returned to the client as a FaultException object. The FaultException object will contain very little information. You can control the information sent to the client by defining a fault contract and returning the error as a FaultException<TDetail>. For more information, see Specifying and Handling Faults in Contracts and Services.

IErrorHandler

The IErrorHandler interface allows you more control over how your WCF application responds to errors. It gives you full control over the fault message that is returned to the client and allows you to perform custom error processing such as logging. For more information about IErrorHandler and Extending Control Over Error Handling and Reporting

ServiceHost Events

The ServiceHost class hosts services and defines several events that may be needed for handling errors. For example:

  1. Faulted

  2. UnknownMessageReceived

For more information, see ServiceHost

最新文章

  1. 利用drozer进行Android渗透测试
  2. c#读取文本文档实践4-读入到list泛型集合计算后写入新文档
  3. 深入浅出话VC++(3)——VC++实现绘图操作
  4. debian , ubuntu 截取下拉菜单
  5. php三维数组变二维数组
  6. SVM中图像常用的HOG特征描述及实现
  7. python操作二进制文件
  8. scjp考试准备 - 3 - 关于Arrays
  9. SPOJ 3267 求区间不同数的个数
  10. hdu1520(树形dp)
  11. 使用ServletContext读取properties配置文件
  12. Git学习 -- 搭建Git服务器
  13. 使用Swift开发一个MacOS的菜单状态栏App
  14. jquery提示sucess
  15. 后台文本编辑器KindEditor介绍
  16. A+B Problem(再升级)
  17. cefglue Flash
  18. 没有什么,开发ASP.NET时随便写写,想到什么写什么
  19. 【转】移除HTML5 input在type=&quot;number&quot;时的上下小箭头
  20. android studio使用真机测试时点击Debug调试模式时报Error running app:No target device found,点击运行模式却是启动正常的

热门文章

  1. Token 认证
  2. 使用lua实现try-catch异常捕获
  3. CentOS7 redhat7 linux系统1分钟安装Zabbix web 监控 服务器
  4. SpringBoot使用RestTemplate 摘要认证
  5. Linux快速访问多个目录
  6. Django基础之简介(二)
  7. restTemplate工具类
  8. Simple GB28181 System
  9. JS window对象 返回前一个浏览的页面 back()方法
  10. python基础内置函数