July 2009 Entries

ASP.NET Performance – Windows Update – a great example for setting performance standards

Much as people love hearing on  the new features of ASP.NET, one of the frequent requests that I receive is around performance counters, high transactional sites using ASP.NET and real world applications that do very well on ASP.NET.  While there are thousands of sites out there running on ASP.NET, many of them being mission critical, our own Windows Update is a great example of high performance.

Windows Update is something all of us use, whether we like it or not.  It helps maintain your system up to date with critical patches, recommended downloads as well as optional add-ins.  Windows Update also periodically provides major updates such as Service Pack for Windows Vista, Office etc., and it is an essential part of your Windows usage.

How does Windows Update cater to a huge use base of an operating system such as Windows and maintains all the transactions / requests for downloads.  Well, the facts, also available in Wikipedia, is as below:-

As of 2008, Windows Update has about 500 million clients, processes about 350 million unique scans per day, and maintains an average of 1.5 million simultaneous connections to client machines.  On Patch Tuesday, the day Microsoft typically releases new software updates, outbound traffic can exceed 500 gigabits per second. Approximately 90% of all clients use automatic updates to initiate software updates, with the remaining 10% using the Windows Update web site. The web site is built using ASP.NET, and processes an average of 60,000 page requests per second.

I think that is quite a huge number of requests per second and to maintain that using IIS, SQL Server as well as Windows Server, it really requires platform stability and performance.

Another great example of performance is our own group portal which caters to millions of requests per second on a day to day basis.

Note: The facts and figures are as gathered by me from wikipedia and various other resources and must be used for information purposes only.  The opinions are solely mine and do not reflect those of my employer in any way.

Update: Since quite a few folks pointed out, I wanted to also add that "Just as in Cricket, where you cannot set fielding for Bad Bowling, no technology can help bad coding/design.  It is implied although worth mentioning that best practices, reviews and performance tuning can help improve performance of your application"

Cheers !

Bill Gates Live at Microsoft Research India, powered by Silverlight

Watch Bill Gates Live in the 5th anniversary celebration of Microsoft Research, India.  Also, present would be the Chief Guest, Hon’ble Shri Kapil Sibal - HRD Ministry of India, Hon’ble Shri Prithviraj Chauhan - Minister of State for Science and Technology, India, Mr.N.R.Narayana Murthy – Chairman and Chief Mentor, Infosys Technologies, Prof.Ashok Jhunjhunwala – IIT Madras, Dr.P.Anandan – MD, Microsoft Research India.

When is this event: Friday, 24th July 2009 10:30 AM IST

Where do I watch this: Right out of your browser 

What do I need: Simple, an Internet Connection & Silverlight (Install from here)

Cheers !!!


Posting Twitter Tweets from ASP.NET using the WCF REST Starter Kit Preview 2

With Twitter becoming more and more popular, I have always wanted to explore its developer wiki and find out ways to post to Twitter programmatically.  While there are a tons of third party tools such as TweetDeck etc., that allow you to tweet right from your desktop, I was looking for a resource that allows me to update my Twitter status from ASP.NET.  I stumbled upon this video for read/write to Twitter using the WCF REST Starter Kit Preview 2.

I just wanted to take the same experience to post it from ASP.NET Webform, so the credit for the REST logic goes to the above post/video.

However, for the purpose of this post, I am explaining the pre-requisites.  You would need to install the WCF REST Starter Kit Preview 2 from Also you would need Visual Studio SP1 or the free Visual Web Developer Express SP1

Creating your Web Client

Create a new ASP.NET Web Application and add reference to Microsoft.Http & Microsoft.Http.Extensions DLLs.  They are found typically at C:\Program Files\Microsoft WCF REST\WCF REST Starter Kit Preview 2\Assemblies once you install the WCF REST Starter Kit (link above)

Open the Default.aspx, add a TextBox, Label, 2 Buttons say btnPostStatus & btnGetStatus as well as a GridView.  The overall markup looks as below:-


<asp:Label ID="lblStatus" runat="server" Font-Bold="True" ForeColor="#006600" />
      <br />
      <br />
      <asp:Button  ID="btnGetStatus" runat="server" Text="Get Tweets"
      <br />
      <br />
       <asp:textbox ID="Textbox1" runat="server" MaxLength="135" 
      <asp:Button ID="btnPostStatus" runat="server" Text="Post Tweet" OnClick="btnPostStatus_Click" />
      <br />
      <br />
      <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333"
          GridLines="None" AutoGenerateColumns="false">
          <RowStyle BackColor="#EFF3FB" />
          <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
          <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
          <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
          <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
          <EditRowStyle BackColor="#2461BF" />
          <AlternatingRowStyle BackColor="White" />
              <asp:TemplateField HeaderText="Posted By">
                      <asp:Label ID="Label1" runat="server" Text='<%#Eval("user.screen_name") %>' />
              <asp:TemplateField HeaderText="Tweet Count">
                      <asp:Label ID="Label1" runat="server" Text='<%#Eval("user.statuses_count") %>' />
              <asp:BoundField HeaderText="Status" DataField="text" />
              <asp:BoundField HeaderText="Posted Time" DataField="created_at" />

In the Default.aspx.cs, add the following using statements:-

using Microsoft.Http;

using System.Xml.Serialization;

using System.Net;

Generate the click events for the btnPostStatus & btnGetStatus

Getting the Twitter Friends Feed

Login to your Twitter account and then type the URL  It may ask you for your credentials again and if so, provide the same.

Grab (copy) the XML File and paste into notepad.

(Replace all “&” with “&amp;” and remove leading blank spaces, - (hyphen) using a simple find and replace with nothing.  i.e. in Find, you type the – and in the Replace, leave it blank to avoid XML parsing error.  If your XML is in good shape, you can save it with a <filename>.xml and then should be able to browse it using Internet Explorer.  It points out if there are any errors in parsing the XML, that can be fixed)

After the above corrections, copy the XML and in the Default.aspx.cs (created above), after the class definition, point the cursor and from the Edit Menu select “Paste XML as Types” to generate serialization class for the XML Feed.  If you receive an error at this point, make sure the XML is well formed (check steps above)

It gives two items.  A partial class statuses and another partial class statusesStatus.  We will use these to Post and Get Twitter Feeds.

Posting to Twitter

In the btnPostStatus event in the code behind, paste the following code snippet:-

                HttpClient httpClient = new HttpClient("");
                httpClient.TransportSettings.Credentials = new NetworkCredential("TWITTER USERNAME", "TWITTER PASSWORD");
                System.Net.ServicePointManager.Expect100Continue = false;
                HttpResponseMessage responseMessage = httpClient.Get("friends_timeline.xml");

                HttpUrlEncodedForm form = new HttpUrlEncodedForm();
                form.Add("status", Textbox1.Text);
                responseMessage = httpClient.Post("update.xml", form.CreateHttpContent());
                lblStatus.Text = "Your Tweet is posted successfully";
            catch (Exception)
                lblStatus.ForeColor = System.Drawing.Color.Red;
                lblStatus.Text = "There seems to be some issue.  Please try again later";
                Textbox1.Text = null;


Basically, we are using the HtpClient Class from Microsoft.Http that is shipped as a part of the WCF REST Starter Kit Preview 2.  Using this, we provide a GET request to firends_timeline.xml which is the Twitter Feed XML.  Therafter, we are creating a UrlEncodedForm to post the TextBox content using the httpClient’s POST Method to the update.xml Twitter Feed XML.  The rest of the stuff is pretty self explanatory.

Get Feeds from Twitter

In the btnGetStatus event in the code behind, paste the following code snippet:-

HttpClient http = new HttpClient("");
           http.TransportSettings.Credentials = new NetworkCredential("TWITTER USERNAME", "TWITTER PASSWORD");
           System.Net.ServicePointManager.Expect100Continue = false;

           HttpResponseMessage resp = http.Get("friends_timeline.xml");

           statuses stats = resp.Content.ReadAsXmlSerializable<statuses>();
           GridView1.DataSource = stats.status;

In this, we are using the HttpClient and issuing a GET request to firneds_timeline.xml and then binding it using the stats.Status that is available as a part of the serialized XML that we pasted in the above steps.  Once that is done, GridView binding and Template Columns is regular stuff with a little amount of UI formatting.

Once you are done with the above, you should be able to Get the Feeds of your friend when you click “Get Status” and also post status to Twitter once you type it in the TextBox and click on the “Post Status” Button. 

The code snippet for GET/POST requests is taken from Aaron’s video available at where he creates a Console Application using the Twitter Feeds and REST StarterKit.

Herebelow is a snapshot of how the Tweet Feeds look like



You can download the sample from the link below

NOTE: You need to change TWITTER USER NAME & TWITTER PASSWORD to your actual Twitter Username and Password.

Some people may argue on what is the great benefit of using an ASP.NET Webform to do that when I can directly browse the Twitter portal and upload it.  The same may hold good for Desktop Applications as well since you anyway need Internet to post / view feed.  The only case where a client app makes sense is when you can save Tweet Draft and also do more rich UI customizations.  I am trying to build a similar sample using WPF / Silverlight and would post it in my blog once it is ready.  Secondly, this may be useful when you want to pull Tweet Feeds and show in your site/portal like the one that appears in this blog down right.

More than anything, this shows the capabilities the WCF REST Starter Kit offers and can be extended to Winforms / WPF easily.

If you receive a “Unable to locate remote host” error, most probably you are facing a firewall / Proxy issue for issuing a Network Request.  To fix that, you need to add the following to your Web.Config after </system.web> settings


Note, you need to replace the Address & Port of your configuration.  To read more about this, visit my earlier post 

Cheers !!!

Binding ADO.NET Data Service to WPF Client – Building a Master Detail Tree View

If you have played with the ADO.NET Data Service, you can experience how quickly you can build RESTful Services using the Entity Model and then consume them as you would do it with WCF Services.  The ADO.NET Data Services offer more flexibility in terms of granular data URIs compared to REST enabling your WCF Service. 

To begin with, if you are REST enabling your WCF Service using the WCF REST Starter Kit, you can enable your service to basic level of REST features.  However, if you want to make this service as a drill down data URI mechanism to ensure each and every data item has a URI, you need to do a lot of plumbing work.  With ADO.NET Data Services, there is very little work that you would need to do, to create a truly RESTful Service.

To begin with, lets start creating an ADO.NET Data Service.   For this you would need Visual Studio 2008 SP1 (Download link) or the free Visual Web Developer Express Edition SP1 (you can download the same from ).  Also, for the purpose of this demo, I am using the Northwind sample database that can be downloaded from here

Building the Service Layer

1. Once you have the above, select “File – New Project” and chose “Web” in the “Project Types”   Chose “ASP.NET Web Application” and click Ok.  You can delete the “Default.aspx” that is created since this application would just be having a Service and no UI Forms. 

2. Select “Add – New Item” and under “Visual Studio Installed Templates” choose “ADO.NET Entity Data Model”.  Give the name say “NorthwindDataModel” and click “Add”

3. The Wizard opens up and in that select “Generate from database” .  Select “Next” and choose Northwind Database connection string if you have already used it or configure the connection string using “New Connection”.  Select “Yes, include the sensitive data in the connection string” and select “Next”

4. The Wizard lists Tables, Views & Stored Procedures.  Expand the “Tables” and select “Customers”, “Orders” and “Order Details” and click “Finish”

The Data Model preview shows the 3 tables in the designer view.  It is important to have a Data Model to expose the data as a RESTful Service and we just created an ADO.NET Entity Data Model using the Northwind Database. 

5. Build the solution to check if there are any errors.  If all is fine, you should get a “Build Succeeded”

6. Now select “Add – New Item” and choose “ADO.NET Data Service” and give that a name “NorthwindService.svc” and click “add”.

7. The CS file opens up and under the “InitializeService” method, you can find a few commented lines.  Uncomment the config.SetEntityAccessrule line and set its properties to look as follow:-

config.SetEntitySetAccessRule("*", EntitySetRights.All);

8. In the top next to public class NorthwindService : DataService, provide the name “NorthwindEntities” in the area “</ TO DO: put your data source class name here />”

9. Once you build the solution, you are ready with the Data Service.

10. You can run the solution to check the NorthWindService and it would open up the Atom Feed of your Data Model. 

11. The URL looks something similar to http://localhost:[portnumber]/SolutionName/NorthwindService.svc

12. You can append “Customers” or “Orders’ to view the respective records.  You can also filter it to something like “Customers('ALFKI')/CompanyName” to view specific DataItem.

As you can see the ADO.NET Data Service provides a truly RESTful Data Identification pattern with an unique URI for every data item, out of the box without writing code.  To achieve something of this sort, in an REST enabled WCF Service, you would have to write the method for filtering the customer name based on the customer id


Building the WPF Client

Now that we are done with building the Service.  The next step is to consume this service and create a master detail view of the records.  For this we would create a WPF Application. 

1. In the Visual Studio project, select “File – Add – New Project” and choose a “WPF Application” and click “Ok”

2. Select the WPF Application Project and Right Click and chose “Add Service Reference”.  The Service Reference dialog opens up.

3. Click on the “Discover” in the dialog and it would identify the “NorthwindService” we created above.  Click on the Service to expand and download the service information.

4. Click “Ok” to create the ServiceReference

5. Now, we are building a TreeView to show a Master – Detail View of the “Customers – Orders – Order Detials” so we will be using a WPF TreeView and Hierarchical Data Template for binding.  Paste the following XAML Code in the Window1.xaml file

<Window x:Class="WpfApplication1.Window1"
    Title="Window1" Height="300" Width="300" Loaded="Window_Loaded">
            <DataTemplate x:Key="orderDetailsTemplate">
                <TextBlock Text="{Binding Path=UnitPrice}"/>

            <HierarchicalDataTemplate x:Key="orderTemplate" ItemsSource="{Binding Path=Order_Details}" ItemTemplate="{StaticResource orderDetailsTemplate}">
                <TextBlock Text="{Binding Path=OrderDate}" />

            <HierarchicalDataTemplate x:Key="customerTemplate" ItemsSource="{Binding Path=Orders}" ItemTemplate="{StaticResource orderTemplate}">
                <TextBlock Text="{Binding Path=CompanyName}" />

        <TreeView  Name="CustomerTreeView" ItemTemplate="{StaticResource customerTemplate}" Background="#FF00BCFF" >


6. In the Window1.xaml.cs, add the following to the using statements

using WpfApplication1.ServiceReference1;
using System.Data.Services;
using System.ServiceModel;
using System.Data.Services.Client;

7. Add the following code within the Class definition

   DataServiceContext context = null;

        public Window1()
            this.WindowState = WindowState.Maximized;  


        private void Window_Loaded(object sender, RoutedEventArgs e)
            context = new DataServiceContext(new Uri("
            CustomerTreeView.ItemsSource = context.Execute<Customers>(new Uri("Customers?$expand=Orders/Order_Details", UriKind.Relative));


8. You are good to go and press f5 to run the service as well as the WPF Application.  If the WPF App doesn’t show up, make sure that it is set as the StartUp Project type.

9. Note that you can handle the TreeView_SelectedItemChanged event and add more functionality based on the Tree selection etc.,

What we saw here is a quick example of taking a relational database, exposing an entity model and building a IQueryable RESTful Service and then binding it to a WPF Client Application as a Master-Detail Tree View.  In the above sample, we used the System.Data.Services.Client namespace and created the DataContext object to execute the Data Service query.  Also, as you can see, the Data Service query uses the Expand operation to navigate to other related tables for getting the values, making it a truly IQueryable Data Service.


Cheers !!!

Windows 7 RC Download will end August 20, 2009

The download link for Windows 7 RC (Release Candidate) would be unavailable post August 20, 2009.  If one has a physical media (DVD, downloaded bits), they can still install post this date but the download option would not be available.

Windows 7 RTM would be available before end of this year and it should also be available in stores etc., by then.  This post is just to create awareness that if you would like to install and play with Windows 7 RC, do it right away before the download becomes unavailable.

The Windows 7 Download page and product key page is

The Windows 7 Forum is

Let me now share my experience with Windows 7.  It is purely unbiased and is a what is what, I have experienced with Windows 7 RC over the past few months.

I have been running my production machine on Windows 7 RC and haven't had a single crash, failure so far.  I leave the machine on over night, for long hours and its battery consumption is optimal.  Compatibility with applications and drivers has never been an issue.  Whatever works on Vista, works here.

The Start-up and Shut Down duration has significantly improved compared to Windows Vista (Ask me why and I will explain).  Visual Studio 2008, 2010, all the various CTPs I play with have all worked without having to install a separate version tailored to Windows 7. 

Over the last 10 years, this has been the most stable operating system I have used (believe me, I have used various OSes including non Microsoft ones') at the RC level.

So, if you are still unable to believe, try it for yourself and you will see the difference.

Cheers !!!

India - Union Budget – Live on - Powered by Silverlight

If you want to catch up with the Indian Budget being presented today, i.e. July 6, 2009, you can watch it live at

All of this playing out of Silverlight !!!

Cheers !!!