Friday, December 30, 2011

Consumption of WCF Service during development

-Balaji Ramasamy
As I was working on project, it demanded to run the WCF service during development which was a challenging task for a novice developer. We successfully developed the WCF service by implementing the service contract interface & service behavior class. The above developed WCF service needs to be consumed by the client application, which will interact with the end point of the services and provides the requested response. To successfully build and test the application, the WCF service needs to be exposed, which will be consumed by client application with the help of svcutil tool. Since the WCF service is a class library, we can’t run it as service.

So here comes the question of how to run the WCF service to generate and consume the service proxy in my client windows application during development. We are very much aware of hosting the service via the console application, winforms application, windows service, IIS, WAS to host the WCF service. Initially we ran the WCF service as windows service, assuming it as a right decision, which resulted in multiple installation and un-installation of windows service. To avoid such painful process during development, we planned to run the WCF service in console application. But how to run in console application? Here comes the ServiceHost runtime, which will enable to the WCF service to load the service class, set up the endpoints and channel listeners, which provides your service class an “ecosystem” to live and operate in.

You can either instantiate a ServiceHost class yourself in a console app, a Windows service, or even a Winforms app, and thus make your WCF service class available to the outside world - or you can delegate that work to IIS or WAS. Even IIS or WAS will use a ServiceHost to host your WCF service - they just do it automatically behind the scenes.

The following is the console application code to run the WCF service
internal class Program
private static void Main(string[] args)
Console.WriteLine("Service is running...");
Console.WriteLine("Press key to end...");
catch (Exception ex)
//Log the Exception
internal static ServiceHost myServiceHost = null;
internal static void StartService()
myServiceHost = new ServiceHost(typeof([namespaceName.ServiceBehaviourClassName]));
catch (Exception ex)
//Log the Exception
internal static void StopService()
if (myServiceHost.State != CommunicationState.Closed)
catch (Exception ex)
//Log the Exception
And the Application configuration includes be the following

  <service name="[namespaceName.ServiceBehaviourClassName]"
    <add baseAddress="[EndPoint Address]" />
  <endpoint address="" binding="[Binding Name]"
   contract="[namespaceName.ServiceContractName]" "/>
  <endpoint address="mex" binding="mexNamedPipeBinding"
   <behavior name="metadataSupport">
   <serviceMetadata />
   <serviceDebug includeExceptionDetailInFaults="true" />
Note: Application Configuration may vary from one binding to another binding. Please check Microsoft MSDN site for more details about bindings and its related configuration

Now run the service and its ready to consume in the client application during development stage of our application


Wednesday, December 21, 2011

Integrate Microsoft Lync 2010 to your .Net Application

- Mohankumar Deivasigamani
This post focus on the process to integrate Microsoft Lync 2010 to your .Net application.
Microsoft Lync is an instant messaging clients . It is a replacement for Windows Messenger and has added feature set that is mainly targeted towards corporate environments.

Note: For this tutorial I assume that you have Lync 2010 running on your machine. Also your machine has Visual Studio 2010.
So here we go with the steps for integration

Step 1: Download and install Lync SDK 2010 (free) on your machine.

Step 2: Open Visual Studio 2010 and create a “New Project”. Select a “WPF Application” template for this project.

Step 3: Lync SDK controls will be available in "Tool box", You can drag the control to your form. For example here I am using few controller like “MyPresenceChooser”, ContactSearch & ContactSearchResultList.

Step 4: Test your application by clicking “Run” from your Visual Studio. The output appears as below, where you see the Lync 2010 gets integrated to your application.

To make it more effective here below i am comparing the output of the application to the Lync 2010 installed in your machine.

So thats it for the basic integration and now you can start customizing and adding more stuffs with your code.

Friday, December 9, 2011

Azure - BLOB Storage

-Balaji Ramasamy
Windows Azure offers four core storage services namely Blob, Table, Queue and Drive, which are accessible via multiple instances / applications simultaneously representing a dedicated storage instead of temporary storage. The simplest way to store with Windows Azure is Binary Large Object (BLOB) Service. In this blog, I provide highlights of storage services offered by MS Azure and compared the same with AWS S3 (Simple Storage Service) that enables you to store data in the AWS cloud.

We can store the files in three ways. The file size with 64MB or lesser size can be uploaded as a single BLOB. If the file size exceeds 64MB then we can go for BLOCK Blob or PAGE Blob.

The BLOCK Blob supports 200GB of total file size and each block should be maximum of 4MB and its identified by BlockID which is unique within the Blob. Block ID is Base64 encoded string of same length and its values can be duplicated in different blobs.
When using base-64 encoding, the pre-encoded string must be 64 bytes or less. The maximum of 50,000 blocks is allowed for each blob. The maximum of 1,00,000 uncommitted blocks is allowed, its total size should be 400GB and finally the uncommitted blocks will be garbage collected after a week. We have to call PutBlockList to commit the uploaded blocks.

The PAGE Blob supports 1TB of total size and each page should be maximum of 4MB and its collection of 512-bytes. To create a page blob, initialize the page blob and specify the maximum size. Writes to page blobs happens in-place and are immediately committed to the blob. It’s optimized for random read and writes operation.

BLOB Storage Local Testing
  1. Local Storage is provided by Windows Azure to test cloud storage with help of Storage Emulator.
  2. Blobs in the Windows Azure storage emulator are limited to 2 GB.
  3. When making a request against the local storage service, specify the local hostname and Blob service port as, followed by the local storage account name
The following is a comparison of Amazon Simple Storage Service and Azure BLOB Storage.

Simple Storage Service
BLOB Storage
User Subscription
Single Account Multiple Accounts
Security Keys
Two set of acceskey and secret key Account name with Primary Access Key / Secondary Access Key
With Acceskey and Secretkey With Account name and Primary Access Key or Secondary Access Key
Domain Name
Bucket Name and its unique Account Name and its unique
Contents are categorized by
Bucket Container
Size Limitations on Storage
No size limit on storage 100TB storage size per account
Size Limitations on File-Size
Up to 5GB in a single PUT
Up to 5 TB using multipart upload
Up to 64MB for single Blob.
Up to 200GB for Block Blobs
Up to 1TB for Page Blobs
Specifying API Version in Request Header
Offline Testing
N/A Local Storage is provided by Windows Azure to test cloud storage with help of Storage Emulator.
Enable/Disable/Suspend versioning at Bucket Level Provided Snapshot functionality for object(s).
Bucket Level Logging

No size limitations.

Logs stored in configured Bucket and Prefix
Service(Blob, Table, Queue) Level Logging for storage account's

20TB size limitations other than 100TB storage size.

Log data is stored as block blobs in a container called $logs in the blob namespace of your account

Logs can be accessed thru $logs container using http://<accountname>$logs

Log name under the $logs container will have the following format:
 <service name>/YYYY/MM/DD/hhmm/<Counter>.log


LIST API Comparison


LIST Bucket
LIST Container

Prefix Prefix Keys that begin with the indicated prefix. prefix Filters the results to return only blobs whose names begin with the specified prefix.
Indicates where in the bucket to begin listing.
Indicates where in the bucket to begin listing.
No.of Records MaxKeys
NextMarker NextMarker element has a value only if the list results are not complete. NextMarker NextMarker element has a value only if the list results are not complete.
To dentify list complete or not IsTruncated Specifies whether (true) or not (false) all of the results were returned. All of the results may not be returned if the number of results exceeds that specified by MaxKeys. N/A N/A
Delimiter Delimiter Causes keys that contain the same string between the prefix and the first occurrence of the delimiter to be rolled up into a single result element in the Common-
Prefixes collection.
delimiter When the request includes this parameter, the operation returns a BlobPrefix element in the response body that acts as a placeholder for all blobs whose names begin with the same substring up to the appearance of the delimiter character. The delimiter may be a single character or a string.
Folders Common-Prefixes
FileName Key The object's key. Name name of the object
Size Size Size in bytes of the object. Content-Length / Size Size in bytes of the object.
Metadata N/A N/A include snapshots,metadata,
ETag ETag MD5 hash of the object. The ETag only reflects changes to the contents of an object, not its metadata. Etag identifier
Content Type N/A N/A Content-Type blob-content-type
Modified Date LastModified Date and time the object was last modified. Last-Modified /LastModified date-time-value

Hope this post helped you to understand Azure BLOB Storage.

Wednesday, November 23, 2011

Adding custom Ribbon menu in MS Office using C#

- Mohankumar Devasigamani
Hope readers might have gone through my previous post which helps you to better understand on how to create MS Office add-ins.
    Note: As per my previous blog post, I sticked on MS Visual Studio 2010 & MS Office 2010.

Creating the add-in project
Click here to refer my pervious blog post.

Adding Reference to the project
  • Open MS Office add-in project (CSSSampleAddin)
  • Right-click on Reference folder in add-in project ->Go to Add Reference
  • Add Reference window will appear.
         Click COM tab. Select Microsoft Office 14.0 Object Library, Microsoft Office Core and then click OK

Creating the Ribbon menu Customization XML File

  • Right-click on project -> Add -> New Item
  • Select XML file and name it as RibbonMenu.xml ->Click Add
  • Edit and add the below XML content to the XML file.
<?xml version="1.0" encoding="utf-8" ?>
<customUI xmlns=           loadImage="GetImage">
   <tab id="tab1" label="CSS Corp Demo">
    <group id="group1" label="CSS Group">
     <menu id="menu1" label="Drop Down" itemSize="large" 
               getScreentip="GetScreenTip" supertip="This is a super tip   
               for the menu." image="star">
      <button id="uxSearchButton" image="search"   
  • Save the file.
Set the RibbonMenu.xml as embedded resource

  • Right-click on the RibbonMenu.xml file -> Properties
  • Change Build Action property to Embedded Resource
  • Go to CSSSampleAddin project properties -> Select Resource tab
  • Select file option, and drag and drop the xml file -> Save the properties
Start writing the code
Open Connect.cs and add below lines in top of the class file

using Microsoft.Office.Core;
using Word = Microsoft.Office.Interop.Word;

Create instance of Word and implement the IRibbonExtensibility interface. Edit / Modify the existing code as below

private Word.Application applicationObject;

Edit /Modify the first line of OnConnection() method as below

applicationObject = (Word.Application)application;

Inherited the IRibbonExtensibility in Connect class

public class Connect : Object, Extensibility.IDTExtensibility2, IRibbonExtensibility

Right-click on implemented interface and click Implement Interface, and then click Implement Interface Explicitly that will add IRibbonExtensibility.GetCustomUI method. Add the below line GetCustimUI method.

return Properties.Resources.Ribbon;

Now almost your demo add-in is ready for test. Before testing add the image for custom ribbon menu.

Adding your own image file

  • Right-click on project -> Add -> New Item
  • Select Bitmap file ->Browse your image -> Click Add
  • To embed the image, please follow the same steps that we did for XML file.
    For example here i have added two images named search and star. You can see those two images below .
Add the below method in connect class
public IPictureDisp GetImage(string imageName)
 IPictureDisp dispImage = null;
 switch (imageName)
  case "search":
  dispImage = PictureConverter.ImageToPictureDisp
  case "star":
  dispImage = PictureConverter.ImageToPictureDisp
return dispImage;
Include the below class in the same file.
internal class PictureConverter : AxHost
 private PictureConverter() : base(String.Empty) { }

 static public IPictureDisp ImageToPictureDisp(Image image)
    return (IPictureDisp)GetIPictureDispFromPicture(image);

 static public IPictureDisp IconToPictureDisp(Icon icon)
   return ImageToPictureDisp(icon.ToBitmap());

 static public Image PictureDispToImage(IPictureDisp picture)
   return GetPictureFromIPicture(picture);

GetImage method will be already referred from RibbonMenu.xml file.
          Right time to test demo project. Build the CSSSampleAddin project. Go to project properties  Select Debug and set Start external program to Word, 
by default word exe located in C:\Program Files\Microsoft Office\Office14\WINWORD.EXE
Run the add-in project, you will be able to see the customized Ribbon menu.

Write the method to handle click event of Search button.

public void Search(Microsoft.Office.Core.IRibbonControl control)
MessageBox.Show("User has clicked Search button.", "CSS Corp Demo");
I hope this post helped you to know how ribbon menu can be added to Microsoft Word. Similarly the same process can be used to add ribbon menu to any of the Microsoft Word Office tools (Excel,Access etc.) As I mentioned in my previous blog. In Further you can setup project to create msi /exe which will help you to create add-in in other machine.

Note: Await and stay tuned for my next post "List to be checked out while MS Office add-ins are not getting loaded".

Tuesday, November 15, 2011

Create your own MS Office add-ins using .Net

-Mohankumar Deivasigamani
      Here I am sharing the steps that will guide you to create a simple MS Office add-in using Microsoft Visual Studio. For further explanation lets take Visual Studio 2010 and MS Office 2010.

You must have the following items to be installed
  1. MS Visual Studio 2010 (You can also use 2005 / 2008)
  2. Microsoft .Net Framework 3 (minimum 2.0 up to 4.5)
  3. Office PIA (Primary Interop Assemblies)
Start creating add-ins
  • Open MS Visual Studio 2010 > Select New Project > Other Project Types > Extensibility

  • Now choose Shared Add-in project Template as shown above.
  • Enter the project name and solution name in the appropriate fields and click ok.

Configuration Wizard
Wizard screen will guide you following steps
  1. Press Next in the welcome add-in wizard
  2. Select the programming Language which you want to develop. (C#)
  3. Select the application host (Word / Visio / Publisher / Project / Power Point /Outlook / Info Page /Excel /Access)
  4. Enter name and description of your add-in
  5. Choose Add-in option
  6. Click the finish button to create new MS Office add-in and setup project for selected host application.
Projects created
Two projects will be created automatically as follows
  1. Add-in project (CSSSampleAddin)
  2. Setup project (CSSSampleAddinSeup)

Add-in gets installed, which is highlighted in the screen displayed below.

Now you can start writing your code to build add-in menu in OnConnection() method of Connect.cs class file. Further you can setup project to create msi /exe which will help you to create add-in other machine.

Note: Await for my next post which will help you to create Ribbon menu in MS Office Word

Wednesday, November 9, 2011

Android & its UI

 -Kalimuthu Rengaswamy
Now a days Smart Phones playing a vital role in IT industry with their innovative applications and OS updates. I am on my toes for getting Android latest version Ice-cream-sandwich which totally updated with many stunning features.
        Probably many of you might be using Android or any other smart phone, which are provided with their own App stores. When you thought of an Application, the first thing you will be expecting is good UI. Right! Android has provided developers with many widgets and necessary layouts. Android done all its part and now UI entirely depends on the developers ability.
People use the Smart mobiles for various purposes, for example security, entertainment, gaming, casual and so on. All persons may not concentrate on UI but many people do. Android is provided with both 2D and 3D graphic engines.
        Lets go little depth in this topic, every activity in the application is designed using the XML coding. As I specified previously, android is providing all the necessary widgets,layouts, composites, media&images in its framework, making developers easy.
If we go little more deeper Android is provided with these following layouts:
  • Frame Layout
  • Absolute Layout
  • Linear Layout
  • Table Layout
  • Relative Layout
Developers uses this according to their convenience and purpose. For the time being I will be explaining only about Relative layout which is most used in general.
Relative layout :
In a relative layout every element arranges itself relative to a parent control or other control.
In this relative layout control place in two way
  1. relative to their container
  2. relative to other controls 
Relative to their container 
In this type controls are relative to container place in layout. It flow some properties android:layout_alignParentTop, Bottom, Right or Left to true. This aligns the Top,Bottom,Right or Left side of the control to the Top, Bottom, Right or Left side of the container respectively.
  • android:layout_centerVertical: The control should be positioned vertically in the center of the container.
  • android:layout_centerHorizontal: The control should be positioned horizontally in the center of the container.
  • android:layout_centerInParent: The control should be positioned both vertically and horizontally in the middle of the container.

Example :
<?xml version="1.0" encoding="utf-8"?>
Position Relative to other control positions:
     In this type controls are relative to other control place in layout. It follow some properties
  • android:layout_above: the widget should be placed above the referenced widget.
  • android:layout_below: The widget should be placed below the referenced widget.
  • android:layout_toRightOf: The widget should be placed to the right of the referenced widget.
  • android:layout_toLeftOf: The widget should be placed above the referenced widget.
Example :
<?xml version="1.0" encoding="utf-8"?>

<Buttonandroid:id="@+id/widget34"android:text="Button3" android:layout_height="wrap_content" android:layout_width="wrap_content"android:layout_below="@+id/widget35" android:layout_alignLeft="@+id/widget35" android:layout_marginTop="165dp">
<Buttonandroid:id="@+id/button2"android:text="Button4" android:layout_height="wrap_content" android:layout_width="wrap_content"android:layout_alignBaseline="@+id/widget34" android:layout_alignBottom="@+id/widget34"android:layout_alignLeft="@+id/button1"></Button>

<Buttonandroid:id="@+id/widget35"android:text="Button1" android:layout_height="wrap_content" android:layout_width="wrap_content"android:layout_alignParentTop="true" android:layout_alignParentLeft="true"android:layout_marginLeft="60dp" android:layout_marginTop="171dp"></Button>

<Buttonandroid:id="@+id/button1"android:text="Button2" android:layout_height="wrap_content" android:layout_width="wrap_content"android:layout_alignBaseline="@+id/widget35" android:layout_alignBottom="@+id/widget35"android:layout_alignParentRight="true" android:layout_marginRight="58dp"></Button>

This is just a introduction to the android application development. Hope it was helpful. Await and keep following for the next post.