This article demo has been uploaded to GitHub: xinyuehtx / WCFdemo
This blog will explain how to set up the service of abnormal feedback
Among multi-process debugging, or client / server FBI, very troublesome point is how to locate an anomaly?
Client problem or server problem, or is it the channel problem?
This time by abnormal abnormal information back to the server to the client feedback occurs it is very important.
Error Agreement (FaultContract)
Service operations can mark an error agreements show that this method might specify error.
Example we SayHello
specifies an exceptional method agreement, indicates that information might throw the details ServiceFault
of the exception.
And ServiceFault
is a sequence of a tag of data type by the agreement. Here we did a packaging method by which abnormal, and the method name.
In the service implementation, we by throwing FaultException
the ServiceFault
package, delivered to the client
Our client will print out an exception by trycatch
Success can see abnormal output
The risk of error Agreement
Smart students have already noticed, we just test the operation of the agreement is (synchronous method) request reply mode. What then for the one-way pattern here?
We will try IsOneWay
toTrue
An exception is thrown slightly, the method can not be used the wrong way agreement
summary
We studied the mistakes agreement WCF service, its features are
- Basic information can specify the server error echo client, you can pass all managed through a simple package of abnormal
- Objects may be passed agreement needs serialized data protocol
- One-way operation can not handle
Reference links:
- How to: Declare error in Service Contracts - Microsoft Docs
- Define and specify the error - Microsoft Docs
This article will be updated frequently, please read personal blog Original: https://xinyuehtx.github.io/ , in order to avoid misleading the old error of knowledge, and a better reading experience.
This work is Creative Commons Attribution - NonCommercial - ShareAlike 4.0 International License Agreement for licensing. Welcome to reprint, use, repost, but be sure to keep the article signed by Huang Tengxiao (containing links: https://xinyuehtx.github.io/ ), shall not be used for commercial purposes, be sure to publish the same work based on the paper license modification. If you have any questions, please contact me .