简体   繁体   中英

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.

Say, I have a service which polls stock exchange titles returning a 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:

  • 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.
  • 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?
  • Do you think it exists a better approach to solve this problem?

Thanks

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

Possible Solutions

  1. My way
  2. Log with some kind of correlation and refer it on the business layer as decyclone suggested
  3. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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