This article demo has been uploaded to GitHub: xinyuehtx / WCFdemo
This blog will explain how to set up the service of abnormal feedback
Introduced on a blog wcf entry (9) - exception handling mechanism _wcf, c # _ Huangteng Xiao's blog -CSDN blog how to use error feedback agreement specified exceptions, but often there is some abnormality is unexpected. This one will explain how to use the service back abnormal behavior is not specified
Abnormal feedback is not specified
Here we make some modifications to the previous example
First, remove the incorrect service interface Agreement
In the service implementation, set IncludeExceptionDetailInFaults
to True
. (If you only expect feedback anomalies in the commissioning phase, can be used ServiceDebugBehavior.IncludeExceptionDetailInFaults
instead)
And directly thrown in the realization of the operation Agreement
In this time we changed to capture clientFaultException
We caught exception in the client, and Detail
service operations to find the actual properties of anomalies
note
This example does not specify exceptions and handle on a blog wcf entry (9) - exception handling mechanism _wcf, c # _ Huangteng Xiao's blog -CSDN blog in the process specified exceptions, the principle is the same.
So the question is the same, we can not handle OneWay
summary
We studied the WCF service IncludeExceptionDetailInFaults
, its features are
- You can specify the server error feedback the client does not need to specify the type of display
- You can configure debug mode
- One-way operation can not handle
Reference links:
- How to: Declare error in Service Contracts - Microsoft Docs
- Define and specify the error - Microsoft Docs
- Specified in the agreement and service and processing errors - Microsoft Docs
- 2019-1-29-wcf entry (9) - huangtengxiao
- wcf entry (9) - exception handling mechanism _wcf, c # _ Huangteng Xiao's blog -CSDN blog