Infosys Microsoft Alliance and Solutions blog

« October 2008 | Main | December 2008 »

November 28, 2008

Silverlight and Matrix Transformation

I found this interesting article explaning the affine transformations that one needs to use to get the true perspective view. There are challenges in getting this to work in Silverlight as explained by Pedro in the article. I look forward to part 2 of the article. BTW, don't forget to read the link that gives detailed maths behind this as it has good detailed explanation. However it is a bit lenghty and if Maths isn't your favorite subjects [and personally I have lost track of matrices and trignometry over the years], you may lose interest quickly.

November 26, 2008

Enterprise systems available on the cloud as services

Suppose an enterprise has a set of services that it feels can be exposed to the internet for business or for its own usage, there are two ways to address it.

1) Setup the services on a DMZ thereby exposing the services in a secure manner to the internet.
2) Open up ports on the enterprise firewall to allow inbound access from outside machines to the services running. [This is not allowed as it has the potential to allow users to exploit the enterprise network]

The first mode of setting up a DMZ is the preferred way, but its limitation would be allowing access of DMZ machines onto the enterprise network. If the DMZ needs to access internal systems like a Mainframe, then there could be deployment and security issues.

The Microsoft .NET services (or the BizTalk Services as it was previously called) allows enterprises to expose their services to the internet from within a firewall without having to setup a DMZ or allow explicit inbound access to the machines. It used the concept of Relay Binding (extension over the existing WCF) to allow access to the services. Allowing disparate systems to be interconnected through the internet, the .NET services sets up an internet service bus in the Microsoft cloud. 

Some of the offerings of .NET Services are:
1) Access Control Services or  Identity Services: it is a hosted service that enables enterprises easily manage its users supporting user identities from various organizations

2) Connectivity Services: These services make connectivity between services in different enterprises feasible. We could host a service from within Infosys Firewall and it could be consumed by a customer in another enterprise or on the internet. It allows enterprises to expose services through the .net services as a URI which is accessible over the internet. In practice, the actual URL and Machine of the service is hidden from the client applications.

3) Workflow Services: A new addition to the .NET services, it allows execution of Windows Workflow Services that orchestrate the interactions between other services hosted via the ISB.

4) .NET framework extensions that allow connecting to the ISB through applications
The Connectivity Services relies on using RelayBinding 


Applications that need to use connectivity services establish outbound connections (allowed by enterprises) to the service bus. This would be done by both the sending as well as receiving applications. 

When an application listens on an endpoint, it automatically polls the Connectivity Service to retrieve incoming messages. In a simple example, suppose applications in two distinct enterprises send and receive messages through the WCF framework and APIs. Enterprise A establishes an outbound connection to the Connectivity Service, and begins listening on an endpoint, defined by the URI  Enterprise B also establishes an outbound connection to the Connectivity Service, and sends a message to the same URI. The Connectivity Service receives the message, and relays it to the application in enterprise A, via its already open connection. The SDK simplifies developing applications that use the .net services, and enables existing applications to use the service bus without modifications.

In cases where Direct connection is possible, the service bus would first establish a relay connection and then make a direct connection between the applications. The connectivity service internally calls the identity services to authenticate the users. The steps to start working on service bus are.
1) Create an account on the site.
2) Download the .net services SDK and install it on the machine.
3) If the machine is within a firewall then open outbound connections to 65.55.22.* and 65.22.20.* IP range over the following ports 808, 809, 818 and 819. Install the Winsock client so that access to the BizTalk service machines is available. [This is required because the relay mechanism internally uses TCP connections to ensure connectivity with the Service bus]. Now we are set to start using the sample applications.

There are many sample applications available in the SDK that showcase the various abilities of the Service bus like Relay connection, multicast, Direct connection, Http based file sharing and Workflow. The .NET services offer a simple way for enterprises to share their services across the internet without having to put them on a DMZ or another hosting service. This blog from Clemens Vasters has a good amount of information about .NET services. 

.NET Framework 4.0 CLR Enhancements

If you attended PDC and specifically the session on .NET Framework: CLR Futures by Joshua Goodman, GPM, CLR team, then already have a good idea on the new enhancements on their way in the CLR 4.0. In this blog, I will only capture the key points that I found interesting and I do suggest that you watch the video of this session to get the complete message.

1. Better support for side by side, where in you can have CLR 2.0 and 4.0 in the same host process.  This will be specifically useful for addins.

2. No more PIA (primary interop assemblies) to worry about.

3. New signature generation tool that can look up windows.h to generate p/invoke signatures. The tool will be on code plex shortly.

4. .NET supported 16 languages, but no support for dynamic languages and functional language. Iron Python, Iron Ruby and F# will now be supported.

5. Big integers support added in BCL (base class library) so any language on top can leverage it. For more details on BCL changes check here.

6. Tuples supported in F# and Iron Python. It is more used for making new classes or allows functions to return multiple values. This is now added to BCL so langauge interop becomes easy.

7. Tail recursion optimizations done in F#. C# compiler still doesn't support this.

8. .NET Framework now installs faster and applications can startup faster. Installation and NGEN is done in parallel. Startup times improvements due to layout optimizations and can result in upto 40% improvements in some applications.

9. .NET applications can now run from network share with full trust, so it is easy to deploy applications. This feature has been added in .NET 3.5 SP1 itself. 

10. Improvements in threading to take advantage of multi-core machines. Thread pool code improved in conjunction with task parallel library implementation.

11. Support for background GC.

12. Better profiling support with ability to attach/detach performance and memory profilers to production servers without having to install

13. Using catch(Exception e) is bad since it will catch all exceptions include access violation, illegal instruction (exceptions that corrupt the state) etc. Going foward to handle this, you will have to use the [HandleProcessCorruptedStateExceptions] attribute at the function level.

14. Dump debugging simplified by supporting ICorDebug to debug dumps right from Visual Studio. Also new lock APIs are available to help find more details about locaked objects.

15. Code contracts are powerful new constructs that can help write assert and post condition type statements, but in a more powerful manner. Static analysis tools can understand these and identify violations without you even running the code. To know more about code contracts and how they work well with unit testing to help improve the code quality, check this pdc session.

If you want to play around VS 2010 and .NET 4.0, you can download the CTP from here, and can provide your feedback here.

November 24, 2008

Configuring WCF on IIS 7

 We have been on Silverlight (SL) for sometime now on an internal project. During the development, we were mostly relying on the ASP.NET Web server. However for a review when we decided to host the application on IIS, we realized that the WCF service wasn't working on it. The machine was a Vista box with IIS 7 and since .net 3.0 comes pre-installed, we had assumed that WCF will also just work.

However when we configured the specific applications on IIS, and tried to browse to the WCF's SVC file, we got a 404.3 as seen in the figure below.


Essentially what this shows is that IIS isn't configured correctly and when you try to access the service details by accessing the SVC file, IIS is unaware on how to handle this request. The resolution shown here can be a bit misleading. The mime map option isn't right since what we want is to be able to execute the SVC file on server and not really return it as some kind of stream from IIS. For execution, appropriate http module and handlers need to be registered with IIS. This can be done via the IIS Admin console or directly editing the applicationHost.config file (filepath - C:\Windows\System32\inetsrv\config). The following changes are required.

Add the following handlers to the file inside of section "<location path="" overrideMode="Allow">"

                <add name="svc-ISAPI-2.0" path="*.svc" verb="*" modules="IsapiModule" scriptProcessor="%SystemRoot%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv2.0,bitness32" />

                <add name="svc-Integrated" path="*.svc" verb="*" type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="integratedMode" />

and also in the same section add the following module

                <add name="ServiceModel" type="System.ServiceModel.Activation.HttpModule, System.ServiceModel, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="managedHandler" />

While you can manually change the file to do this, it is much easier to do this via the "Turn Windows features on or off" (via Control panel). Apart from the config file changes, there could be other configurations related to specific security settings etc (I haven't tried to find out as yet) could be required that will be taken care via this setup.


The "Windows Communication Foundation HTTP Activation" is not enabled by default. You can check that and click OK and this will do the necessary configurations along with making the changes to the applicationHost.config file as I mentioned above.

With these done, when I browsed my service's SVC file again. I got the familiar screen as seen below and got the service working fine.



November 21, 2008

Silverlight Theming

If you have been following updates on Silverlight (SL) 2, you would already be aware of SL 2 Toolkit on codeplex. Scott in his blog has shared some amazing numbers on usage of SL and also given some indicators to where SL is headed in its next version.

I had been away from SL for some time due to other focus areas. However I decided to try my hands on the support for themes, a feature added with SL Toolkit.

This intro by Jesse Liberty amazed me. The theme seemed so trivial to use. The basic idea on these being available as controls that I could drop on my form and embed other controls inside of it was amazing. I decided to give this a try and started with my sample application. While building this, I observed a few things, which I wanted to capture and share

  1. To work with themes, I started by adding necessary references
    • Microsoft.Windows.Controls.Theming.dll
    • Microsoft.Windows.Controls.Theming.ExpressionDark.dll
    • Microsoft.Windows.Controls.Theming.ExpressionLight.dll
    • Microsoft.Windows.Controls.Theming.RainierOrange.dll
    • Microsoft.Windows.Controls.Theming.RainierPurple.dll
    • Microsoft.Windows.Controls.Theming.ShinyBlue.dll
    • Microsoft.Windows.Controls.Theming.ShinyRed.dll
  2. I then added RainierOrange and ShinyRed to 2 columns in my Grid and then further child controls inside of these theme controls.
  3. After I added the child controls, I expected them to display using the parent theme, but that didn't happen till the time I built the project once. I guess that caused the designer to refresh and load the theme assemblies appropriately.
  4. I then also added Microsoft.Windows.Controls.dll to add some new controls from the toolkit and when I tried to debug I got an error - "Invalid attribute value input:ButtonSpinner for property TargetType. [Line: 1 Position: 220]"
  5. Doing some online search pointed that need to also add reference to Microsoft.Windows.Controls.Input.dll and Microsoft.Windows.Controls.DataVisualization.dll. Interestingly, this error is seen when I debug the solution. If I run it without debugging, it works fine.
  6. If you add only one of the assemblies, you might end up seeing an error like this - "Invalid attribute value charting:Chart for property TargetType. [Line: 1 Position: 262]". Hence it will be good to add reference to both the assemblies mentioned in the previous point

I am surprised why debug execution gives an error while run doesn't (point 5). If anyone has found out a reason, please share.

November 17, 2008

Handling Thread Exceptions

The other day someone asked "What is the best way to handle exceptions in a thread method and communicate back to the main thread?" The reason for the question is this - If you raise exceptions from a thread function (which is not the main thread) and if this is unhandled in the thread method itself, it causes an unhandled exception to be raised in the AppDomain and the application terminates.

You can handle the AppDomain.UnhandledException event to attempt to save some state/information as may be required and possible, but you can't stop the application from terminating. Note however that if a similar unhandled exception is raised from the main thread (of a winform application), the application may not terminate.

MSDN excerpt - "In applications that use Windows Forms, unhandled exceptions in the main application thread cause the Application..::.ThreadException event to be raised. If this event is handled, the default behavior is that the unhandled exception does not terminate the application, although the application is left in an unknown state."

To see this behavior, check the following code. In the Form1, I have added 2 buttons (button1 and button2). In the button1 code, I raise an exception, so this acts as an exception on the main thread itself. In button1 code, I start a new thread and then raise an exception in the thread function.

        private void button1_Click(object sender, EventArgs e)


            throw new NotImplementedException();



        private void button2_Click(object sender, EventArgs e)


            Thread th = new Thread(new ThreadStart(func));




        void func()


            throw new NotImplementedException();


Finally, in the program.cs, I have added an event handler to handle the thread exception.

        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)


            MessageBox.Show("exception caught");


To see the actual behavior, you should run the application and not debug it. In case of the button1 exception, you get a framework provided message box that allows you to handle the exception and continue executing the application. In case of the button1 exception, you will see the message box as per the code in the event handler that I have written in program.cs (as shown above), and after you click OK on the message box, the application terminates.

So back to the question we started with. Essentially the solution lies in not throwing the exception from the thread, but handling it in the thread method itself and instead firing an event that the main thread can handle and get details on the exception. The good news is that this behavior has already been provided in BackgroundWorker class. See the modified logic for button2 code to show how this works.

        private void button2_Click(object sender, EventArgs e)


            BackgroundWorker worker = new BackgroundWorker();

            worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);

            worker.DoWork += new DoWorkEventHandler(worker_DoWork);




        void worker_DoWork(object sender, DoWorkEventArgs e)


            throw new NotImplementedException();



        void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)


            if (e.Error != null)



                MessageBox.Show("all fine");


In case of exception the RunWorkerCompletedEventArgs.Error property is set and the details on the same can be obtained in the RunWorkerCompleted event handler. If you are interested, you can always debug into the framework code to see the details. The following code snippet shows how this is implemented in the BackgroundWorker.cs class

        private void WorkerThreadStart(object argument)


            object workerResult = null;

            Exception error = null;

            bool cancelled = false;




                DoWorkEventArgs doWorkArgs = new DoWorkEventArgs(argument);


                if (doWorkArgs.Cancel)


                    cancelled = true;




                    workerResult = doWorkArgs.Result;



            catch (Exception exception)


             error = exception;



            RunWorkerCompletedEventArgs e =

                new RunWorkerCompletedEventArgs(workerResult, error, cancelled);


            asyncOperation.PostOperationCompleted(operationCompleted, e);


You can see the main execution logic on the BackgroundWorker is inside of a try catch block and the exception obtained is set to the Error property of the RunWorkerCompletedEventArgs class.

Hope this helps.

November 10, 2008

Microsoft Blueprint Walkthrough – Creating My First Blueprint

One of my colleague, Archana Sachin Ghag who is a key member of our software factory team has just finished writing a Blueprints Walkthrough. I am sharing this walkthrough with rest of the development community hoping it may act as a jumpstart for your Blueprints adoption.

Before you start creating your own Blueprint using Microsoft’s Blueprint Manger go through this article which introduces Blueprint Concept and Blueprint Manager. To start building your own Blueprint, Blueprint Manager comes with “Microsoft Blueprint Factory” which is nothing but a Blueprint itself.

When you select “Microsoft Blueprint Factory” from Blueprint Manager and click “Unfold”, it prompts for project you want to unfold this Blueprint Factory. I usually prefer Blank Solution to unfold Blueprint Factory.

Figure - 1

Before unfolding starts, user will be prompted for the project name.

Figure - 2
By default, the name is shown as BlueprintFactory. You can change the name according to your requirements. I will say it as MyFirstBlueprint.
Unfolded project in blank solution will look like this.

Figure - 3
When you right click MyFirstBlueprint project you get a context menu with caption “Blueprints” containing different options to configure various aspects of the blueprint.

Figure - 4
Note: Menu item Blueprints is the key for Blueprint development. All guidance is provided through this menu. Whenever a blueprint is unfolded on a machine, it adds a blueprint context menu item specific to this unfolded blueprint which provides guidance to the developer.

Next step is to configure my Blueprint. Click Blueprints -> Edit Configuration. Blueprint will display Blueprint Editor which allows user to configure all possible options available with blueprint viz.

1. General Configuration
2. Options
3. Menus
4. Commands
5. Related Blueprints
6. Installation Actions.

In this article we will see some of the general configuration settings and further discuss how to implement commands and menus in our custom blueprints.
Edit Configuration will show the following dialogue box.

Figure - 5
On Configuration Tab you can configure

1. Project Name- This name will be used during unfolding of projects and it is also important as far as build artifacts of blueprint is concerned. When we build Blueprint project it creates a zip file containing all information for RSS. The name of this file will be <ProjectName> Build will also generate folder named ‘ProjectName_Pacakge’. This contains all files needed to run blueprint. To see all this information you have to open Windows Explorer after build and see your blueprint directory. You cannot see this information in Visual Studio itself.

2. Type of Blueprint can be Microsoft or Third Party or hidden.

3. Publisher will be your company name.

4. You can also give RSS feed link here. This is very important from a delivery and deployment perspective as Blueprints Manager can update existing blueprints through this RSS Feed whenever a new version is available from within Visual Studio IDE itself.

We will now see how to use Commands and Menus Tabs to create our own Menu option for “Blueprints”.Each menu item has command associated with it. On click of this menu item, command associated with it gets executed.
Blueprint shows/executes its commands or menus from .Net library called Blueprint Extension Library. This library has to follow some standard so that blueprint understands it properly.

1. Assembly name for extension library should start with Blueprint’s project name.

2. Class which handles commands must derive from ‘BPMExtensionBase’ from ‘Microsoft.SoftwareFactories.Blueprints’

3. You must copy the extension library to “extensions” folder inside “MyFirstBlueprint” project folder.

Click Blueprints -> Add Extensions to create a new extension.

Figure - 6
It will add extension library project to the solution and set Assembly Name as required by the blueprint. Specify project name for extension using the following dialog box. 
Figure - 7

Now solution will look like this

Figure - 8

MyExtensions project contains class “ExtensionClass” with a sample command implemented that will help you to implement your own commands. You get Menu “Blueprints” even on MyExtensions project which will give option to see workflow which will give step by step guidance on how to use this project for your blueprint. Modify class ExtensionClass to implement your own commands. Build MyExtensions project using Visual Studio.

Now the next step is to specify commands from MyExtension which will be used by “MyFirstBlueprint”. For this we will again click on Blueprints -> Edit Configuration menu to get Blueprint Editor. Open Commands Tab.

Add new command and fill the details as follows

Figure - 9
Once command is added, the only step remains is to associate this command with a Menu Item. Create new Menu Item using Blueprint Editor’s Menus Tab.

Figure - 10
Visibility has many options supported as Filters. You can see all available Filters from Blueprints -> Workflow menu item.  These filters decide for which project or project item you want to show this context menu item.
Save both projects and build them. Once built and auto install is successful, you can see your blueprint entry in Blueprint manager. Unfold it and see whether you get custom menu created by you.
NOTE. Remember you have checkbox “Custom Menu Filters” checked on Blueprint Manager to see your own menus.

Figure - 11

Hope this helps to quick start Blueprint development. Once Menus are appearing you can write whole lot of customized stuff in your commands to auto generate repetitive code or provide any kind of guidance needed.






November 7, 2008

Cloud computing made possible with Azure

Ranked as number 2 in the Gartner strategic technologies of 2009, Cloud computing as a technology has been marked as the potential to have a significant impact in the enterprises in the future. Microsoft too has been investing a lot in shaping the cloud of the future to will help users, be it start-ups, individuals, hobbyists or even large enterprises; build a new breed of applications and potentially create new business of the future.

In the recently held PDC 2008,  Microsoft announced Azure, a cloud platform from Microsoft which comprise of the following technologies:

  1. Windows Services – A compute platform of the likes of Windows would be the basic building block for executing web application, WCF services on the cloud
  2. .Net Services – A service enabler that will allow enterprises to extend locally running services on the cloud and providing additional capabilities on service interface level security, connectivity and workflow
  3. SQL Data services –  To support on-premise SQL Server like storage capabilities on the cloud
  4. Live Services

We are working closely with Microsoft on these set of technologies to understand and in turn realize the learning’s into real life solutions that will benefit our customers in their businesses. Through these blogs we shall attempt to share learning’s and developments happening on the Microsoft cloud platform aka Azure.

You can download the Azure developer SDK from here. You can view details on the session we took at PDC 2008 here.

November 6, 2008

Command prompt instance counting

Here's something that I accidently noticed today. Inside of a command prompt, of you type "cmd" (to launch  a commonad prompt), it treats this as a new instance, though no new windows is opened. Now if you type "exit", the command window still stays since there were effectively two instances. Only when you type "exit" the second time, will the command window close.

This can go on at any level (I didn't really try too many levels). You can also easily make out the # instances by looking at the title bar. Every time you type "cmd" at a command prompt, you will see "- cmd" get added to the title. With every "exit" one of these goes away till you are back to the default title you had started up with and another "exit" will close the window.

November 3, 2008

WPF: Working with command line arguments

The other day I hit upon this blog that describes how to work with command line arguments and custom file extensions in WPF applications. We have been using this in our application for a while now. I am however surprised to note that double clicking a file required Avi to work with different syntax.

I am simplifying the logic we have in our application to showcase here and it is pretty much same as what Avi has shown.

        public static string commandArgs = string.Empty;


        protected override void OnStartup(StartupEventArgs e)


            if (e.Args!= null && e.Args.Length > 0)


                commandArgs = e.Args[0];



We have some custom file extension that we have associated with our application. And on double clicking such a file, our application launches and we still very much get the file name as part of command line arguments, without having to worry about accesssing it from AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData[0].

And we have been working with .net 3.5 and our code works both without SP1 and with SP1

November 2, 2008

More on Windows 7

Microsoft has shared the pre-beta build of Windows 7 during the recently concluded PDC 2008 with the attendees. If you are planning to write applications that target Windows 7, this Windows 7 Developer Guide will help get an idea of the features to expect in this OS. For engineering details keep reading the Engineering Windows 7 blog and if you are developer, you can check out the Windows 7 blog for Developers.

Subscribe to this blog's feed

Follow us on

Blogger Profiles

Infosys on Twitter