February 22, 2010

.NET 4.0 WCF: Issues with WebFaultException

         In WCF 3.5,  WebHttpBinding  doesn't return faults in expected response format. It ignores the format specified in the contract, and returns the error in html format. I was expecting error to be in the format specified in the WebGet/WebInvoke. For one of my project with WCF RESTful/JQuery solution stack, I end up writing a custom error handler implementing IErrorHandler to receive the fault in the desired JSON format.

         .NET 4.0 introduces a class WebFaultException<> to tackle this formatting issue. What all you have to do is throw the fault using this class, and you get the HTTP response in correct desired format. Digging deep the WebHttpErrorHandler with Reflector, I found that formatting decision is made based on type of the fault thrown.The expected fault should of type  IWebFaultException. WebFaultException implements IWebFaultException.

        I see few problems with this solution. If I forget to use WebFaultException in one of my operation implementation, I am screwed, I get response in same old html format. Deriving message format from the implementation(i.e. service behavior) seems to me odd.  Second one, If I have to go with this solution and to retire my custom error handler, I will have to modify code in several places changing use of FaultException to WebFaultException. These two issues making me to think whether I should stick with custom error handler solution unless situtation demands for different status codes. With WebFaultException, you can set http status code.   I was just throwing one status code BadRequest, and application specific status codes were in the fault details object.

February 16, 2010

Improving learning skills

             In Year 2009, I luckily found two books  How to Read a Book and Pragmatic Thinking & Learning. These books helped me in enhancing my learning abilities.  I wish I had these books especially How to Read a Book in my high school curriculum. But it is never too late.In this book,  You would find several key skills such as how to actually own a book not just physical ownership, note making, how to decide quickly whether a book is worthy of your valuable time, and when to agree/disagree with author, the absent teacher so on.Book talks about use of information in book cover, preface, and table of contents.
                 
                 With these new skills in reading, I am rereading my favorite books. Lot of satisfaction these days I have in reading. 

                  If How to Read a Book makes you a demanding reader by empowering you with the necessary skills in reading difficult books,  Pragmatic Thinking & Learning helps you in taking care of your inner learning and thinking processes. Writing a book on thinking is tough, but the author Andy Hunt has done fantastic job in covering the subject.  If you don't know Andy Hunt, He is one of the signatory of agile manifesto, and author of several books. This book gives you not only practical tools in improving your thinking and learning, but also gives you tools for your awareness.  What matters most, at least to me, is this awareness. Tools might go, but this awareness stays with you, and helping you in growing your mind. Book talks about use of Mind maps, Screencasts, Podcasts, Blogging, and Wiki, and how you can integrate these tools in to your learning & thinking process.
                                 
                  I was reluctant to blog, but these books changed my view, and I am here writing first post for my blog.  I am thankful to the authors Andy Hunt, and Mortime  J. Adler. 

            
                For those, who like to read  but don't have time, I recommend you  Pomodoro technique.  This simple technique helps you in gaining quality of your time. Best of Luck.