Saturday, December 14, 2013

ASP.NET Web API vs WCF

With Microsoft.NET Stack there are lots of way to create service like ASP.NET Web Service, WCF(Windows Communication Foundation) service and now ASP.NET Web API. The developer often get confused mainly between WCF Service and Web API. So I thought it is a good idea to write a blog post to about differences between ASP.NET Web API and WCF Service.

Difference between ASP.NET Web API  and WCF Service:


  1. WCF services support multiple transport support like HTTP,TCP,UDP,MSMQ and allow switching between them while ASP.NET Web API is used only http based services best suited for http service and mobile based application back end service. It is an quick and easy way to create http service.
  2. WCF support multiple encodings like Text,MTOM while ASP.NET Web API support wide range of media types like XML,JSON etc.
  3. WCF Service support Request-Reply, One way and duplex exchange patterns while HTTP service only support Request/Return pattern.

When to choose? What? WCF or Web API


  • Choose WCF if you want to support any other transport protocol then HTTP.
  • Choose Web API when you want to create resource oriented services very quickly.
  • Choose Web API when you want to serve wide variety of clients like browsers, mobile etc.
  • Choose WCF when you want to support message queuing, one way messaging and duplicate message communication.
Share:
Wednesday, December 11, 2013

Creating first python application in Visual Studio

Before some time I have blogged about Python tools in Visual Studio and explained how we install python tools with visual studio and start developing python application with the one of greatest editor in class Visual Studio. In this post we are going to learn how we can create a python application in Visual Studio.

First check whether Python Interpreters are install on your machine or not?


First step for creating python application with Visual Studio is to check whether Python interpreters are installed or not not. To Check this after installing Python tools for Visual Studio go to Tools menu –> Python Environments and it will show a list of python environments available.

Python Enviroments for Visual Studio

If it is not installed, you need to download from http://www.python.org/. I have already installed Python 3.3 so its showing there.

Creating first python application:


Once you install Python tools for visual studio it will also have options to create python application in visual studio. So go to file menu –> new project options->templates-> Select python it will show all the python options available for visual studio just like below.

Visual Studio Python Project Templates

There you have few options like below.
  • From Existing Python Code
  • Python Application
  • Django Project
  • Python MPI Application
  • IronPython Application
  • IronPython WPF application
  • IronPython Silverlight Web page
  • IronPython Windows application
As we need to create a simple application for python we are going to our first application with Python application.Once create project it will create application like following.

Python application in visual studio solution explorer

Now open that PythonApplication1.Py and write following code.

Python Hello World application with Visual Studio

And now run application via pressing f5.

PythonApplicationfromvisualStudioOutput

That’s it we are able to run our first application in Visual Studio. Woohoo!! Hope you like it. Stay tuned for more..
Share:
Sunday, December 8, 2013

Python tools for Visual Studio

Lots of people complaining that Microsoft does not support open source that is a myth about Microsoft it does support there are lots of open source initiative done by Microsoft and Python tools for Visual Studio is one of them.

With the help of this plugin you are able to do work on python on Visual Studio one of best editor in class.

Here is the link from you can download the Python tools for Visual Studio. Python tools are available for Visual Studio 2010,2012 and 2013. You can download the tools according your version.

PythonToolsForVisualStudioCodePlex

Go to download and here you can download Python as per your visual studio version 2010,2012 or 2013.

Pythontoolsfordiffrentvisualstudioversion

Installing Python Tools for Visual Studio :


Installation of Python tools is quite easy. Download the setup files and run exe of for that setup. You will get following screen.

PythonForVisualStudioInstallation1

Accept terms in License Agreement and click on install. There is also advance mode available where you can select different options.

PythonForVisualStudioInstallation2

Once you click install it will start installing python tools.

PythonForVisualStudioInstallation3

Once installation complete it will notify like below.

PythonForVisualStudioInstallation4

Click on finish and Yep you are ready to write code in python for Visual Studio.

Python and Visual Studio :


Now once you open Visual Studio and create a new project it will also Python as new language options.

VisualStudioPythonProject

Here you have various like From Existing Application, Python Application, DJango Project, Python MPI application. You can also see there is IronPython support is also there.

That’s it. You can see its very easy. Hope you like it. Stay tuned for more..
Share:

ASP.NET and Web Tools 2013.1 Tools for Visual Studio 2012

Recently Microsoft has released ASP.NET and Web Tools 2013.1 for visual studio 2012. There are tons of new feature and improvements are there. So Now it’s possible to have all the latest feature on ASP.NET stack on Visual Studio 2012 like ASP.NET MVC 5, ASP.NET Web API 2, Entity Framework 6.0 etc.
You can download this update from the following link.

http://www.asp.net/visual-studio/overview/2012/aspnet-and-web-tools-20131-for-visual-studio-2012

ASP.NET MVC 5:


Once you install this tools, ASP.NET MVC 5 templates are also installed.

ASPNETMVC5VisualStudio2012ProjectTemplate

So now you can use all the ASP.NET MVC 5 feature like One ASP.NET, ASP.NET Identity,Bootstrap MVC template, Authentication Filters,Filter overrides etc.

ASP.NET Web API 2:


ASP.NET Web API2 is also available here.

ASPNETWebAPI2VisualStudio2012ProjectTemplate 

So all ASP.NET Web API2 features like attribute routing, Cross Origin Resource Sharing, OWIN (Open Web Interface for .NET), IHttpActionResult, Web API Odata all are available Visual Studio 2012.

Twitter BootStrap Template:


Now ASP.NET MVC 5 application comes with Twitter Bootstrap, So all goodies of Twitter Bootstrap will be there with your ASP.NET MVC application.

Entity Framework 6.0:


It’s also comes with Entity framework 6.0. Where you have some new great features like Async Query and Save,Connection Resiliency, Code-Based Configuration, Dependency Resolution, Interception/SQL Logging, Improved transaction support etc will be available in Visual Studio 2012 itself.

Also there is a new version of Nuget is also available with this release. So now if one developer has Visual Studio 2012 and another one is having Visual Studio 2013 then also they can work on same project.

This post is a just an overview of all the new features that are available with this release. I will write in detail about all this new features. Stay tuned for more..
Share:
Saturday, December 7, 2013

New Milestone achieved–600,000 visits for my blog

Today, I got a good news from www.sitemeter.com that My blog has completed 600,000 visits for my blog. It’s a great achievement. I have never thought I will go so far.  It’s because of readers of my blog so thank you very much for your support and love without you guys this was not possible. On this occasion I would also like to thank my family for always being there and supporting me whatever I do and believing in me that I could do that. Thanks you very family!!.

Here are few statistics of my blog.

Statistics for my blog - A blog about asp.net mvc and other microsoft technologies

So till now 600,505 visits and 763,338 page views I got about 253 unique visits everyday.

Again thank you very much all readers of this blog without you it was not possible. I will keep writing blog whenever I get time from my professional commitments. I am loving all the communities are there and always been part of that.

Please also suggest me topics for writing blog post. Stay tuned for more..
Share:
Saturday, November 30, 2013

Getting started with ELMAH and ASP.NET MVC

We all need a framework to log exceptions in our web application. Today, We are going to learn about same. ELMAH(Error Logging Modules and Handlers) is an application wide error logging framework. How we can install it in ASP.NET MVC.

What is ELMAH:


ELMAH(Error logging Modules and Handlers) is an application wide error logging facility that is an pluggable framework. It can dynamically added to running an ASP.NET application. You also have Nuget package for the same.
You can find more information about on following link.

https://code.google.com/p/elmah/

Once you install ELMAH, You can have following advantages
  1. You can log almost all unhandled exceptions in the system.
  2. An RSS feed of last 15 errors from the log
  3. An email notification of each error occurs.
  4. A remote web page to log all the exceptions.
  5. You can insert log a various locations like files text file, SQL Server, Oracle etc.

ELMAH NuGet Package:


There is a nuget package also available for ELMAH. You can find at following link.

http://www.nuget.org/packages/elmah/

and Following Command you have to run for installing NuGet Pacakge.

ELMAHNuGetPackageASP.NETMVC

Getting Started with ASP.NET MVC and ELMAH:


So Let’s first create a new project with ASP.NET MVC  from Visual Studio via File->New Project –>ASP.NET MVC 4 Application.

ELMAHNewProjectMVC

Once you click OK it will ask you for type of application like following. We are going to select internet application here.

TypeofApplicationELMAHMVC

Once you click on OK it will create new ASP.NET MVC 4 Application. Once our ASP.NET MVC 4 application is ready. It’s time to add ELMAH to ASP.NET MVC4 Application. The best way to add ELMAH is nuget package so we don’t have to worry about the configuration settings in web.config. So Let’s go to Tools-> Library Package Manager-> Package Manger Console and run the NuGet Command like following.

PackageManagerConsoleNuGetPacakgeELMAH

So now if you see in web.config all configuration is added.
Web.ConfigErrorHandlingSection
Now let’s run our asp.net application via pressing f5.

ElMAHASP.NETMVCSite

Now let’s create some unhandled errors for example test Action Result does not exist in our ASP.NET MVC application. So Let’s write that in URL and it will give error like following.

ErrorElMAHASPNETMVC

Now let’s see whether this error is logged by ELMAH or not. Here you go

ErrorLogELMAH

Once you click on details. It will show details error like following.

DetailErroLogELMAH

That’s it. You can see now it’s very easy to log errors and unhandled exceptions in ELMAH. There are various options to log errors in ELMAH we will see that in future posts.

Hope you like it. Stay tuned for more..
Share:

How to find days in year except Saturday and Sunday in C#

Before 2 years I have written a blog post to find Saturday and Sunday in given date range.  It has gain a lot of popularity and on that blog post one user ask about how we can find days in year except Saturday and Sunday in C#. This post is a in reply for that. Following is a code for that.
using System;

namespace DatimeApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            DateTime startDate = new DateTime(2013, 1, 1);
            DateTime endDate = new DateTime(2013, 12, 31);

            TimeSpan diff = endDate - startDate;
            int days = diff.Days;
            int j=0;
            for (var i = 0; i <= days; i++)
            {
                var testDate = startDate.AddDays(i);
                if (testDate.DayOfWeek != DayOfWeek.Saturday && testDate.DayOfWeek != DayOfWeek.Sunday)
                {
                    j = j + 1;
                    Console.WriteLine(testDate.ToShortDateString());
                }
            }
            Console.WriteLine(string.Format("Total Days:{0}",j));
            Console.ReadLine();
        }
    }
}

If you see above code,  Its very easy to find all days except Saturday and Sunday in a year. I have created two dates with Start date and end date and then I found a difference between those two days. And then in for loop I have checked whether they are weekdays then I have printed a date for that. I have calculated all days except Saturday and Sunday for year 2013. At the end I have printed total days also.

Once you run the code following is a output as expected.

FindDaysExceptSatudaySundayInCsharp

That’s it. Hope you like it. Stay tuned for more…
Share:

Support this blog-Buy me a coffee

Buy me a coffeeBuy me a coffee
Search This Blog
Subscribe to my blog

  

My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews