Solved

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

Posted on 2006-07-20
6
309 Views
Last Modified: 2010-04-16
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
0
Comment
Question by:PoeticAudio
6 Comments
 
LVL 6

Author Comment

by:PoeticAudio
ID: 17151954
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,
0
 
LVL 24

Expert Comment

by:Justin_W
ID: 17155652
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.
0
 
LVL 6

Assisted Solution

by:NunoGodinho
NunoGodinho earned 400 total points
ID: 17158643
I agree with Justin W, the best way should be letting each service to throw it's own exception because than you'll have all the information regarding each one, but if you want just a custom error message than i think the best way should be making a new serializable class that will be the return class of the service methods that would contain the ErrorMessage and the DataSet returned and so you can build all that you want just using your custom errorMessages and no stack trace.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 1

Assisted Solution

by:flashaoy
flashaoy earned 100 total points
ID: 17159855

In your scenario, I believe the best practice would be messages. Each message contains the sender info, and the error message. The protocole, or implementation is totally up to you. There are million ways to communicate between different applications and services.

Hints:
- You can return success/failure messages, or only failure messages.
- You can put your messages in a queue and check it periodically, or handle it promptly.
- You can send the error message in the service output, or send it in a private stream.

0
 
LVL 1

Expert Comment

by:flashaoy
ID: 17159857
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.

0
 
LVL 6

Accepted Solution

by:
NunoGodinho earned 400 total points
ID: 17161667
I'll say the best way should be having a custom class created to have 2 things, the errorMessage and the return value that you want, and have the methods return it, because this would release you from the overhead of having the exceptions stack trace that can become huge, and you could get your code clean and simple. The comment you flashboy is one option but in my humble opinion it would be better with the custom class to encapsulate all properties.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

823 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question