Solved

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

Posted on 2006-07-20
6
292 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Article by: Ivo
Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

707 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

18 Experts available now in Live!

Get 1:1 Help Now