Tuesday, May 26, 2009

Download .Net Framework 4 Beta 1 and documentation

The beta1 of .Net framework4 has been released.Here are the details including offline documentation of .Net 4.0.
Download links
New features include Win7 Support,Surface development support,Parallel programming , parallel linq and much more
Offline documentation
Windows Presentation Foundation SDK - Offline Beta WPF .Net 
Direct download

Friday, May 22, 2009

Beginning tfs programming

Some readers may not have knowledge about the new project management framework introduced by Microsoft.So let’s start from what is Team Foundation Server.

What is tfs
Simply saying tfs is a replacement for the existing source control mechanisms such as VSS.But it has got so many additional features like bug tracking,bug automation,reporting etc... In earlier days we have use different tools to do these tasks such as VSS for source control,OnTime for bug tracking etc…Now everything  under one umbrella.So it is more like a project management environment.See what wikipedia says about tfs.

WorkItems contains all the bugs,feature request along with all other tasks.The main advantage of tfs which I have seen is we can associate a source file check in with a bug id easily.

Introduction to Team Foundation Server programming.
Another big advantage of tfs is it’s programming interface.We can easily develop programs which access tfs.We can create work items,log bugs view work items etc…
Microsoft has provided .net libraries for working with tfs.Those dlls normally reside in the folder
[Install drive]:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies
Most of the tfs related dlls have name starting with “Microsoft.TeamFoundation”. Here are the commonly used tfs dlls in developing applications.

  • Microsoft.TeamFoundation.Client.dll
  • Microsoft.TeamFoundation.WorkItemTracking.Client.dll

Authenticating into tfs server
Like any other source control system tfs too stores files and data in a remote server and it needs authentication to that server before accessing tfs resources.Here is the code which authenticate a user into tfs system from our application.

NetworkCredential tfsCredential = new NetworkCredential(login, password);
TeamFoundationServer tfs = new TeamFoundationServer(tfsName, tfsCredential);

Here login is the login id of the user and tfs name is the full url of the tfs server.eg https://mytfs.mycompany.com:443/
Once the user is authenticated we can query work items as well.

Listing all projects of user in tfs

//Connecting Server
NetworkCredential tfsCredential = new NetworkCredential(login, password);
TeamFoundationServer tfs = new TeamFoundationServer(tfsName, tfsCredential);

WorkItemStore wis = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));

//Iterate Through Projects
foreach (Project project in wis.Projects)
lvProjects.Items.Add(new ListViewItem() { Text = project.Name });

No need to explain I think.Just adding all the projects into a ListView.

Listing work items in a Project

private void LoadWorkItems(Project project)
WorkItemCollection wic = project.Store.Query(
" SELECT [System.Id], [System.WorkItemType]," +
" [System.State], [System.AssignedTo], [System.Title] " +
" FROM WorkItems " +
" WHERE [System.TeamProject] = '" + project.Name +
"' ORDER BY [System.WorkItemType], [System.Id]");
foreach (WorkItem wi in wic)

Again a self explanatory code.Adds all work items into another list box.

A WIME (Works In My Environment) sample is available here.

Tuesday, May 19, 2009

Implementing REST using WCF

REpresentational State Transfer is an architectural approach which treats the url as resource pointer which is more human readable by its syntax.

For example see the Google Picasa urls.They just denote the resource rather than a physical aspx, php or html files.Below is the link to my picasa home page.It just says my username alone.

If we navigate again into any album the url will change and that again point to a resource than a file with query strings.

Don’t think that there is some magic going on.Internally this url is getting mapped to a file which process and outputs the required data as html format.Hope the concept is clear.
The main advantage of this approach is simplicity.Urls are all predictable and easy to remember.
Links to implement this in WCF

Friday, May 15, 2009

Exposing 2 EndPoints for same WCF service using different Bindings

The main attraction of WCF, when I started was it’s ability to expose a service using more than 1 endpoint with different bindings.Yesterday I just created a simple which exposes a service through 2 different endpoints which uses different bindings.One is basicHttpBinding and another using wsHttpBinding.

Before continuing please have a look at these links about ABC ,only if you are not aware of WCF yet.


Specifying 2 EndPoints

If you have a basic idea about WCF you can easily understand the below configuration in web.config which exposes  Uploader service through 2 different end points.

<service behaviorConfiguration="DemoMTOM.Web.UploaderBehavior" name="DemoMTOM.Web.Uploader">
<endpoint address="bh" binding="basicHttpBinding" contract="DemoMTOM.Web.IUploader">
<dns value="localhost"/>
<endpoint address="wh" binding="wsHttpBinding" contract="DemoMTOM.Web.IUploader">
<dns value="localhost"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>

In the sample the url to the basicHttpBinding endpoint is http://localhost:64738/Uploader.svc/bh and the url to the wsHttpBinding endpoint is http://localhost:64738/Uploader.svc/wh. You can check this by adding a service reference in to a WPF application.

Creating ServiceClient to call the service in WPF
When we create service reference in the WPF application, the app.config in the WPF application will get 2 entries.One for basicHttpBinding and another for wsHttpBinding.See the sample app.config below.

<endpoint address="http://localhost:64738/Uploader.svc/bh" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IUploader" contract="UploadServiceReference.IUploader"
name="BasicHttpBinding_IUploader" />
<endpoint address="http://localhost:64738/Uploader.svc/wh" binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IUploader" contract="UploadServiceReference.IUploader"
<dns value="localhost" />

So at the calling side there will be confusion of course in selecting the end point.So to resolve that confusion we have to specify the endPointConfigurationName at the time of creating client.See code below which uses the basicHttpBinding.

UploadServiceReference.UploaderClient cli = new UploadServiceReference.UploaderClient("BasicHttpBinding_IUploader");
string res = cli.DoWork("Joy");

UploadServiceReference.UploaderClient cli = new UploadServiceReference.UploaderClient("WSHttpBinding_IUploader");
string res = cli.DoWork("Joy");

The second code snippet uses wsHttpBinding to call the service.

Hosting service using 2 endpoints in a Console Application

static void Main(string[] args)
ServiceHost serviceHost = new ServiceHost(typeof(Uploader),
new Uri("http://localhost:64738/Uploader.svc"));

serviceHost.AddServiceEndpoint(typeof(IUploader), new BasicHttpBinding(), "bh");
serviceHost.AddServiceEndpoint(typeof(IUploader), new WSHttpBinding(), "wh");

ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;

ServiceDebugBehavior sdb = serviceHost.Description.Behaviors.Find<ServiceDebugBehavior>();
sdb.IncludeExceptionDetailInFaults = true;


Console.WriteLine("Service running below are the Endpoints :");
foreach (ServiceEndpoint se in serviceHost.Description.Endpoints)
Console.WriteLine("Press any key to quit...");

catch (Exception ex)
Console.WriteLine(string.Format("Error :{0}", ex.Message));

In the sample when you try to run the console application it will throw an error because the asp.net application also runs and uses the same port.So run the console application from command line or explorer.

There is no need to change the reference in the WPF application since both these console application and asp.net service host is using same url.

Silverlight application in the sample is created using Silverlight 3.Remove that project if you don’t have Silverlight 3 installed in your machine.
Download sample from here.

Thursday, May 14, 2009

Comparison of WSHttpBinding and BasicHttpBinding in WCF

Criteria BasicHttpBinding WSHttpBinding
Messaging Soap 1.1 Soap 1.2
Security Very less More
Security level SSL @ Transport layer SSL @ Transport and MessageLevel
Speed High Low
Ordered delivery No Yes
Compatibility Like asmx.Older versions can Older .Net versions can’t since this implements more WS specs
Silverlight supports Yes Upto Silverlight 2 doesn’t support.

I will be adding more as and when I come across.

More links


Wednesday, May 6, 2009

What is Microsoft Surface

Microsoft surface in simple word is a multi-touch enabled flat screen device which has the ability to recognize objects.In other words it is a computer without mouse and keyboard ,packed as a single box whose upper side acts as a monitor and is equipped with infrared sensors to identify the objects placed on the monitor (top).


There are a bunch of photos and videos available in internet to get an idea how this looks like and how it operates.

Multi touch capability

The touch is basically identified by infrared rays.There are 5 cameras under the screen of the surface and they do this job by getting the reflected IR rays from the screen.The reflection can be by finger,objects or tags.

The surface can identify 3 types of touches or contacts on its display area.They are Contact,Blob and Tag.

Contact is the normal finger touch or what ever we are doing with our finger.It will handle more than one touch simultaneously.Hence it is called multi touch.

Blob is the contact which covers a large area.For example if we place our hand over the surface it is identified as Blob.

Tag contact is another type of contact which is used to identify objects by its value.This is described below in details.

Object recognition or Tag identification

This is one of the key feature which is not in the other multi touch devices.In the demo videos of surface we can see some nice visuals coming around a glass when it is placed.That is performed through tags only.Tag is like a bar code which should be present in the object to get recognized by the surface.So when we place a glass or any other object with tag over the surface it recognizes the tag value and the underlying program shows the visual according to that.


  • In high class hotels and wine bars : This gives a new experience and entertainment to the customers.Recently Microsoft introduced a new technique which lets the system knows about the level of liquid in the glass.Thus it can be refilled at some particular levels.
  • Parties and events : Networked surface machines can display the live videos and photos taken during the event.They can even transfer those photos to their online account or mobile devices.
  • Games : New experience in gaming using multi touch and object recognition.This can be hosted in the above said places.
  • Information systems : Current information systems can be redesigned to have multi touch capabilities and tag recognition.For example in a hospital when someone places his card which contains surface tag it can identify him and show him necessary details about the treatments he has taken and whether a particular doctor is available or not etc…

Developing surface applications

Currently there are 2 ways to write programs for surface.One is XNA and another one is to use WPF with surface sdk provided by Microsoft.XNA is more like a low level program.We have to install the XNA framework to build programs.

Surface sdk and surface simulator

The surface sdk supports WPF.But it is now available to partners only and to the developers who attended the PDC.In the FAQ section they told to write a mail to sbizdesk@microsoft.com if you need sdk.

Before starting development we have to install some prerequisites.A list is available in my colleague’s blog.The sdk itself includes a simulator which helps us to see the surface application without the actual surface machine.Currently the surface machine is available in U.S and some selected countries only.So for developers like us who are from India ,the simulator is really a gift.Working with the simulator is another big topic.I will be blogging about that later.

We can run our normal WPF programs in the surface.But the issue is the mouse related actions won’t get fired.For example mouse click, mouse hover etc…The reason is very simple.There is no mouse in surface. Everything is by contact or touch.So we have to use the Surface button which is available in the sdk.Similarly there are so many controls which replaces the normal WPF controls in surface world.

Porting existing applications to surface

These normal mouse related things we can make as surface enabled by hooking into the Contacts.ContactDown event.But the real issue is with the text box.Surface doesn’t have a keyboard.The only way is to show a keyboard in the surface display area ,recognize touches ,process it and use as virtual keyboard.This virtual key board support is there in the SurfaceTextBox by default.

Next post : Surface Application Development using Simulator and VisualStudio in my WPF blog