Wednesday, June 22, 2011

Friday, June 17, 2011

Windows Azure 30 Days Pass- Try it out

IF you want to try out Microsoft Windows Azure Application Development

image

http://windowsazurepass.com/?campid=56742C47-F0FB-DF11-B2EA-001F29C6FB82

Nandri(Thanks)

Sreenivasaragavan

Monday, June 13, 2011

Debugger Canvas - VS.NET 2010 Extension

 

This is really cool Extension for VS.NET 2010 with SP1, when it hits breakpoint  Debugger canvas shows just the methods that you are debugging  with call lines and local variables as shown below.

image

 

Here below image I invoked two methods from different class so it opens different windows for each method with Local variables.

image

Here the following images shows the method and its Local Variables .

image

Here is the different options we can set for Debugger canvas, to get here click debug-> Options & Settings from VS.NET 2010 Menu.

image

If you like and wanted to load please Point your IE  to

http://msdn.microsoft.com/en-us/devlabs/debuggercanvas and download

download

FYI. The Debugger Canvas is built on technologies that only ship with Visual Studio Ultimate, such as IntelliTrace and the code analysis features in the Architecture tools.

Nandri(Thanks)

SreenivasaRagavan,

Sunday, June 5, 2011

How to Host WCF Service in BasicHttpBinding & HTTPS

Today One of my Best Friend asked me how to host WCF service in IIS with HTTPS binding . I showed the demo to him from my machine then I thought let me share in my blog here it is.

To host WCF service in HTTPS here are basic steps we need to follow

1) First Create Self contained Certificate ( we are doing in Development )

2) Create Web Site with Port 443 ( Https –secure )

3) Change the some settings in Web.config

First to create Self contained Server Certificate  Open IIS  Manger and select the Server Certificates Icon Under IIS section as shown below

image

image

image

Next Create the Web site with HTTPS binding and 443 port number

image

Next we need to change web.config to set Security mode as  Transport

image

Now browse the site with HTTPS

image

For Production environment you can obtain the Certificates from Verisign or CA and install on the server . 

 

Nandri(Thanks)

Sreenivasa ragavan.

EF 4.1 Code First Approach

In this Blog post we are going to see Entity Framework 4.1 Code First approach.  Here I am going to create Small console application to demonstrate. First of all you may ask question what is code first?

EF code first means first Define the classes this is nothing but our MODEL , then EF will work with theses classes this is called CODE FIRST APPROACH. Here I am going to use  Nuget to get EF 4.1 Reference assemblies from the Internet.  Here is how you get it.

First Create C# Console application then go to tools menu in VS.NET 2010 

image

Once you click Package Manager Console you will provided to execute the  Windows PowerShell prompt to execute the command . The command we need to execute to get  EF 4.0 assemblies is

Install-Package EntityFramework.

image

Next create the Entity class and Context class as shown below

 

DB Context

public class ContactCtx :DbContext
  {
      public DbSet<Contact> Contacts
      {
          get;
          set;
      }
  }

 

Entity


public class Contact
   {
       public int Id
       {
           get;
           set;
       }
       public string Name
       {
           get;
           set;
       }
       public string Phone
       {
           get;
           set;
       }

       public string Email
       {
           get;
           set;
       }
   }

Here I am creating a contact that will be saved in DB.

class Program
  {
      static void Main(string[] args)
      {
          ContactCtx db = new ContactCtx();
         
          db.Contacts.Add(new Contact
          {
              Name = "Vasanth.v",
              Phone = "23232323",
              Email = "v@v.com"
          });
        int a=  db.SaveChanges();
        Console.WriteLine("DB ID is " +a);

       Contact c= db.Contacts.Find(1);
      }

    
  }

when you execute the program the DB is created and the records are added .  EF use SQL Express by default if do not specify .

image

Nandri(Thanks)

SreenivasaRagavan

Thursday, June 2, 2011

Sunday, April 17, 2011

Exposing POCO as OData Service.

OData – Open Protocol Data aka WCF Data Services.

We all know that using EF(Entity Framework) Data model exposing any relational Data source is very very easy.  But here I am going to show how to expose Plain Old CLR Objects as  OData Service.

1) First Create Empty ASP.NET Web Application.

2) Second we need define or create the Entity Classes and we need to define Primary key using DataServiceKey Attribute for each entity as shown below

image

3) Next we need to create the class which exposes the IQueryable properties which returns the collection of Each entity which we created about. here I have defined the Entity as Contact so my IQueryable properties returns collection of Contacts.

image

image

Next we need to add WCF Data Service Template to this project to host the OData Service with the above Entities.

image

Once we added WCF Data Service Template next we need to specify the Entity class name as shown below.  Next we can set the Access rule for Entity

here I set all Entity have read only access.

image

Now run the service you will see the ODataservice with Two Entity exposed .

image

IF we browse the following URL we get  Contacts details http://localhost:52200/WcfDataService1.svc/MyContacts 

image

Nandri(Thanks)

SreenivasaRagavan

Friday, April 15, 2011

Get Silverlight 5.0 Beta

Silverlight 5 continues the pace of rapid innovation, building on Silverlight 4's capabilities in the areas of rich applications and premium media experiences. With over 40 new features, the Silverlight 5 beta highlights dramatic video quality and performance improvements, as well as new capabilities that improve developer productivity

image

Here is the URL where you can download Silverlight 5.0 beta http://www.silverlight.net/getstarted/silverlight-5-beta/

Nandri(Thanks)

Sreenivasaragavan.R

Wednesday, April 6, 2011

Escape Sequence for { in C#

Today there was need for me to print {} char in my console output. I knew there are standard Escape Sequences in C# but I was not aware of Escape Sequence for  {.  when I was binging I found the solution to this problem I just wanted to share with my Blog readers.

image

Nandri(Thanks)

Sreenivasaragavan.

Sunday, March 27, 2011

System.Runtime.Caching Namespace for Caching-II

In this Blog Post we are going to see how we can use this API in .NET Applications.

image

Here I am going create my own CacheLib class with the following   Add, Get, Remove methods as shown above.

First Let me create a C# class file called  CacheLib.cs  in which  I am going to implement all the CURD methods for the Cache object. to do let us create ObjectCache Cache = MemoryCache.Default . (Memory Cache) Then we Add Get, Add, Remove Methods.

Add any object to Cache:

Here  I am created the Generic Add method.

image

Get or Retrieve Cached Item from Cache Object: Generic get method

image

Remove or Delete from Cache:

image

User Defined class to store in Cache.

image

the following Code snippet shows how to add and retrieve data from Cache object .

image

Nandri(Thanks)

Sreenivasa Ragavan

Wednesday, March 23, 2011

System.Runtime.Caching Namespace for Caching

Today I happened to come across System.Runtime.Caching  new API in .NET Framework  4.0 this System.Runtime.Caching namespace contains types that let you implement caching in NET Framework applications. The good thing about this API is we can use this API same as  ASP.NET Out Caching functionality but without a dependency on the System.Web assembly.

When I Reference System.Runtime.Caching  assembly in my project it was showing not available then after looking project properties I found out this Namespace NOT part of the .NET 4 client profile, it is only in the full .NET 4 Framework.  then I changed my project to Full .NET Framework as shown below.

image

Next Post we will see how we can use this API to Cache.

Nandri(Thanks)

Sreenivasaragavan

Wednesday, March 16, 2011

IE 9 Released

Point your Old browser to the following URL and see More Beautiful WEBWe Exchange Bytes

image

http://windows.microsoft.com/en-US/internet-explorer/downloads/ie-9/worldwide-languages

Nandri(Thanks)

SreenivasaRagavan

Going Full Screen Mode in Silverlight

In Silverlight Application using App.Current.Host.Content  IsFullScreen property we can go Full Screen mode.

First get the App.Current.Host.Content value and change to True if IsFullScreen is False.

image

image

when you click Full Screen Button here is the button click  event handler code.

image

Here is the FullScreenChanged Event Handler.

image

 

Nandri(Thanks)

SreenivasaRagavan

Thursday, March 10, 2011

Visual Studio 2010 SP-1 Released

 

MS Released SP-1 for VS.NET 2010.

image

http://www.microsoft.com/downloads/en/details.aspx?FamilyID=75568aa6-8107-475d-948a-ef22627e57a5&displaylang=en

I downloaded and Installed it went without  any  ERROR.

image

Nandri(Thanks)

Sreenivasaragavan

Tuesday, March 1, 2011

Debugger.Break Method().

This method lives inside System.Diagnostics Namespace. This method Signals a breakpoint to an attached debugger.

image

This is really useful when we debugging .NET Windows Service.   In your Program  add the following line of code wherever you want to break into debug mode:
System.Diagnostics.Debugger.Break()

Nandri(Thanks)

Sreenivasaragavan

Sunday, February 27, 2011

AggregateException In Parallel Programming

AggregateException which can contain one or more exceptions. Suppose when you have multiple threads of execution each of the threads could throw and exception as a result .NET Framework “bundle” all of these exceptions which occurred in the parallel operations into one exception which is passed (thrown) back to the caller. Acting as a container for all exceptions generated in a function is the function which the AggregateException Class performs.

To Understand any new concept its better to show in an action with Example.

image

image

Nandri(Thanks)

Sreenivasaragavan

Friday, February 25, 2011

Installing Windows-7 Service Pack 1

Here are the steps to install Windows 7 Service pack 1.  First you need to download System Update Readiness Tool for Windows 7  either 32 bit or b4bit based on what version of windows you installed on your Machine. Here is the link where you can download the above mentioned tool.

image

http://www.microsoft.com/DOWNLOADS/en/details.aspx?FamilyId=914fbc5b-1fba-4bae-a7c3-d2c47c6fcffc&displaylang=en

why this tool needed?

This tool is being offered because an inconsistency was found in the Windows servicing store which may prevent the successful installation of future updates, service packs, and software. This tool checks your computer for such inconsistencies and tries to resolve issues if found.

image

image

image

Nandri(Thanks)

Sreenivasa Ragavan

Saturday, February 19, 2011

Parallel.For and Parallel.ForEach in .NET 4.0

Basically Parallel.For and Parallel.ForEach is very similar to For and ForEach except that  Paralle.For and ForEach use Multiple threads to execute different iterations of the loop body.  Using Parallel loops are very good way to  speed of the multicore machines.

image

when we execute the above code. here is the result .

image

Nandri(Thanks)

SreenivasaRagavan.

Parallel Programming .NET 4.0 IV–Using Task.Factory.FromAsync convert Task to asynchronous Method.

In this blog post we are going to see how we can covert asynchronous method call to Task by using Task.Factory.FromAsync method.

For this example I am going to call the following  Web service  to get the weather information for given Zip code.

image

when adding this above Web Service Reference we need to check  Generate asynchronous Operations. so that VS.NET will generate Async method calls. 

image

First Create Instance of the web service Proxy. and Create the Task with Begin and End methods which you are going to invoke on Web Service.  Basically this web service takes input as Zip code and returns as 1 week Weather forecast info  .

image

 

Here is the weather result for the Zipcode =75023

image

suppose Web service response is null then I can canceling the task .  here is the result for unknown zip code.

image

Here I am scheduling a continuation task once we get the response from Web Service. I feel this way of calling Web Service is more convenient than an IAsyncResult.

Nandri(Thanks)

SreenivasaRagavan.