Wednesday, June 30, 2010

Leave It To A Programmer...

As an American, I'm not a big fan of watching soccer.

My co-workers, being confused by our win over mexico last year, imagine that watching soccer on the television is a fun past-time and have been trying to get me to show more interest in it.

My co-worker, we'll call him "Jose" to protect his identity, says to me:

I have something for you that i think may get you more interested in soccer...

I quickly reply that the only thing that's interesting about Soccer, is if it's a girl playing Soccer. He sends me a link to an article on the Huffington Post website

After viewing this site, and exchanging some of the normal guy comments back and forth, i say that if she didn't have the nice body she has, i wouldn't find her very attractive. Another co-worker retorts saying that she's prettier than those pictures give her credit for. Now i was only half-kidding about my comments about her not being pretty...in part because most of the pictures (as you've probably saw) show her face in some sort of enraged\cheering expression.

Jose decides to go on the dangerous mission of finding pictures of her on the internet, on our work internet mind you, that are SFW and that might make me think she's pretty.

Upon finding she has a website dedicated to her, of course, he passed the link around to all of us. http://www.larissariquelme.com/

His first comment upon loading the page was nothing less than what we expect from Jose. I'm paraphrasing from memory...

I wonder if she made this site herself, it has a really nice layout! Ooooo i like the sparkly thing she does with Flash for the images.

Yes. His first comments upon going to a website dedicated to a lingerie model, filled with pictures of her in risqué "outfits", is about the layout and design of her website.

Leave it to a Programmer! I love my job!

I do like Twilight, but i still thought this quote from my friend, not to be named, was funny:
Twilight's like soccer. They run around for 2 hours, nobody scores, and its billion fans insist you just don't understand.

Monday, June 21, 2010

Monday, June 7, 2010

Handling WCF TimeoutExceptions "Globally" Part 1

One of the WCF services I've setup at work has a high volume of calls being made through it. The application retrieving this information requires the data to be delivered in a timely fashion and we can't afford there to be timeouts.

Most of the methods have been split out onto separate WCF service instances to better configure their InstanceContextMode and ConcurrencyMode so that we may handle the priority of the importance of the data as well as handling caching.

Due to some clients being many network hops away, we would get random timeouts that we weren't able to control. In addition, sometimes there were high cost (webserver-side, not database) methods and resource consumption would spike causing a temporary queue for data.

I wanted to handle time-outs without having to muck-up my code by putting a try catch around everything. Also since i had split different methods onto different WCF service instances i had multiple clients. So if i made a change in the proxy, i'd have to make it in more than one place, which is bad news for code upkeep.

My solution was to make use of Generic Methods and Service Extensions to create a wrapper of sorts to handle my service calls.

namespace SecretProject.Module.Services
{
    public static class ExceptionService
    {
        public static T TryWebMethod<T, TClient>(this TClient client, string methodName,params object[] parameters)
        {
            try
            {
                    MethodInfo methodInfo = client.GetType().GetMethod(methodName);
                    return (T) methodInfo.Invoke(client, parameters);
            }
            catch (Exception err)
            {
                if (err.InnerException is TimeoutException)
                {

                }
            }
            return default(T);
        }
    }
}

The above code would allow me to call the method and handle globally the TimeOutException, if thrown.

In this example, assume the GetProgrammers, from dataClient (of type CommonServiceClient), returns a List of the class Programmers
This would change my usage of the method from something like:

dataClient.GetProgrammers(parameter1, paramter2);


To this:

dataClient.TryWebMethod<List<Programmers>,CommonServiceClient>("GetProgrammers",parameter1, paramter2);

This allows us to now handle logging, rolling over to a backup server, requiring user interaction to make another attempt, or whatever you may want to handle here! And this will all be done without having to muck-up your code around every service call.

In Part 2, I will show how I handle rolling over to a backup server to temporarily balance the "overflow of the data queue" on that one server.