Thursday, March 20, 2014

Display buzy icon during windows client web service call .Net 4.5

Think of a situation where you encounter delay when performing remote service calls from your thick client. For example a windows forms application calling a long running process. Your user might have no clue of what is going on with their application. So it is very important at-least to let the user know something is going behind the scenes. One option is to use a busy cursor when performing a service call and hide when the service call is done. As a developer this can be achieved in several ways. But we need to look into the best possible option to fulfill this requirement in a generalized way.

Since this requirement is common and we will have to duplicate code in each place where the application calls a service, there is an elegant common solution to this. 

Whenever we need to intercept service calls to and from client and the server, .Net framework has provided necessary tools with extension points to tap into the service call and perform actions.


Take a look at Message Inspectors at MSDN


http://msdn.microsoft.com/en-us/library/aa717047(v=vs.110).aspx


We can use the BeforeSendRequest method to display the buzy cursor and AfterReceiveReply to hide the wait cursor

Thursday, June 27, 2013

Custom WCF Bahavior GOTCHA

WCF also provides a higher-level runtime that sits on top of the channel layer, targeted more at the application developer. It is often referred to throughout the WCF documentation as the service model layer. This higher-level runtime consists primarily of a component called the dispatcher (within the context of a service host) and a component called the proxy (within the context of a client). The dispatcher/proxy combination serves one primary purpose—to translate between WCF Message objects and Microsoft® .NET Framework method calls (see Figure). These components follow a well-defined sequence of steps to perform this process, and at each step along the way they provide extensibility points that you can plug into. You can use these extensibility points to implement a wide variety of custom behaviors including message or parameter validation, message logging, message transformations, custom serialization/deserialization formats, output caching, object pooling, error handling, and authorization, to name a few. Here I'll focus on the implementation of these types of custom behaviors
Figure : WCF Runtime Architecture

When you add a custom behavior to a WCF service to intercept calls before the operation is invoked, you need to add the Fully-Qualified Type Name (FQTN) into the web.config file like the following example.

<behaviorExtensions><add name=”MessageInspector” type=”MessageInspector.MessageInspectorEndpointBehaviour, MessageInspector Version=1.1.0.0, Culture=neutral, PublicKeyToken=2a8e0f2687fa1def″ /></behaviorExtensions>

How to find the Fully Qualified Assembly Name(FQAN) of a GAC registered assembly called 'MessageInspector'?

Command: GACUTIL.EXE /L MessageInspector
Result = MessageInspector, Version=1.1.0.0, Culture=neutral, PublicKeyToken=2a8e0f2687fa1def, processorArchitecture=MSIL


However if you then add the type name to that FQAN, the interceptor fails to execute. Why?
Well see the processor architecture directive at the end? REMOVE IT.
For some reason, Microsoft are doing a string comparison on the FQTN name when determining whether the WCF custom behavior is valid. As a result your WCF services will stop working.

Friday, April 19, 2013

Clean Sticky Footer

We had a requirement in one the of the web applications i am working on to have the footer stick to the bottom no matter what the height of the page content is. When i googled for this task, there are many solutions out there. In fact I experimented several of them to find that the footer hides some of the page contents when the content is larger than the height of the  page content height.

Finally found the solution at cleanstickyfooter which worked like charm.

I just wanted to mark this here first of all for my reference, and then for anybody who came here in search of a solution for a similar problem.