简体   繁体   English

记录WCF API错误(最佳方式)

[英]documenting WCF API errors (Best way)

I know, it's too late now and we should have created all possible error list before. 我知道,现在已经太晚了,我们之前应该创建所有可能的错误列表。 We couldn't do this before bcse we were using another API to server our API and that third party API provided us german messages for any error. 在我们使用其他API来为我们的API提供服务之前我们无法做到这一点,并且第三方API为我们提供了任何错误的德语消息。

Now one of our client has requested to provide them the list of possible error messages for them to handle it accordingly. 现在我们的一个客户端已经请求向他们提供可能的错误消息列表,以便他们相应地处理它。

Could you please provide me ideal way to document the error lists. 能否请您提供记录错误列表的理想方法。 I was about to start with an excel spreadsheet but reckon, there should be some better way. 我即将开始使用excel电子表格,但估计应该有更好的方法。

In WCF you should be using a FaultException. 在WCF中,您应该使用FaultException。 Effectively you derive from FaultException and these will be serialized over the wire. 实际上,您从FaultException派生,这些将通过线路序列化。

That way your service will correctly pass exceptions down the wire (eg. serialized to SOAP) which your consumers can deal with. 这样,您的服务将正确地将异常传递给消费者可以处理的异常(例如,序列化为SOAP)。

That's why it's there. 这就是为什么它在那里。 But given you are in production you might not have a choice. 但鉴于你正在制作中,你可能没有选择余地。

There is a standard C# XML documentation syntax you could use, explaining what each method can throw. 您可以使用标准的C#XML文档语法,解释每种方法可以抛出的内容。 See: http://msdn.microsoft.com/en-us/library/b2s063f7(v=VS.100).aspx 请参阅: http//msdn.microsoft.com/en-us/library/b2s063f7(v = VS.100).aspx

You can then present the docs using a tool such as Sandcastle , which will spit out MSDN-style documentation. 然后,您可以使用Sandcastle等工具展示文档,该工具将吐出MSDN样式的文档。

Tools like GhostDoc can help you write these more quickly. 像GhostDoc这样的工具可以帮助您更快地编写这些工具

Since you're already in production, I'd write a patch for the code and shelve it in source control. 由于你已经在制作中,我会为代码编写一个补丁并将其搁置在源代码控制中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM