Solved

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

Posted on 2006-07-20
6
300 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

867 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now