Link to home
Start Free TrialLog in
Avatar of PoeticAudio
PoeticAudio

asked on

Hypothetical situation that I wouldn't know exactly how to handle...

Hello,

I was thinking the other day about how I would solve the following problem, but I just couldn't seem to come up with a really logical solution... or at least what I would think is a best practice. How would you handle the following?

Say I have winform client apps... any number of them. Lets say that this app has a couple web services. Okay, now lets say that one of the web service is like a broker web service... it also contains other web services. The client isn't aware of all the web services the broker service is hitting, the broker is responsible for knowing that. The point here is that we have a web service which may hit another web service, could be anything. Now, here's the hard part... getting all of the errors in case one happens. So client requests data from Service1. Service one then hits Service2, Service3 and Service4. Service3 errors out because the server that it's on is down. Service4 errors out because of a database issue or something. I want to return something back to the client listing all of the details of why the transaction failed (like in a log file or something), like

Success: Transaction to Service1 was successful
Success: Transaction to Service2 was successful
Error: Could not access Service3.
Error: Duplicate Primary Keys in Service4.


How do I handle this? Lets take it to another level and say that Service2 in itself might contain other services, so the transaction to Service2 was successful, but the transaction to Service2a failed for some reason.

The trick is keeping a single log file that contains all of the details on why various services failed, even if those service contain services which may have failed for some reason. What's the best way to handle something like this? I can't have every method return a bool if it passes or fails because it might already have a return value... So I can't just call GetData on Service2 and return a bool whether it passed or failed because it might already return a dataset... Does this make sense?


Keep in mind this is hypothetical, but I am just wondering what the best practice is in handling this type of scenerio.

Thanks!
- Steven
Avatar of PoeticAudio
PoeticAudio

ASKER

By the way here is what I came up with (just not sure if it's the best way)

My solution is that each service would have it's own transaction log. Whenever something was successful, or something failed it would append this to the transaction log and then whatever consumes that service would have a transaction log too, and everyting would append... for example

Service1
------------------------------------------------------
public DataSet DownloadPendingFiles(params)
{
    Service2.GetData(params);
    this.TransactionLog += Service2.TransactionLog;

    Service3.CreatePayment(params);
    this.TransactionLog += Service3.TransactionLog;
}


Client app that calls Service1
-------------------------------------------------------
Service1.DownloadPendingFiles(params);
this.TransactionLog += Service1.TransactionLog;

//some sort of logic to handle TransactionLog
if(LogFileHasErrors(TransactionLog))
{
      //do whatever;
}


you see, the client calls Service1, which in turn calls Service2 and 3. If those have errors it appends that info to Service1s TransactionLog, in the end the client will have all errors from all services, because the TransactionLogs sorta... stack up I guess you would say.


Just not sure if this is any good or not.

Thanks,
If the "inner" services don't throw exceptions and always just return, then there is no "good" way to do what you are describing.

The "good" way would be for each service to actually throw exceptions, and then let the client (whether it is another service, or an app) handle (e.g. log) the exception in whatever way it wishes.
SOLUTION
Avatar of NunoGodinho
NunoGodinho

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'd say instead of returning a bool type, return a object[] type. The elements in the object array can then be anything. Thus retuning a whole package of info regarding what had happend during the call to Service3. The return return object can tell you for example:
obj[0] : failed/success
obj[1] : error message
obj[2] : error code
obj[3] : some other usefull return

This obviously means that the size of the package returned might be big; in terms of bool bytes vs. object[] bytes.
i hope this helps.

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial