wcf entry (9) - exception handling mechanism

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.

Here Insert Picture Description

Example we SayHellospecifies an exceptional method agreement, indicates that information might throw the details ServiceFaultof the exception.

Here Insert Picture Description

And ServiceFaultis a sequence of a tag of data type by the agreement. Here we did a packaging method by which abnormal, and the method name.

Here Insert Picture Description
In the service implementation, we by throwing FaultExceptionthe ServiceFaultpackage, delivered to the client

Here Insert Picture Description

Our client will print out an exception by trycatch

Here Insert Picture Description
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 IsOneWaytoTrue

Here Insert Picture Description

An exception is thrown slightly, the method can not be used the wrong way agreement

Here Insert Picture Description

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:


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.

Creative Commons License 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 .

Published 54 original articles · won praise 0 · Views 2426

Guess you like

Origin blog.csdn.net/htxhtx123/article/details/104231450