简体   繁体   English

使用批处理操作处理WCF异常

[英]WCF Exception handling with batch operations

I need an hint on this architectural problem. 我需要一个关于这个架构问题的提示。

My application calls different wcf services that perform specific tasks returning a list of model objects. 我的应用程序调用不同的wcf服务,这些服务执行返回模型对象列表的特定任务。

Say, I have a service which polls stock exchange titles returning a List<SeTitle> . 说,我有一个服务,轮询股票交易所标题返回List<SeTitle> [Purely fictional example, I'm reading a book on this subject] [纯粹是虚构的例子,我正在读一本关于这个主题的书]

If an exception happens in one or few elements of this list I have two options in the wcf service: 如果此列表中的一个或几个元素发生异常,则wcf服务中有两个选项:

  • catch the exception, log it and return the List<>, but in this way I'll lose evidence of all the faulty items in my application. 捕获异常,将其记录下来并返回List <>,但是这样一来,我将失去应用程序中所有错误项的证据。
  • throw an exception on first error, but in this way I won't receive any info even if only one item was "faulty". 在第一个错误上引发异常,但是通过这种方式,即使只有一个项目“出现故障”,我也不会收到任何信息。

My will is to go for a third option, meaning that I'll always return my List but with the evidence of faulty items. 我的意愿是选择第三个选项,这意味着我将始终返回我的列表,但要提供有缺陷的项目的证据。

My idea is to let all my model object extend a simple interface like (pardon names, they are horrible) 我的想法是让我所有的模型对象扩展一个简单的接口,例如(对不起的名字,它们很可怕)

public interface IWcfReturnObject
{
    public List<WarningModel> Warnings;
}

and

public class SeTitle : IWcfReturnObject

in a such a way each element of the list could have an associated List of Warnings/Error to be returned to the application and then to the interface. 以这种方式,列表的每个元素可以具有关联的警告/错误列表,以将其返回给应用程序,然后返回给界面。

My questions are: 我的问题是:

  • Is my question clear to understand?! 我的问题清楚易懂吗? ;) ;)
  • Do you think my desire (receive all element from wcf with warnings attached) is architecturally good? 您认为我的愿望(从带有警告的wcf中接收所有元素)在体系结构上是否良好?
  • Do you think it exists a better approach to solve this problem? 你认为它存在解决这个问题的更好方法吗?

Thanks 谢谢

M. M.

EDIT: I was doing research and looking at the first answer I think it is useful to give one solution I found on the NET 编辑:我正在做研究,并看着第一个答案,我认为给出我在NET上找到的一个解决方案很有用

Possible Solutions 可能的解决方案

  1. My way 我的方式
  2. Log with some kind of correlation and refer it on the business layer as decyclone suggested 记录某种相关性,并在业务层上将其引用为decyclone建议
  3. AggregateException AggregateException

I think you should log your exceptions/errors/warnings instead of sending them along with result data. 我认为您应该记录您的异常/错误/警告,而不是将它们与结果数据一起发送。 You can always refer to log and maybe create an interface to see error log. 您始终可以参考日志,也可以创建一个界面来查看错误日志。 But, common result data should not be mixed with exception data. 但是,常见结果数据不应与异常数据混合。

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

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