<?xml version="1.0"?><?xml-stylesheet type="text/xsl" href="/rss.xsl"?><rss version="2.0"><channel><title>pocwebapi Wiki Rss Feed</title><link>http://pocwebapi.codeplex.com/</link><description>pocwebapi Wiki Rss Description</description><item><title>Updated Wiki: Documentation</title><link>http://pocwebapi.codeplex.com/documentation?version=7</link><description>&lt;div class="wikidoc"&gt;
&lt;h2&gt;&lt;strong&gt;Intr&lt;/strong&gt;&lt;strong&gt;oduction&amp;nbsp;&lt;/strong&gt;&amp;nbsp;&lt;/h2&gt;
&lt;p&gt;The purpose of this article is to create a&lt;strong&gt;&amp;nbsp;proof of concept&amp;nbsp;&lt;/strong&gt;to demonstrate the feasibility of&amp;nbsp;&lt;a href="http://www.asp.net/web-api"&gt;ASP.NET WebAPI&lt;/a&gt;&amp;nbsp;final release.&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Update&amp;nbsp;&lt;/strong&gt;&amp;nbsp;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Modify code for Visual Studio 2012 &lt;/li&gt;&lt;li&gt;Replace Autofac with Castle Windsor for Dependency Injection &amp;nbsp;&amp;nbsp; &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Prerequisite:&lt;/strong&gt;&amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://msftdbprodsamples.codeplex.com/"&gt;AdventureWorksLT2008R2&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://www.asp.net/web-api"&gt;ASP.Net WebAPI&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://code.google.com/p/autofac/downloads/list"&gt;&lt;span style="text-decoration:line-through"&gt;Autofac for Dependency Injection&lt;/span&gt;&lt;/a&gt;&amp;nbsp; &amp;nbsp;&lt;a title="Castle Windsor" href="http://docs.castleproject.org/Default.aspx?Page=MainPage&amp;NS=Windsor&amp;AspxAutoDetectCookieSupport=1" target="_blank"&gt;Castle
 Windsor for DI&amp;nbsp;&lt;/a&gt;&amp;nbsp; &lt;/li&gt;&lt;li&gt;&lt;a href="http://logging.apache.org/log4net/download.html"&gt;Log4Net&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://www.microsoft.com/download/en/details.aspx?displaylang=en&amp;id=8363"&gt;&lt;span style="text-decoration:line-through"&gt;&amp;nbsp;EntityFramework 4.1&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;a title="Entity Framework 5" href="http://blogs.msdn.com/b/adonet/archive/2012/08/15/ef5-released.aspx" target="_blank"&gt;Entity
 Framework 5&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/li&gt;&lt;li&gt;&lt;a href="https://github.com/jquery/jquery-tmpl"&gt;jQuery Templates plugin (jquery-tmpl)&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a title="Visual Studio Express 2012 for Web" href="http://www.microsoft.com/visualstudio/eng/products/visual-studio-express-for-web" target="_blank"&gt;Visual Studio Express 2012&lt;/a&gt;&lt;a href="https://github.com/jquery/jquery-tmpl"&gt;&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Goals to achieve:&lt;/strong&gt;&amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Any user should be able to view products &lt;/li&gt;&lt;li&gt;Product would be filtered by Categories &lt;/li&gt;&lt;li&gt;User should be able to add products in cart &lt;/li&gt;&lt;li&gt;Only registered user will be able to submit cart &lt;/li&gt;&lt;li&gt;User should be able to register into system &lt;/li&gt;&lt;li&gt;User will get confirmation Invoice after generating order in system. &lt;/li&gt;&lt;/ul&gt;
&lt;h2&gt;&lt;strong&gt;Architecture for this POC&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;I am not following any specific Architecture Pattern, although while designing this POC, I&amp;nbsp;&lt;strong&gt;try to follow&lt;/strong&gt;&amp;nbsp;some of the key design principles like:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Separation_of_concerns"&gt;Separation of concerns&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Abstraction_(computer_science)"&gt;Abstraction&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself"&gt;Don't repeat yourself&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/KISS_principle"&gt;KISS principle&lt;/a&gt; &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;span&gt;Again I am repeating my word&amp;nbsp;&lt;strong&gt;try to follow&amp;hellip;..&amp;nbsp;&lt;img src="http://www.codeproject.com/script/Forums/Images/smiley_smile.gif" alt="Smile | :)" align="top"&gt;&amp;nbsp;&lt;/strong&gt;. So, all comments/suggestions are more than welcome to discuss
 and I am always ready to adopt changes, or you can do it yourself by join&amp;nbsp;&lt;a href="http://pocwebapi.codeplex.com/"&gt;@CodePlex&lt;/a&gt;. The initial Skeleton for this application is as per below diagram:&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/1.PNG" alt="Architecture" width="652" height="500"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Step-by-Step&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#step1"&gt;Step 1: Create a basic Application Structure Layout&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#step2"&gt;Step 2: Create the Data Access Layer&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#step3"&gt;Step 3: Create the Service Layer&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#step4"&gt;Step 4: Create the API Layer&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#step5"&gt;Step 5: Integration of Dependency Injection using Castle Windsor&lt;/a&gt;&amp;nbsp;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#step6"&gt;Step 6: Add Views to solution&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#step7"&gt;Step 7: Unit test and resolve issues&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#step8"&gt;Step 8: Deploy application on IIS&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#step9"&gt;Step 9: Provide Cross Domain Support&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;h2&gt;&lt;strong&gt;Step 1: Create a basic Application Structure Layout&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;For more information on ASP.NET WebAPI, watch Videos and Tutorials&amp;nbsp;&lt;a href="http://www.asp.net/web-api"&gt;here&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add a blank Solution named as&amp;nbsp;&lt;strong&gt;Application&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add a new Project (Class Library) named as&amp;nbsp;&lt;strong&gt;Application.DAL&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Repeat above process and create four more Class Library projects named as &amp;ndash;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Application.Model&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Repository&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Common&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Service&lt;/strong&gt; &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;span&gt;Now, application will look like below screen-shot&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/4.PNG" alt="Solution 1" width="252" height="352"&gt;&lt;/p&gt;
&lt;p&gt;Next, add a new Project named as&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;as ASP.Net MVC 4 Web Application. After click on OK, select template as Web API&lt;/p&gt;
&lt;p&gt;&lt;span&gt;This will add a full functional Web API template Application into our main solution.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/7.PNG" alt="Solution 1" width="232" height="352"&gt;&lt;/p&gt;
&lt;p&gt;Right click on Application.API project in Solution Explorer and go to properties, than assign a port to be use by this service application ( In my case its 30000). Hit F5 and we are ready with a dummy data as below screen:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/8.PNG" alt="Solution 1" width="652"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Step 2: Prepare Application.DAL, Application.Repository and Application.Model Layers&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Check&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/library/bb399182.aspx"&gt;@MSDN&lt;/a&gt;&amp;nbsp;for more information on Entity Framework&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add Entity Data Model to&amp;nbsp;&lt;strong&gt;Application.DAL&lt;/strong&gt;&amp;nbsp;project. To do this select ADO.NET Entity Data Model from the Data Templates list, and name it as&amp;nbsp;&lt;strong&gt;AdventureWorks.edmx&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Choose&amp;nbsp;&lt;strong&gt;&amp;ldquo;Generate from Database&amp;rdquo;&lt;/strong&gt;&amp;nbsp;and provide the connection string to read the database schema. This will add AdventureWorks.edmx into current project. Right click on the blank space in Entity Model surface and click
 on properties (or alternate press Alt &amp;#43;Enter on keyboard). Now set its Code Generation Strategy as&amp;nbsp;&lt;strong&gt;None&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/10.PNG" alt="Solution 1" width="552" height="300"&gt;&lt;/p&gt;
&lt;p&gt;Now create POCO entities for AdventureWorks Data Model into&amp;nbsp;&lt;strong&gt;Application.Model&lt;/strong&gt;&amp;nbsp;Solution. Check this article to do this job for you on MSDN to use&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/gg558520"&gt;T4 Templates and the Entity
 Framework&lt;/a&gt;&lt;br&gt;
Then, create all required repositories under Application.Repositories.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/11.PNG" alt="Solution 1" width="252" height="500"&gt;&lt;/p&gt;
&lt;p&gt;To build solution, add reference of&amp;nbsp;&lt;strong&gt;Application.Model.dll&lt;/strong&gt;&amp;nbsp;to&amp;nbsp;&lt;strong&gt;Application.DAL.dll&lt;/strong&gt;&amp;nbsp;and&lt;strong&gt;Application.Repository.dll&lt;/strong&gt;&amp;nbsp;projects, and add reference of&amp;nbsp;&lt;strong&gt;Application.DAL.dll&lt;/strong&gt;&amp;nbsp;to&amp;nbsp;&lt;strong&gt;Application.Repository.dll&lt;/strong&gt;project.
 (See below picture for reference)&lt;br&gt;
Before proceeding to next step (designing Application.Service and Application.API Layer), let us see what we have designed yet:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/12.PNG" alt="Solution 1" width="652"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Step 3: Add files to Application.Service Layer&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Before adding files to Service layer let us look at the Goals which we want to achieve.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Any user should be able to view products &lt;/li&gt;&lt;li&gt;Product would be filtered by Categories &lt;/li&gt;&lt;li&gt;User should be able to add products in cart &lt;/li&gt;&lt;li&gt;Only registered user will be able to submit cart &lt;/li&gt;&lt;li&gt;User should be able to register into system &lt;/li&gt;&lt;li&gt;User will get confirmation Invoice after generating order in system. &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To achieve the above mention Goals, we need to add three service classes to Application.Service as per below image&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/13.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/14.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;I am not going in deatils, as the implementation for each methods are clear and easy to understand.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Step 4: Add files to Application.API Layer&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To make this Web API accessed from a broad range of clients like any browsers which use JavaScript or any windows/Mobile platform which supports .dll files, we need to add Controllers with base class as&amp;nbsp;&lt;strong&gt;ApiController&lt;/strong&gt;.&lt;a href="http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api"&gt;More
 details here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;First, we remove the default controllers added by template (HomeController and ValuesController) and then add three new controllers as per below diagram:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/15.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;Again, nothing special in the implementation of these methods, they all jst push the data to service layer.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step5"&gt;Step 5: Integration of Dependency Injection with WebAPI using Castle Windsor&lt;/a&gt;&amp;nbsp;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The implementation is very much straight forward and clear.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;Solution Explorer, right-click the References node and click Manage NuGet Packages&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/16.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;It will open the below screen.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/Working/Nuget_Castle.png" alt="" width="892" height="184"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Click on install and it will add below two references in solution&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/Working/Nuget_Castle_Ref.png" alt="" width="380" height="288"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Create an adopter for Castle Windsor as&amp;nbsp;&lt;strong&gt;WindsorActivator&amp;nbsp;&lt;/strong&gt;to implement&amp;nbsp;&lt;strong&gt;IHttpControllerActivator&amp;nbsp;&lt;/strong&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div id="premain0"&gt;&lt;img id="preimg0" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse0"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre0" lang="cs"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;class&lt;/span&gt; WindsorActivator : IHttpControllerActivator
    {
        &lt;span&gt;private&lt;/span&gt; &lt;span&gt;readonly&lt;/span&gt; IWindsorContainer container;

        &lt;span&gt;public&lt;/span&gt; WindsorActivator(IWindsorContainer container)
        {
            &lt;span&gt;this&lt;/span&gt;.container = container;
        }

        &lt;span&gt;public&lt;/span&gt; IHttpController Create(
            HttpRequestMessage request,
            HttpControllerDescriptor controllerDescriptor,
            Type controllerType)
        {
            &lt;span&gt;var&lt;/span&gt; controller =
                (IHttpController)&lt;span&gt;this&lt;/span&gt;.container.Resolve(controllerType);

            request.RegisterForDispose(
                &lt;span&gt;new&lt;/span&gt; Release(
                    () =&amp;gt; &lt;span&gt;this&lt;/span&gt;.container.Release(controller)));

            &lt;span&gt;return&lt;/span&gt; controller;
        }

        &lt;span&gt;private&lt;/span&gt; &lt;span&gt;class&lt;/span&gt; Release : IDisposable
        {
            &lt;span&gt;private&lt;/span&gt; &lt;span&gt;readonly&lt;/span&gt; Action release;

            &lt;span&gt;public&lt;/span&gt; Release(Action release)
            {
                &lt;span&gt;this&lt;/span&gt;.release = release;
            }

            &lt;span&gt;public&lt;/span&gt; &lt;span&gt;void&lt;/span&gt; Dispose()
            {
                &lt;span&gt;this&lt;/span&gt;.release();
            }
        }

    } &lt;/pre&gt;
&lt;div&gt;
&lt;p&gt;&amp;nbsp;&lt;span&gt;The&amp;nbsp;&lt;/span&gt;&lt;strong&gt;installer&lt;/strong&gt;&lt;span&gt;&amp;nbsp;uses the&amp;nbsp;&lt;/span&gt;&lt;code&gt;container&lt;/code&gt;&lt;span&gt;&amp;nbsp;parameter of the&amp;nbsp;&lt;/span&gt;&lt;code&gt;Install&lt;/code&gt;&lt;span&gt;&amp;nbsp;method to&amp;nbsp;&lt;/span&gt;&lt;code&gt;Register&lt;/code&gt;&lt;span&gt;&amp;nbsp;controllers using
 Windsor's&amp;nbsp;&lt;/span&gt;&lt;a title="Fluent Registration API" href="http://docs.castleproject.org/Windsor.Fluent-Registration-API.ashx"&gt;Fluent Registration API&lt;/a&gt;&lt;span&gt;.&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Now we need to tell Castle Windsor to know about all dependencies for it to manage them. For that, we create a new class&amp;nbsp;&lt;strong&gt;DependencyInstaller&amp;nbsp;&lt;/strong&gt;to implement&amp;nbsp;&lt;strong&gt;IWindsorInstaller&lt;/strong&gt;. The installer uses the container
 parameter of the Install() method to Register dependencies using Windsor's Fluent Registration API. As per below implementation&amp;nbsp;every time&amp;nbsp;we add any new class to Controller/Service/Repository in our application, it will be automatically registered,
 the only thing we need follow is naming convention, i.e. all Controller class should end with Controller similarly Service and Repository classes should end with Service and Repository.&amp;nbsp;&lt;/p&gt;
&lt;div id="premain1"&gt;&lt;img id="preimg1" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse1"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre1" lang="cs"&gt;        &lt;span&gt;public&lt;/span&gt; &lt;span&gt;void&lt;/span&gt; Install(IWindsorContainer container, IConfigurationStore store)
        {
            container.Register(
                        Component.For&amp;lt;ILogService&amp;gt;()
                            .ImplementedBy&amp;lt;LogService&amp;gt;()
                            .LifeStyle.PerWebRequest,

                        Component.For&amp;lt;IDatabaseFactory&amp;gt;()
                            .ImplementedBy&amp;lt;DatabaseFactory&amp;gt;()
                            .LifeStyle.PerWebRequest,

                        Component.For&amp;lt;IUnitOfWork&amp;gt;()
                            .ImplementedBy&amp;lt;UnitOfWork&amp;gt;()
                            .LifeStyle.PerWebRequest,

                        AllTypes.FromThisAssembly().BasedOn&amp;lt;IHttpController&amp;gt;().LifestyleTransient(),

                        AllTypes.FromAssemblyNamed(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Application.Service&amp;quot;&lt;/span&gt;)
                            .Where(type =&amp;gt; type.Name.EndsWith(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Service&amp;quot;&lt;/span&gt;)).WithServiceAllInterfaces().LifestylePerWebRequest(),

                        AllTypes.FromAssemblyNamed(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Application.Repository&amp;quot;&lt;/span&gt;)
                            .Where(type =&amp;gt; type.Name.EndsWith(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Repository&amp;quot;&lt;/span&gt;)).WithServiceAllInterfaces().LifestylePerWebRequest()
                        );
        }
    } &lt;/pre&gt;
&lt;div&gt;
&lt;p&gt;&amp;nbsp;Next, in final step create and configure&amp;nbsp;the Windsor container in Application's constructor inside Global.asax.cs, &amp;nbsp;so that it will be automatically dispose when application exits.&amp;nbsp;&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div id="premain2"&gt;&lt;img id="preimg2" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse2"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre2" lang="cs"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;class&lt;/span&gt; WebApiApplication : System.Web.HttpApplication
    {
        &lt;span&gt;private&lt;/span&gt; &lt;span&gt;readonly&lt;/span&gt; IWindsorContainer container;

        &lt;span&gt;public&lt;/span&gt; WebApiApplication()
        {
            &lt;span&gt;this&lt;/span&gt;.container =
                &lt;span&gt;new&lt;/span&gt; WindsorContainer().Install(&lt;span&gt;new&lt;/span&gt; DependencyInstaller());
        }

        &lt;span&gt;public&lt;/span&gt; &lt;span&gt;override&lt;/span&gt; &lt;span&gt;void&lt;/span&gt; Dispose()
        {
            &lt;span&gt;this&lt;/span&gt;.container.Dispose();
            &lt;span&gt;base&lt;/span&gt;.Dispose();
        }


        &lt;span&gt;protected&lt;/span&gt; &lt;span&gt;void&lt;/span&gt; Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            GlobalConfiguration.Configuration.Services.Replace(
                &lt;span&gt;typeof&lt;/span&gt;(IHttpControllerActivator),
                &lt;span&gt;new&lt;/span&gt; WindsorActivator(&lt;span&gt;this&lt;/span&gt;.container));
        }
    }&amp;lt;logservice&amp;gt;&amp;lt;ilogservice&amp;gt;&amp;lt;unitofwork&amp;gt;&amp;lt;iunitofwork&amp;gt;&amp;lt;databasefactory&amp;gt;&amp;lt;idatabasefactory&amp;gt;
            &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;idatabasefactory&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;databasefactory&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;iunitofwork&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;unitofwork&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;ilogservice&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;logservice&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Now we are ready to test our application. Hit F5 and check the browser with following url&amp;rsquo;s:&amp;nbsp;&lt;br&gt;
http://localhost:30000/api/products : will result all Product Categories&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/20.PNG" alt="Solution 1" width="652"&gt;&lt;/p&gt;
&lt;p&gt;http://localhost:30000/api/products/2 : will result all Products with ProductcategoryID as 2&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/21.PNG" alt="Solution 1" width="652"&gt;&lt;/p&gt;
&lt;p&gt;To check other methods, First we will add some Views in current solution.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Step 6: Add View to solution&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Delete all default files and folders from Views Folder, and add three Html and their supportive Javascript File as. For this POC we will use html files, and some jquery libraries like:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;jquery.tmpl.js :&lt;/strong&gt;&amp;nbsp;to create template based screen, and&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;jquery.validationEngine.js :&lt;/strong&gt;&amp;nbsp;to validate form data&lt;/p&gt;
&lt;p&gt;Now the structure will looks like below picture :&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/22.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;For details code in html and JS file please look into the code. In next step I am going to resolve problems.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Step 7: Resolve issues&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Before run the application Right Click on Products.htm and click on Set As start Page. Now hit F5&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/23.PNG" alt="Solution 1" width="700" height="300"&gt;&lt;/p&gt;
&lt;p&gt;It means, two WebAPI methods in ProductsController.cs are working perfectly. In JavaScript, on page load we are calling first method inside&amp;nbsp;&lt;strong&gt;product.js&lt;/strong&gt;&amp;nbsp;as:&lt;/p&gt;
&lt;div id="premain3"&gt;&lt;img id="preimg3" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse3"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre3" lang="js"&gt;                    var productcategoriesAddress = &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;/api/products/&amp;quot;&lt;/span&gt;;
                    $(function () {
                        $(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;#tblRight'&lt;/span&gt;).hide();
                        $.getJSON(
                                productcategoriesAddress,
                                function (data) {
                                    var parents = jQuery.grep(data, function (a) { &lt;span&gt;return&lt;/span&gt; a.ParentProductCategoryID == null });
                                    var childs = jQuery.grep(data, function (a) { &lt;span&gt;return&lt;/span&gt; a.ParentProductCategoryID != null });
                                    $.&lt;span&gt;each&lt;/span&gt;(parents,
                                        function (index, &lt;span&gt;value&lt;/span&gt;) {
                                            var categorydata = [];
                                            var subCategory = &lt;span&gt;'&lt;/span&gt;&lt;span&gt;'&lt;/span&gt;;
                                            var subChild = jQuery.grep(childs, function (a) { &lt;span&gt;return&lt;/span&gt; a.ParentProductCategoryID == &lt;span&gt;value&lt;/span&gt;.ProductCategoryID });
                                            $.&lt;span&gt;each&lt;/span&gt;(subChild,
                                                function (index, item) {
                                                    var serviceURL = productcategoriesAddress &amp;#43; item.ProductCategoryID;
                                                    subCategory = subCategory &amp;#43; &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;  &amp;quot;&lt;/span&gt; &amp;#43; &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;lt;a href=&amp;quot;&lt;/span&gt;%20&amp;#43;%20serviceURL%20&amp;#43;%20&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt; class=&amp;quot;&lt;/span&gt;menuButton&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;gt;&amp;quot;&lt;/span&gt; &amp;#43; item.Name &amp;#43; &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;lt;/a&amp;gt;&amp;quot;&lt;/span&gt;;
                                                });
                                            categorydata.push({
                                                &lt;span&gt;'&lt;/span&gt;&lt;span&gt;ProductCategoryID'&lt;/span&gt;: &lt;span&gt;value&lt;/span&gt;.ProductCategoryID,
                                                &lt;span&gt;'&lt;/span&gt;&lt;span&gt;ParentCategory'&lt;/span&gt;: &lt;span&gt;value&lt;/span&gt;.Name,
                                                &lt;span&gt;'&lt;/span&gt;&lt;span&gt;ChildCategory'&lt;/span&gt;: subCategory
                                            });
                                            $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#categoryTemplate&amp;quot;&lt;/span&gt;).tmpl(categorydata).appendTo(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#categories&amp;quot;&lt;/span&gt;);
                                            $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#&amp;quot;&lt;/span&gt; &amp;#43; &lt;span&gt;value&lt;/span&gt;.Name).html(subCategory);
                                        });

                                        GetProducts(&lt;span&gt;1&lt;/span&gt;);
                                }
                            );
                &lt;/pre&gt;
&lt;p&gt;This call hits below method in ProductsController, and returns all Product Category to create the Upper Menu Part&lt;/p&gt;
&lt;div id="premain4"&gt;&lt;img id="preimg4" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse4"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre4" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; IQueryable&amp;lt;productcategory&amp;gt; GetProductCategories()
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with null parameter&amp;quot;&lt;/span&gt;);
                        &lt;span&gt;return&lt;/span&gt; _productservice.GetProductCategories().AsQueryable&amp;lt;productcategory&amp;gt;();
                    }
                &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;productcategory&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;productcategory&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;In ProductService implementation is :&lt;/p&gt;
&lt;div id="premain5"&gt;&lt;img id="preimg5" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse5"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre5" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; IQueryable&amp;lt;productcategory&amp;gt; GetProductCategories()
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with null parameter&amp;quot;&lt;/span&gt;);
                        &lt;span&gt;return&lt;/span&gt; _productservice.GetProductCategories().AsQueryable&amp;lt;productcategory&amp;gt;();
                    }
                &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;productcategory&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;productcategory&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;The second call is to fetch all products depends on selected category. In javascript&lt;/p&gt;
&lt;div id="premain6"&gt;&lt;img id="preimg6" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse6"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre6" lang="js"&gt;                      function GetProducts(ProductCategoryID) {
                        var serviceURL = productcategoriesAddress &amp;#43; ProductCategoryID;
                        $(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;#categories li h1'&lt;/span&gt;).css(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;background'&lt;/span&gt;, &lt;span&gt;'&lt;/span&gt;&lt;span&gt;#736F6E'&lt;/span&gt;);
                        $(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;#mnu'&lt;/span&gt; &amp;#43; ProductCategoryID).css(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;background'&lt;/span&gt;, &lt;span&gt;'&lt;/span&gt;&lt;span&gt;#357EC7'&lt;/span&gt;);
                        $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#loader&amp;quot;&lt;/span&gt;).show();
                        $.ajax({
                            type: &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;GET&amp;quot;&lt;/span&gt;,
                            datatype: &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;json&amp;quot;&lt;/span&gt;,
                            url: serviceURL,
                            context: &lt;span&gt;this&lt;/span&gt;,
                            success: function (&lt;span&gt;value&lt;/span&gt;) {
                                $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#productData&amp;quot;&lt;/span&gt;).html(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;quot;&lt;/span&gt;);
                                $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#productTemplate&amp;quot;&lt;/span&gt;).tmpl(&lt;span&gt;value&lt;/span&gt;).appendTo(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#productData&amp;quot;&lt;/span&gt;);
                                $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#loader&amp;quot;&lt;/span&gt;).hide();
                            }
                        });
                        &lt;span&gt;return&lt;/span&gt; &lt;span&gt;false&lt;/span&gt;;
                    }
                &lt;/pre&gt;
&lt;p&gt;and in ProductsController it goes to&lt;/p&gt;
&lt;div id="premain7"&gt;&lt;img id="preimg7" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse7"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre7" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; IQueryable&amp;lt;product&amp;gt; GetProductByProductCategoryID(&lt;span&gt;int&lt;/span&gt; id)
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with null parameter as : id : &amp;quot;&lt;/span&gt; &amp;#43; id);
                        &lt;span&gt;return&lt;/span&gt; _productservice.GetProductByProductCategoryID(id).AsQueryable&amp;lt;product&amp;gt;();
                    }

                &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;product&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;product&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;In ProductService implementation is :&lt;/p&gt;
&lt;div id="premain8"&gt;&lt;img id="preimg8" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse8"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre8" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; IQueryable&amp;lt;product&amp;gt; GetProductByProductCategoryID(&lt;span&gt;int&lt;/span&gt; id)
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with null parameter as : id : &amp;quot;&lt;/span&gt; &amp;#43; id);
                        &lt;span&gt;return&lt;/span&gt; _productservice.GetProductByProductCategoryID(id).AsQueryable&amp;lt;product&amp;gt;();
                    }
                &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;product&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;product&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Next, let us try to add some products to Cart and Checkout cart&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/28.PNG" alt="Solution 1" width="400" height="300"&gt;&lt;/p&gt;
&lt;p&gt;On clicking on checkout It redirect to Checkout.htm page and asking for either Login using existing CustomerID or Register for a new Customer.&lt;br&gt;
Click on&amp;nbsp;&lt;strong&gt;Register&lt;/strong&gt;&amp;nbsp;link to create a new Customer.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/29.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;Submit form after clicking on Register button and see if Posting is working or not. Again its success!!!&lt;/p&gt;
&lt;p&gt;Now we will try to update records for AddressLine2, and Update is also working fine!!!&lt;/p&gt;
&lt;p&gt;In both scenario (Add or Update Customer) we are calling below method of CutomerControllers.cs&lt;/p&gt;
&lt;div id="premain9"&gt;&lt;img id="preimg9" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse9"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre9" lang="cs"&gt;                     &lt;span&gt;public&lt;/span&gt; &lt;span&gt;int&lt;/span&gt; PostCustomer(CustomerDTO customer)
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with parameter as : customer: &amp;quot;&lt;/span&gt; &amp;#43; customer);
                        &lt;span&gt;return&lt;/span&gt; _customerService.SaveOrUpdateCustomer(customer);
                    }
                &lt;/pre&gt;
&lt;p&gt;In CustomerService implementation is :&lt;/p&gt;
&lt;div id="premain10"&gt;&lt;img id="preimg10" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse10"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre10" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;int&lt;/span&gt; SaveOrUpdateCustomer(CustomerDTO customer)
                    {
                        &lt;span&gt;string&lt;/span&gt; passwordSalt = CreateSalt(&lt;span&gt;5&lt;/span&gt;);
                        &lt;span&gt;string&lt;/span&gt; pasword = CreatePasswordHash(customer.Password, passwordSalt);
                        Customer objCustomer;

                        &lt;span&gt;if&lt;/span&gt; (customer.CustomerID != &lt;span&gt;0&lt;/span&gt;)
                            objCustomer = _customerRepository.GetById(customer.CustomerID);
                        &lt;span&gt;else&lt;/span&gt;
                            objCustomer = &lt;span&gt;new&lt;/span&gt; Customer();

                        objCustomer.NameStyle = customer.NameStyle;
                        objCustomer.Title = customer.Title;
                        objCustomer.FirstName = customer.FirstName;
                        objCustomer.MiddleName = customer.MiddleName;
                        objCustomer.LastName = customer.LastName;
                        objCustomer.Suffix = customer.Suffix;
                        objCustomer.CompanyName = customer.CompanyName;
                        objCustomer.SalesPerson = customer.SalesPerson;
                        objCustomer.EmailAddress = customer.EmailAddress;
                        objCustomer.Phone = customer.Phone;
                        objCustomer.PasswordHash = pasword;
                        objCustomer.PasswordSalt = passwordSalt;
                        objCustomer.ModifiedDate = DateTime.Now;
                        objCustomer.rowguid = Guid.NewGuid();

                        &lt;span&gt;if&lt;/span&gt; (customer.CustomerID != &lt;span&gt;0&lt;/span&gt;)
                            _customerRepository.Update(objCustomer);
                        &lt;span&gt;else&lt;/span&gt;
                            _customerRepository.Add(objCustomer);

                        _unitOfWork.Commit();
                        SaveOrUpdateAddress(customer, objCustomer.CustomerID);
                        &lt;span&gt;return&lt;/span&gt; objCustomer.CustomerID;
                    }
                &lt;/pre&gt;
&lt;p&gt;Next, click on Submit Order Button, to make previously selected products as an Order and receive Order Invoice.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/33.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;!!!Hurray!!! Order is created in system and invoice is generated with a new Purchase Order. But, wait we got one BUG&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue 1. is fixed with the final release of Asp.Net WebAPI&amp;nbsp;&lt;/strong&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span style="text-decoration:line-through"&gt;&lt;strong&gt;Issue 1:&lt;/strong&gt;&amp;nbsp;we have an issue with Date Format.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/34.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="text-decoration:line-through"&gt;According to,&amp;nbsp;&lt;a href="http://www.hanselman.com/blog/OnTheNightmareThatIsJSONDatesPlusJSONNETAndASPNETWebAPI.aspx"&gt;Scott Hanselman&amp;rsquo;s post&lt;/a&gt;&amp;nbsp;this is a bug and will resolve in next release of ASP.Net
 WebAPI. This issue is resolved using&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/02/18/using-json-net-with-asp-net-web-api.aspx"&gt;solution provided in Henrik's Blog&lt;/a&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/35.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue 2:&lt;/strong&gt;&amp;nbsp;Another issue was, when I try to Checkout Cart using the last created Customer. The error was:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/36.PNG" alt="Solution 1" width="700" height="300"&gt;&lt;/p&gt;
&lt;p&gt;After looking this error, first thought comes that we missed the method in CustomersController.cs, but the method was already there. Further investigation make it clear, that, the reason behind this error was name of this method as ValidateCustomer():&lt;/p&gt;
&lt;div id="premain11"&gt;&lt;img id="preimg11" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse11"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre11" lang="cs"&gt;                     &lt;span&gt;public&lt;/span&gt; CustomerDTO ValidateCustomer(&lt;span&gt;int&lt;/span&gt; id, &lt;span&gt;string&lt;/span&gt; password)
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with parameter as : id and password: &amp;quot;&lt;/span&gt; &amp;#43; id &amp;#43; &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt; and &amp;quot;&lt;/span&gt; &amp;#43; password);
                        &lt;span&gt;return&lt;/span&gt; _customerService.ValidateCustomer(id, password);
                    }
                &lt;/pre&gt;
&lt;p&gt;In CustomerService implementation is :&lt;/p&gt;
&lt;div id="premain12"&gt;&lt;img id="preimg12" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse12"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre12" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; CustomerDTO ValidateCustomer(&lt;span&gt;int&lt;/span&gt; id, &lt;span&gt;string&lt;/span&gt; password)
                    {
                        Customer objCustomer = _customerRepository.GetById(id);
                        &lt;span&gt;if&lt;/span&gt; (objCustomer == &lt;span&gt;null&lt;/span&gt;)
                            &lt;span&gt;return&lt;/span&gt; &lt;span&gt;null&lt;/span&gt;;
                        &lt;span&gt;string&lt;/span&gt; strPasswordHash = objCustomer.PasswordHash;
                        &lt;span&gt;string&lt;/span&gt; strPasswordSalt = strPasswordHash.Substring(strPasswordHash.Length - &lt;span&gt;8&lt;/span&gt;);
                        &lt;span&gt;string&lt;/span&gt; strPasword = CreatePasswordHash(password, strPasswordSalt);

                        &lt;span&gt;if&lt;/span&gt; (strPasword.Equals(strPasswordHash))
                            &lt;span&gt;return&lt;/span&gt; CreateCustomerDTO(objCustomer);
                        &lt;span&gt;else&lt;/span&gt;
                            &lt;span&gt;return&lt;/span&gt; &lt;span&gt;null&lt;/span&gt;;
                    }
                &lt;/pre&gt;
&lt;p&gt;By default the&amp;nbsp;&lt;strong&gt;route configuration&lt;/strong&gt;&amp;nbsp;of Asp.Net WebAPI follows RESTFUL conventions meaning that it will accept only the&amp;nbsp;&lt;strong&gt;Get, Post, Put and Delete&lt;/strong&gt;&amp;nbsp;action names. So when we send a GET request to http://localhost:30000/api/customers/ValidateCustomer/30135/test
 we are basically calling the Get(int id) action and passing id=30135 which obviously crashes because we don&amp;rsquo;t have any method starting with Get which accept Id as parameter. To resolve this issue I need to add a new route definition in&amp;nbsp;&lt;strong&gt;Global.asax&lt;/strong&gt;&amp;nbsp;file
 as:&lt;/p&gt;
&lt;div id="premain13"&gt;&lt;img id="preimg13" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse13"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre13" lang="cs"&gt;                     routes.MapHttpRoute(
                           name: &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;ValidateCustomer&amp;quot;&lt;/span&gt;,
                           routeTemplate: &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;api/{controller}/{action}/{id}/{password}&amp;quot;&lt;/span&gt;,
                           defaults: &lt;span&gt;new&lt;/span&gt; { action = &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;get&amp;quot;&lt;/span&gt; }
                       );
                &lt;/pre&gt;
&lt;p&gt;Adding this line done the magic and Login functinality start waorking&amp;hellip;.&amp;nbsp;&lt;img src="http://www.codeproject.com/script/Forums/Images/smiley_smile.gif" alt="Smile | :)" align="top"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Step 8: Deploy on IIS&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To deploy this API on IIS version 7.5, first, publish only&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;solution to a Folder.&lt;/p&gt;
&lt;p&gt;Next, open IIS Manager and create a new website and set path to Publish folder, and we are done with deployment.&lt;/p&gt;
&lt;p&gt;Now, check whether page is opening or not, in my case, initially I got below error, which is self-explanatory.&lt;br&gt;
The error comes because this application is running on Asp.Net Framework Version 2.0. So, we need to change it to Asp.Net Framework Version 4.0:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/40.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/41.PNG" alt="Solution 1" width="652"&gt;&lt;/p&gt;
&lt;p&gt;To change the Asp.Net Framework from 2.0 to 4.0, follow below steps.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/42.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/43.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;That was not the only reason not to run application, because after made above change in Application pool next error was:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/44.PNG" alt="Solution 1" width="700" height="200"&gt;&lt;/p&gt;
&lt;p&gt;To resolve this error again go to Advance Settings of Application pool and change the identity to Local System from ApplicationPoolIdentity&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/45.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;After modify the Application pool to use Local System, Application starts working on browser...&amp;nbsp;&lt;img src="http://www.codeproject.com/script/Forums/Images/smiley_smile.gif" alt="Smile | :)" align="top"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/46.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;Although IIS errors are depending on servers/Firewall/Network or system to system, so it is very difficult to assume that you will also get the same error as mine. Check these links which help me to resolve some of the IIS issues in
 my work environment.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en/wcf/thread/b990d3ea-3335-40a6-877f-7c295da67a85"&gt;HTTP Error 500.19&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/eu/wcf/thread/39571e42-aca7-469d-8c68-aa59c2da4fcc"&gt;Could Not Load Type &amp;lsquo;System.ServiceModel.Activation.HttpModule&amp;rsquo;&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/k6h9cz8h.aspx"&gt;ASP.NET IIS Registration Tool&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms732012.aspx"&gt;ServiceModel Registration Tool&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Step 9: Cross Domain Support&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The idea behind the Cross Domain Support comes when I try to remove all HTML pages from&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;solution and created a new Empty Web Application (Adventure.Website) which includes only&amp;nbsp;&lt;strong&gt;.html, .Js and .css&lt;/strong&gt;files
 along with images. The structure for this application is as per below image:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/47.PNG" alt="Solution 1" width="300" height="500"&gt;&lt;/p&gt;
&lt;p&gt;Point all URL address to deployed code on IIS, after build and run application, output was null.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/48.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;To resolve this issue I would like to give my special thanks to Carlos&amp;rsquo; blog on MSDN&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2012/02/20/implementing-cors-support-in-asp-net-web-apis.aspx"&gt;Implementing CORS support in ASP.NET Web
 APIs&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;blockquote&gt;
&lt;div&gt;Quote:&lt;/div&gt;
&amp;ldquo;By default, a web page cannot make calls to services (APIs) on a domain other than the one where the page came from. This is a security measure against a group of cross-site forgery attacks in which browsing to a bad site could potentially use the browser
 cookies to get data from a good site which the user had previously logged on (think your bank). There are many situations, however, where getting data from different sites is a perfectly valid scenario, such as mash-up applications which need data from different
 sources.&amp;rdquo;&amp;nbsp;&amp;nbsp;&lt;/blockquote&gt;
&lt;h2&gt;&lt;strong&gt;Code Setup&lt;/strong&gt;&amp;nbsp;&lt;/h2&gt;
&lt;p&gt;Due to size restriction I have attached code in three parts :&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Part 1 : Application.Zip&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Part 2 : Packages.Zip&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Part 3 : AdventureSite.Zip&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Part 1 and Part 3 are independent applications. Whereas, for Part 2 we need to copy its content inside the package folder of Application (Part 1). Please refer below image :&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;img src="http://www.codeproject.com/KB/WCF/350488/Working/Code_setup.png" alt="" width="820" height="377"&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&amp;nbsp;&lt;/h2&gt;
&lt;p&gt;That's it !!! Hope you enjoy this article. I am not an expert, and also I have not followed the entire industry standard at the time of writing this article (time factor).&lt;/p&gt;
&lt;p&gt;All&amp;nbsp;&lt;strong&gt;comment/Vote&lt;/strong&gt;&amp;nbsp;are more than welcome&amp;hellip;.&amp;nbsp;&lt;img src="http://www.codeproject.com/script/Forums/Images/smiley_smile.gif" alt="Smile | :)" align="top"&gt;&amp;nbsp;, whenever, I get time, will try to modify this solution. You can
 also join/contribute to this project on&amp;nbsp;&lt;a href="http://pocwebapi.codeplex.com/"&gt;CodePlex&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Thank's for your time.&lt;/p&gt;
&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>anandranjanpandey</author><pubDate>Sat, 27 Oct 2012 18:49:36 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Documentation 20121027064936P</guid></item><item><title>Updated Wiki: Documentation</title><link>http://pocwebapi.codeplex.com/documentation?version=6</link><description>&lt;div class="wikidoc"&gt;
&lt;h2&gt;&lt;strong&gt;Intr&lt;/strong&gt;&lt;strong&gt;oduction&amp;nbsp;&lt;/strong&gt;&amp;nbsp;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The purpose of this article is to create a&lt;strong&gt;&amp;nbsp;proof of concept&amp;nbsp;&lt;/strong&gt;to demonstrate the feasibility of&amp;nbsp;&lt;a href="http://www.asp.net/web-api"&gt;ASP.NET WebAPI&lt;/a&gt;&amp;nbsp;final release.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Update&amp;nbsp;&lt;/strong&gt;&amp;nbsp;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Modify code for Visual Studio 2012 &lt;/li&gt;&lt;li&gt;Replace Autofac with Castle Windsor for Dependency Injection&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Prerequisite:&lt;/strong&gt;&amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://msftdbprodsamples.codeplex.com/"&gt;AdventureWorksLT2008R2&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://www.asp.net/web-api"&gt;ASP.Net WebAPI&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://code.google.com/p/autofac/downloads/list"&gt;&lt;span style="text-decoration:line-through"&gt;Autofac for Dependency Injection&lt;/span&gt;&lt;/a&gt;&amp;nbsp; &amp;nbsp;&lt;a title="Castle Windsor" href="http://docs.castleproject.org/Default.aspx?Page=MainPage&amp;NS=Windsor&amp;AspxAutoDetectCookieSupport=1" target="_blank"&gt;Castle
 Windsor for DI&amp;nbsp;&lt;/a&gt;&amp;nbsp; &lt;/li&gt;&lt;li&gt;&lt;a href="http://logging.apache.org/log4net/download.html"&gt;Log4Net&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://www.microsoft.com/download/en/details.aspx?displaylang=en&amp;id=8363"&gt;&lt;span style="text-decoration:line-through"&gt;&amp;nbsp;EntityFramework 4.1&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;a title="Entity Framework 5" href="http://blogs.msdn.com/b/adonet/archive/2012/08/15/ef5-released.aspx" target="_blank"&gt;Entity
 Framework 5&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/li&gt;&lt;li&gt;&lt;a href="https://github.com/jquery/jquery-tmpl"&gt;jQuery Templates plugin (jquery-tmpl)&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a title="Visual Studio Express 2012 for Web" href="http://www.microsoft.com/visualstudio/eng/products/visual-studio-express-for-web" target="_blank"&gt;Visual Studio Express 2012&lt;/a&gt;&lt;a href="https://github.com/jquery/jquery-tmpl"&gt;&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Goals to achieve:&lt;/strong&gt;&amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Any user should be able to view products &lt;/li&gt;&lt;li&gt;Product would be filtered by Categories &lt;/li&gt;&lt;li&gt;User should be able to add products in cart &lt;/li&gt;&lt;li&gt;Only registered user will be able to submit cart &lt;/li&gt;&lt;li&gt;User should be able to register into system &lt;/li&gt;&lt;li&gt;User will get confirmation Invoice after generating order in system. &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Architecture for this POC&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I am not following any specific Architecture Pattern, although while designing this POC, I&amp;nbsp;&lt;strong&gt;try to follow&lt;/strong&gt;&amp;nbsp;some of the key design principles like:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Separation_of_concerns"&gt;Separation of concerns&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Abstraction_(computer_science)"&gt;Abstraction&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself"&gt;Don't repeat yourself&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/KISS_principle"&gt;KISS principle&lt;/a&gt; &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;span&gt;Again I am repeating my word&amp;nbsp;&lt;strong&gt;try to follow&amp;hellip;..&amp;nbsp;&lt;img src="http://www.codeproject.com/script/Forums/Images/smiley_smile.gif" alt="Smile | :)" align="top"&gt;&amp;nbsp;&lt;/strong&gt;. So, all comments/suggestions are more than welcome to discuss
 and I am always ready to adopt changes, or you can do it yourself by join&amp;nbsp;&lt;a href="http://pocwebapi.codeplex.com/"&gt;@CodePlex&lt;/a&gt;. The initial Skeleton for this application is as per below diagram:&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/1.PNG" alt="Architecture" width="652" height="500"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Step-by-Step&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#step1"&gt;Step 1: Create a basic Application Structure Layout&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#step2"&gt;Step 2: Create the Data Access Layer&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#step3"&gt;Step 3: Create the Service Layer&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#step4"&gt;Step 4: Create the API Layer&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#step5"&gt;Step 5: Integration of Dependency Injection using Castle Windsor&lt;/a&gt;&amp;nbsp;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#step6"&gt;Step 6: Add Views to solution&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#step7"&gt;Step 7: Unit test and resolve issues&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#step8"&gt;Step 8: Deploy application on IIS&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#step9"&gt;Step 9: Provide Cross Domain Support&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;h2&gt;&lt;strong&gt;Step 1: Create a basic Application Structure Layout&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;For more information on ASP.NET WebAPI, watch Videos and Tutorials&amp;nbsp;&lt;a href="http://www.asp.net/web-api"&gt;here&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add a blank Solution named as&amp;nbsp;&lt;strong&gt;Application&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add a new Project (Class Library) named as&amp;nbsp;&lt;strong&gt;Application.DAL&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Repeat above process and create four more Class Library projects named as &amp;ndash;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Application.Model&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Repository&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Common&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Service&lt;/strong&gt; &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;span&gt;Now, application will look like below screen-shot&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/4.PNG" alt="Solution 1" width="252" height="352"&gt;&lt;/p&gt;
&lt;p&gt;Next, add a new Project named as&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;as ASP.Net MVC 4 Web Application. After click on OK, select template as Web API&lt;/p&gt;
&lt;p&gt;&lt;span&gt;This will add a full functional Web API template Application into our main solution.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/7.PNG" alt="Solution 1" width="232" height="352"&gt;&lt;/p&gt;
&lt;p&gt;Right click on Application.API project in Solution Explorer and go to properties, than assign a port to be use by this service application ( In my case its 30000). Hit F5 and we are ready with a dummy data as below screen:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/8.PNG" alt="Solution 1" width="652"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Step 2: Prepare Application.DAL, Application.Repository and Application.Model Layers&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Check&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/library/bb399182.aspx"&gt;@MSDN&lt;/a&gt;&amp;nbsp;for more information on Entity Framework&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add Entity Data Model to&amp;nbsp;&lt;strong&gt;Application.DAL&lt;/strong&gt;&amp;nbsp;project. To do this select ADO.NET Entity Data Model from the Data Templates list, and name it as&amp;nbsp;&lt;strong&gt;AdventureWorks.edmx&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Choose&amp;nbsp;&lt;strong&gt;&amp;ldquo;Generate from Database&amp;rdquo;&lt;/strong&gt;&amp;nbsp;and provide the connection string to read the database schema. This will add AdventureWorks.edmx into current project. Right click on the blank space in Entity Model surface and click
 on properties (or alternate press Alt &amp;#43;Enter on keyboard). Now set its Code Generation Strategy as&amp;nbsp;&lt;strong&gt;None&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/10.PNG" alt="Solution 1" width="552" height="300"&gt;&lt;/p&gt;
&lt;p&gt;Now create POCO entities for AdventureWorks Data Model into&amp;nbsp;&lt;strong&gt;Application.Model&lt;/strong&gt;&amp;nbsp;Solution. Check this article to do this job for you on MSDN to use&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/gg558520"&gt;T4 Templates and the Entity
 Framework&lt;/a&gt;&lt;br&gt;
Then, create all required repositories under Application.Repositories.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/11.PNG" alt="Solution 1" width="252" height="500"&gt;&lt;/p&gt;
&lt;p&gt;To build solution, add reference of&amp;nbsp;&lt;strong&gt;Application.Model.dll&lt;/strong&gt;&amp;nbsp;to&amp;nbsp;&lt;strong&gt;Application.DAL.dll&lt;/strong&gt;&amp;nbsp;and&lt;strong&gt;Application.Repository.dll&lt;/strong&gt;&amp;nbsp;projects, and add reference of&amp;nbsp;&lt;strong&gt;Application.DAL.dll&lt;/strong&gt;&amp;nbsp;to&amp;nbsp;&lt;strong&gt;Application.Repository.dll&lt;/strong&gt;project.
 (See below picture for reference)&lt;br&gt;
Before proceeding to next step (designing Application.Service and Application.API Layer), let us see what we have designed yet:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/12.PNG" alt="Solution 1" width="652"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Step 3: Add files to Application.Service Layer&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Before adding files to Service layer let us look at the Goals which we want to achieve.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Any user should be able to view products &lt;/li&gt;&lt;li&gt;Product would be filtered by Categories &lt;/li&gt;&lt;li&gt;User should be able to add products in cart &lt;/li&gt;&lt;li&gt;Only registered user will be able to submit cart &lt;/li&gt;&lt;li&gt;User should be able to register into system &lt;/li&gt;&lt;li&gt;User will get confirmation Invoice after generating order in system. &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To achieve the above mention Goals, we need to add three service classes to Application.Service as per below image&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/13.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/14.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;I am not going in deatils, as the implementation for each methods are clear and easy to understand.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Step 4: Add files to Application.API Layer&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To make this Web API accessed from a broad range of clients like any browsers which use JavaScript or any windows/Mobile platform which supports .dll files, we need to add Controllers with base class as&amp;nbsp;&lt;strong&gt;ApiController&lt;/strong&gt;.&lt;a href="http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api"&gt;More
 details here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;First, we remove the default controllers added by template (HomeController and ValuesController) and then add three new controllers as per below diagram:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/15.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;Again, nothing special in the implementation of these methods, they all jst push the data to service layer.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step5"&gt;Step 5: Integration of Dependency Injection with WebAPI using Castle Windsor&lt;/a&gt;&amp;nbsp;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The implementation is very much straight forward and clear.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;Solution Explorer, right-click the References node and click Manage NuGet Packages&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/16.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;It will open the below screen.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/Working/Nuget_Castle.png" alt="" width="892" height="184"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Click on install and it will add below two references in solution&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/Working/Nuget_Castle_Ref.png" alt="" width="380" height="288"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Create an adopter for Castle Windsor as&amp;nbsp;&lt;strong&gt;WindsorActivator&amp;nbsp;&lt;/strong&gt;to implement&amp;nbsp;&lt;strong&gt;IHttpControllerActivator&amp;nbsp;&lt;/strong&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div id="premain0"&gt;&lt;img id="preimg0" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse0"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre0" lang="cs"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;class&lt;/span&gt; WindsorActivator : IHttpControllerActivator
    {
        &lt;span&gt;private&lt;/span&gt; &lt;span&gt;readonly&lt;/span&gt; IWindsorContainer container;

        &lt;span&gt;public&lt;/span&gt; WindsorActivator(IWindsorContainer container)
        {
            &lt;span&gt;this&lt;/span&gt;.container = container;
        }

        &lt;span&gt;public&lt;/span&gt; IHttpController Create(
            HttpRequestMessage request,
            HttpControllerDescriptor controllerDescriptor,
            Type controllerType)
        {
            &lt;span&gt;var&lt;/span&gt; controller =
                (IHttpController)&lt;span&gt;this&lt;/span&gt;.container.Resolve(controllerType);

            request.RegisterForDispose(
                &lt;span&gt;new&lt;/span&gt; Release(
                    () =&amp;gt; &lt;span&gt;this&lt;/span&gt;.container.Release(controller)));

            &lt;span&gt;return&lt;/span&gt; controller;
        }

        &lt;span&gt;private&lt;/span&gt; &lt;span&gt;class&lt;/span&gt; Release : IDisposable
        {
            &lt;span&gt;private&lt;/span&gt; &lt;span&gt;readonly&lt;/span&gt; Action release;

            &lt;span&gt;public&lt;/span&gt; Release(Action release)
            {
                &lt;span&gt;this&lt;/span&gt;.release = release;
            }

            &lt;span&gt;public&lt;/span&gt; &lt;span&gt;void&lt;/span&gt; Dispose()
            {
                &lt;span&gt;this&lt;/span&gt;.release();
            }
        }

    } &lt;/pre&gt;
&lt;div&gt;
&lt;p&gt;&amp;nbsp;&lt;span&gt;The&amp;nbsp;&lt;/span&gt;&lt;strong&gt;installer&lt;/strong&gt;&lt;span&gt;&amp;nbsp;uses the&amp;nbsp;&lt;/span&gt;&lt;code&gt;container&lt;/code&gt;&lt;span&gt;&amp;nbsp;parameter of the&amp;nbsp;&lt;/span&gt;&lt;code&gt;Install&lt;/code&gt;&lt;span&gt;&amp;nbsp;method to&amp;nbsp;&lt;/span&gt;&lt;code&gt;Register&lt;/code&gt;&lt;span&gt;&amp;nbsp;controllers using
 Windsor's&amp;nbsp;&lt;/span&gt;&lt;a title="Fluent Registration API" href="http://docs.castleproject.org/Windsor.Fluent-Registration-API.ashx"&gt;Fluent Registration API&lt;/a&gt;&lt;span&gt;.&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Now we need to tell Castle Windsor to know about all dependencies for it to manage them. For that, we create a new class&amp;nbsp;&lt;strong&gt;DependencyInstaller&amp;nbsp;&lt;/strong&gt;to implement&amp;nbsp;&lt;strong&gt;IWindsorInstaller&lt;/strong&gt;. The installer uses the container
 parameter of the Install() method to Register dependencies using Windsor's Fluent Registration API. As per below implementation&amp;nbsp;every time&amp;nbsp;we add any new class to Controller/Service/Repository in our application, it will be automatically registered,
 the only thing we need follow is naming convention, i.e. all Controller class should end with Controller similarly Service and Repository classes should end with Service and Repository.&amp;nbsp;&lt;/p&gt;
&lt;div id="premain1"&gt;&lt;img id="preimg1" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse1"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre1" lang="cs"&gt;        &lt;span&gt;public&lt;/span&gt; &lt;span&gt;void&lt;/span&gt; Install(IWindsorContainer container, IConfigurationStore store)
        {
            container.Register(
                        Component.For&amp;lt;ILogService&amp;gt;()
                            .ImplementedBy&amp;lt;LogService&amp;gt;()
                            .LifeStyle.PerWebRequest,

                        Component.For&amp;lt;IDatabaseFactory&amp;gt;()
                            .ImplementedBy&amp;lt;DatabaseFactory&amp;gt;()
                            .LifeStyle.PerWebRequest,

                        Component.For&amp;lt;IUnitOfWork&amp;gt;()
                            .ImplementedBy&amp;lt;UnitOfWork&amp;gt;()
                            .LifeStyle.PerWebRequest,

                        AllTypes.FromThisAssembly().BasedOn&amp;lt;IHttpController&amp;gt;().LifestyleTransient(),

                        AllTypes.FromAssemblyNamed(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Application.Service&amp;quot;&lt;/span&gt;)
                            .Where(type =&amp;gt; type.Name.EndsWith(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Service&amp;quot;&lt;/span&gt;)).WithServiceAllInterfaces().LifestylePerWebRequest(),

                        AllTypes.FromAssemblyNamed(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Application.Repository&amp;quot;&lt;/span&gt;)
                            .Where(type =&amp;gt; type.Name.EndsWith(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Repository&amp;quot;&lt;/span&gt;)).WithServiceAllInterfaces().LifestylePerWebRequest()
                        );
        }
    } &lt;/pre&gt;
&lt;div&gt;
&lt;p&gt;&amp;nbsp;Next, in final step create and configure&amp;nbsp;the Windsor container in Application's constructor inside Global.asax.cs, &amp;nbsp;so that it will be automatically dispose when application exits.&amp;nbsp;&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div id="premain2"&gt;&lt;img id="preimg2" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse2"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre2" lang="cs"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;class&lt;/span&gt; WebApiApplication : System.Web.HttpApplication
    {
        &lt;span&gt;private&lt;/span&gt; &lt;span&gt;readonly&lt;/span&gt; IWindsorContainer container;

        &lt;span&gt;public&lt;/span&gt; WebApiApplication()
        {
            &lt;span&gt;this&lt;/span&gt;.container =
                &lt;span&gt;new&lt;/span&gt; WindsorContainer().Install(&lt;span&gt;new&lt;/span&gt; DependencyInstaller());
        }

        &lt;span&gt;public&lt;/span&gt; &lt;span&gt;override&lt;/span&gt; &lt;span&gt;void&lt;/span&gt; Dispose()
        {
            &lt;span&gt;this&lt;/span&gt;.container.Dispose();
            &lt;span&gt;base&lt;/span&gt;.Dispose();
        }


        &lt;span&gt;protected&lt;/span&gt; &lt;span&gt;void&lt;/span&gt; Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            GlobalConfiguration.Configuration.Services.Replace(
                &lt;span&gt;typeof&lt;/span&gt;(IHttpControllerActivator),
                &lt;span&gt;new&lt;/span&gt; WindsorActivator(&lt;span&gt;this&lt;/span&gt;.container));
        }
    }&amp;lt;logservice&amp;gt;&amp;lt;ilogservice&amp;gt;&amp;lt;unitofwork&amp;gt;&amp;lt;iunitofwork&amp;gt;&amp;lt;databasefactory&amp;gt;&amp;lt;idatabasefactory&amp;gt;
            &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;idatabasefactory&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;databasefactory&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;iunitofwork&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;unitofwork&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;ilogservice&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;logservice&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Now we are ready to test our application. Hit F5 and check the browser with following url&amp;rsquo;s:&amp;nbsp;&lt;br&gt;
http://localhost:30000/api/products : will result all Product Categories&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/20.PNG" alt="Solution 1" width="652"&gt;&lt;/p&gt;
&lt;p&gt;http://localhost:30000/api/products/2 : will result all Products with ProductcategoryID as 2&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/21.PNG" alt="Solution 1" width="652"&gt;&lt;/p&gt;
&lt;p&gt;To check other methods, First we will add some Views in current solution.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Step 6: Add View to solution&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Delete all default files and folders from Views Folder, and add three Html and their supportive Javascript File as. For this POC we will use html files, and some jquery libraries like:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;jquery.tmpl.js :&lt;/strong&gt;&amp;nbsp;to create template based screen, and&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;jquery.validationEngine.js :&lt;/strong&gt;&amp;nbsp;to validate form data&lt;/p&gt;
&lt;p&gt;Now the structure will looks like below picture :&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/22.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;For details code in html and JS file please look into the code. In next step I am going to resolve problems.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Step 7: Resolve issues&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Before run the application Right Click on Products.htm and click on Set As start Page. Now hit F5&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/23.PNG" alt="Solution 1" width="700" height="300"&gt;&lt;/p&gt;
&lt;p&gt;It means, two WebAPI methods in ProductsController.cs are working perfectly. In JavaScript, on page load we are calling first method inside&amp;nbsp;&lt;strong&gt;product.js&lt;/strong&gt;&amp;nbsp;as:&lt;/p&gt;
&lt;div id="premain3"&gt;&lt;img id="preimg3" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse3"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre3" lang="js"&gt;                    var productcategoriesAddress = &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;/api/products/&amp;quot;&lt;/span&gt;;
                    $(function () {
                        $(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;#tblRight'&lt;/span&gt;).hide();
                        $.getJSON(
                                productcategoriesAddress,
                                function (data) {
                                    var parents = jQuery.grep(data, function (a) { &lt;span&gt;return&lt;/span&gt; a.ParentProductCategoryID == null });
                                    var childs = jQuery.grep(data, function (a) { &lt;span&gt;return&lt;/span&gt; a.ParentProductCategoryID != null });
                                    $.&lt;span&gt;each&lt;/span&gt;(parents,
                                        function (index, &lt;span&gt;value&lt;/span&gt;) {
                                            var categorydata = [];
                                            var subCategory = &lt;span&gt;'&lt;/span&gt;&lt;span&gt;'&lt;/span&gt;;
                                            var subChild = jQuery.grep(childs, function (a) { &lt;span&gt;return&lt;/span&gt; a.ParentProductCategoryID == &lt;span&gt;value&lt;/span&gt;.ProductCategoryID });
                                            $.&lt;span&gt;each&lt;/span&gt;(subChild,
                                                function (index, item) {
                                                    var serviceURL = productcategoriesAddress &amp;#43; item.ProductCategoryID;
                                                    subCategory = subCategory &amp;#43; &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;  &amp;quot;&lt;/span&gt; &amp;#43; &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;lt;a href=&amp;quot;&lt;/span&gt;%20&amp;#43;%20serviceURL%20&amp;#43;%20&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt; class=&amp;quot;&lt;/span&gt;menuButton&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;gt;&amp;quot;&lt;/span&gt; &amp;#43; item.Name &amp;#43; &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;lt;/a&amp;gt;&amp;quot;&lt;/span&gt;;
                                                });
                                            categorydata.push({
                                                &lt;span&gt;'&lt;/span&gt;&lt;span&gt;ProductCategoryID'&lt;/span&gt;: &lt;span&gt;value&lt;/span&gt;.ProductCategoryID,
                                                &lt;span&gt;'&lt;/span&gt;&lt;span&gt;ParentCategory'&lt;/span&gt;: &lt;span&gt;value&lt;/span&gt;.Name,
                                                &lt;span&gt;'&lt;/span&gt;&lt;span&gt;ChildCategory'&lt;/span&gt;: subCategory
                                            });
                                            $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#categoryTemplate&amp;quot;&lt;/span&gt;).tmpl(categorydata).appendTo(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#categories&amp;quot;&lt;/span&gt;);
                                            $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#&amp;quot;&lt;/span&gt; &amp;#43; &lt;span&gt;value&lt;/span&gt;.Name).html(subCategory);
                                        });

                                        GetProducts(&lt;span&gt;1&lt;/span&gt;);
                                }
                            );
                &lt;/pre&gt;
&lt;p&gt;This call hits below method in ProductsController, and returns all Product Category to create the Upper Menu Part&lt;/p&gt;
&lt;div id="premain4"&gt;&lt;img id="preimg4" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse4"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre4" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; IQueryable&amp;lt;productcategory&amp;gt; GetProductCategories()
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with null parameter&amp;quot;&lt;/span&gt;);
                        &lt;span&gt;return&lt;/span&gt; _productservice.GetProductCategories().AsQueryable&amp;lt;productcategory&amp;gt;();
                    }
                &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;productcategory&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;productcategory&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;In ProductService implementation is :&lt;/p&gt;
&lt;div id="premain5"&gt;&lt;img id="preimg5" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse5"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre5" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; IQueryable&amp;lt;productcategory&amp;gt; GetProductCategories()
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with null parameter&amp;quot;&lt;/span&gt;);
                        &lt;span&gt;return&lt;/span&gt; _productservice.GetProductCategories().AsQueryable&amp;lt;productcategory&amp;gt;();
                    }
                &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;productcategory&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;productcategory&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;The second call is to fetch all products depends on selected category. In javascript&lt;/p&gt;
&lt;div id="premain6"&gt;&lt;img id="preimg6" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse6"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre6" lang="js"&gt;                      function GetProducts(ProductCategoryID) {
                        var serviceURL = productcategoriesAddress &amp;#43; ProductCategoryID;
                        $(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;#categories li h1'&lt;/span&gt;).css(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;background'&lt;/span&gt;, &lt;span&gt;'&lt;/span&gt;&lt;span&gt;#736F6E'&lt;/span&gt;);
                        $(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;#mnu'&lt;/span&gt; &amp;#43; ProductCategoryID).css(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;background'&lt;/span&gt;, &lt;span&gt;'&lt;/span&gt;&lt;span&gt;#357EC7'&lt;/span&gt;);
                        $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#loader&amp;quot;&lt;/span&gt;).show();
                        $.ajax({
                            type: &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;GET&amp;quot;&lt;/span&gt;,
                            datatype: &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;json&amp;quot;&lt;/span&gt;,
                            url: serviceURL,
                            context: &lt;span&gt;this&lt;/span&gt;,
                            success: function (&lt;span&gt;value&lt;/span&gt;) {
                                $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#productData&amp;quot;&lt;/span&gt;).html(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;quot;&lt;/span&gt;);
                                $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#productTemplate&amp;quot;&lt;/span&gt;).tmpl(&lt;span&gt;value&lt;/span&gt;).appendTo(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#productData&amp;quot;&lt;/span&gt;);
                                $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#loader&amp;quot;&lt;/span&gt;).hide();
                            }
                        });
                        &lt;span&gt;return&lt;/span&gt; &lt;span&gt;false&lt;/span&gt;;
                    }
                &lt;/pre&gt;
&lt;p&gt;and in ProductsController it goes to&lt;/p&gt;
&lt;div id="premain7"&gt;&lt;img id="preimg7" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse7"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre7" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; IQueryable&amp;lt;product&amp;gt; GetProductByProductCategoryID(&lt;span&gt;int&lt;/span&gt; id)
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with null parameter as : id : &amp;quot;&lt;/span&gt; &amp;#43; id);
                        &lt;span&gt;return&lt;/span&gt; _productservice.GetProductByProductCategoryID(id).AsQueryable&amp;lt;product&amp;gt;();
                    }

                &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;product&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;product&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;In ProductService implementation is :&lt;/p&gt;
&lt;div id="premain8"&gt;&lt;img id="preimg8" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse8"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre8" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; IQueryable&amp;lt;product&amp;gt; GetProductByProductCategoryID(&lt;span&gt;int&lt;/span&gt; id)
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with null parameter as : id : &amp;quot;&lt;/span&gt; &amp;#43; id);
                        &lt;span&gt;return&lt;/span&gt; _productservice.GetProductByProductCategoryID(id).AsQueryable&amp;lt;product&amp;gt;();
                    }
                &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;product&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;product&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Next, let us try to add some products to Cart and Checkout cart&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/28.PNG" alt="Solution 1" width="400" height="300"&gt;&lt;/p&gt;
&lt;p&gt;On clicking on checkout It redirect to Checkout.htm page and asking for either Login using existing CustomerID or Register for a new Customer.&lt;br&gt;
Click on&amp;nbsp;&lt;strong&gt;Register&lt;/strong&gt;&amp;nbsp;link to create a new Customer.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/29.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;Submit form after clicking on Register button and see if Posting is working or not. Again its success!!!&lt;/p&gt;
&lt;p&gt;Now we will try to update records for AddressLine2, and Update is also working fine!!!&lt;/p&gt;
&lt;p&gt;In both scenario (Add or Update Customer) we are calling below method of CutomerControllers.cs&lt;/p&gt;
&lt;div id="premain9"&gt;&lt;img id="preimg9" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse9"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre9" lang="cs"&gt;                     &lt;span&gt;public&lt;/span&gt; &lt;span&gt;int&lt;/span&gt; PostCustomer(CustomerDTO customer)
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with parameter as : customer: &amp;quot;&lt;/span&gt; &amp;#43; customer);
                        &lt;span&gt;return&lt;/span&gt; _customerService.SaveOrUpdateCustomer(customer);
                    }
                &lt;/pre&gt;
&lt;p&gt;In CustomerService implementation is :&lt;/p&gt;
&lt;div id="premain10"&gt;&lt;img id="preimg10" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse10"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre10" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;int&lt;/span&gt; SaveOrUpdateCustomer(CustomerDTO customer)
                    {
                        &lt;span&gt;string&lt;/span&gt; passwordSalt = CreateSalt(&lt;span&gt;5&lt;/span&gt;);
                        &lt;span&gt;string&lt;/span&gt; pasword = CreatePasswordHash(customer.Password, passwordSalt);
                        Customer objCustomer;

                        &lt;span&gt;if&lt;/span&gt; (customer.CustomerID != &lt;span&gt;0&lt;/span&gt;)
                            objCustomer = _customerRepository.GetById(customer.CustomerID);
                        &lt;span&gt;else&lt;/span&gt;
                            objCustomer = &lt;span&gt;new&lt;/span&gt; Customer();

                        objCustomer.NameStyle = customer.NameStyle;
                        objCustomer.Title = customer.Title;
                        objCustomer.FirstName = customer.FirstName;
                        objCustomer.MiddleName = customer.MiddleName;
                        objCustomer.LastName = customer.LastName;
                        objCustomer.Suffix = customer.Suffix;
                        objCustomer.CompanyName = customer.CompanyName;
                        objCustomer.SalesPerson = customer.SalesPerson;
                        objCustomer.EmailAddress = customer.EmailAddress;
                        objCustomer.Phone = customer.Phone;
                        objCustomer.PasswordHash = pasword;
                        objCustomer.PasswordSalt = passwordSalt;
                        objCustomer.ModifiedDate = DateTime.Now;
                        objCustomer.rowguid = Guid.NewGuid();

                        &lt;span&gt;if&lt;/span&gt; (customer.CustomerID != &lt;span&gt;0&lt;/span&gt;)
                            _customerRepository.Update(objCustomer);
                        &lt;span&gt;else&lt;/span&gt;
                            _customerRepository.Add(objCustomer);

                        _unitOfWork.Commit();
                        SaveOrUpdateAddress(customer, objCustomer.CustomerID);
                        &lt;span&gt;return&lt;/span&gt; objCustomer.CustomerID;
                    }
                &lt;/pre&gt;
&lt;p&gt;Next, click on Submit Order Button, to make previously selected products as an Order and receive Order Invoice.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/33.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;!!!Hurray!!! Order is created in system and invoice is generated with a new Purchase Order. But, wait we got one BUG&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue 1. is fixed with the final release of Asp.Net WebAPI&amp;nbsp;&lt;/strong&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span style="text-decoration:line-through"&gt;&lt;strong&gt;Issue 1:&lt;/strong&gt;&amp;nbsp;we have an issue with Date Format.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/34.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="text-decoration:line-through"&gt;According to,&amp;nbsp;&lt;a href="http://www.hanselman.com/blog/OnTheNightmareThatIsJSONDatesPlusJSONNETAndASPNETWebAPI.aspx"&gt;Scott Hanselman&amp;rsquo;s post&lt;/a&gt;&amp;nbsp;this is a bug and will resolve in next release of ASP.Net
 WebAPI. This issue is resolved using&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/02/18/using-json-net-with-asp-net-web-api.aspx"&gt;solution provided in Henrik's Blog&lt;/a&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/35.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue 2:&lt;/strong&gt;&amp;nbsp;Another issue was, when I try to Checkout Cart using the last created Customer. The error was:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/36.PNG" alt="Solution 1" width="700" height="300"&gt;&lt;/p&gt;
&lt;p&gt;After looking this error, first thought comes that we missed the method in CustomersController.cs, but the method was already there. Further investigation make it clear, that, the reason behind this error was name of this method as ValidateCustomer():&lt;/p&gt;
&lt;div id="premain11"&gt;&lt;img id="preimg11" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse11"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre11" lang="cs"&gt;                     &lt;span&gt;public&lt;/span&gt; CustomerDTO ValidateCustomer(&lt;span&gt;int&lt;/span&gt; id, &lt;span&gt;string&lt;/span&gt; password)
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with parameter as : id and password: &amp;quot;&lt;/span&gt; &amp;#43; id &amp;#43; &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt; and &amp;quot;&lt;/span&gt; &amp;#43; password);
                        &lt;span&gt;return&lt;/span&gt; _customerService.ValidateCustomer(id, password);
                    }
                &lt;/pre&gt;
&lt;p&gt;In CustomerService implementation is :&lt;/p&gt;
&lt;div id="premain12"&gt;&lt;img id="preimg12" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse12"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre12" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; CustomerDTO ValidateCustomer(&lt;span&gt;int&lt;/span&gt; id, &lt;span&gt;string&lt;/span&gt; password)
                    {
                        Customer objCustomer = _customerRepository.GetById(id);
                        &lt;span&gt;if&lt;/span&gt; (objCustomer == &lt;span&gt;null&lt;/span&gt;)
                            &lt;span&gt;return&lt;/span&gt; &lt;span&gt;null&lt;/span&gt;;
                        &lt;span&gt;string&lt;/span&gt; strPasswordHash = objCustomer.PasswordHash;
                        &lt;span&gt;string&lt;/span&gt; strPasswordSalt = strPasswordHash.Substring(strPasswordHash.Length - &lt;span&gt;8&lt;/span&gt;);
                        &lt;span&gt;string&lt;/span&gt; strPasword = CreatePasswordHash(password, strPasswordSalt);

                        &lt;span&gt;if&lt;/span&gt; (strPasword.Equals(strPasswordHash))
                            &lt;span&gt;return&lt;/span&gt; CreateCustomerDTO(objCustomer);
                        &lt;span&gt;else&lt;/span&gt;
                            &lt;span&gt;return&lt;/span&gt; &lt;span&gt;null&lt;/span&gt;;
                    }
                &lt;/pre&gt;
&lt;p&gt;By default the&amp;nbsp;&lt;strong&gt;route configuration&lt;/strong&gt;&amp;nbsp;of Asp.Net WebAPI follows RESTFUL conventions meaning that it will accept only the&amp;nbsp;&lt;strong&gt;Get, Post, Put and Delete&lt;/strong&gt;&amp;nbsp;action names. So when we send a GET request to http://localhost:30000/api/customers/ValidateCustomer/30135/test
 we are basically calling the Get(int id) action and passing id=30135 which obviously crashes because we don&amp;rsquo;t have any method starting with Get which accept Id as parameter. To resolve this issue I need to add a new route definition in&amp;nbsp;&lt;strong&gt;Global.asax&lt;/strong&gt;&amp;nbsp;file
 as:&lt;/p&gt;
&lt;div id="premain13"&gt;&lt;img id="preimg13" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse13"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre13" lang="cs"&gt;                     routes.MapHttpRoute(
                           name: &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;ValidateCustomer&amp;quot;&lt;/span&gt;,
                           routeTemplate: &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;api/{controller}/{action}/{id}/{password}&amp;quot;&lt;/span&gt;,
                           defaults: &lt;span&gt;new&lt;/span&gt; { action = &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;get&amp;quot;&lt;/span&gt; }
                       );
                &lt;/pre&gt;
&lt;p&gt;Adding this line done the magic and Login functinality start waorking&amp;hellip;.&amp;nbsp;&lt;img src="http://www.codeproject.com/script/Forums/Images/smiley_smile.gif" alt="Smile | :)" align="top"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Step 8: Deploy on IIS&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To deploy this API on IIS version 7.5, first, publish only&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;solution to a Folder.&lt;/p&gt;
&lt;p&gt;Next, open IIS Manager and create a new website and set path to Publish folder, and we are done with deployment.&lt;/p&gt;
&lt;p&gt;Now, check whether page is opening or not, in my case, initially I got below error, which is self-explanatory.&lt;br&gt;
The error comes because this application is running on Asp.Net Framework Version 2.0. So, we need to change it to Asp.Net Framework Version 4.0:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/40.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/41.PNG" alt="Solution 1" width="652"&gt;&lt;/p&gt;
&lt;p&gt;To change the Asp.Net Framework from 2.0 to 4.0, follow below steps.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/42.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/43.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;That was not the only reason not to run application, because after made above change in Application pool next error was:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/44.PNG" alt="Solution 1" width="700" height="200"&gt;&lt;/p&gt;
&lt;p&gt;To resolve this error again go to Advance Settings of Application pool and change the identity to Local System from ApplicationPoolIdentity&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/45.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;After modify the Application pool to use Local System, Application starts working on browser...&amp;nbsp;&lt;img src="http://www.codeproject.com/script/Forums/Images/smiley_smile.gif" alt="Smile | :)" align="top"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/46.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;Although IIS errors are depending on servers/Firewall/Network or system to system, so it is very difficult to assume that you will also get the same error as mine. Check these links which help me to resolve some of the IIS issues in
 my work environment.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en/wcf/thread/b990d3ea-3335-40a6-877f-7c295da67a85"&gt;HTTP Error 500.19&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/eu/wcf/thread/39571e42-aca7-469d-8c68-aa59c2da4fcc"&gt;Could Not Load Type &amp;lsquo;System.ServiceModel.Activation.HttpModule&amp;rsquo;&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/k6h9cz8h.aspx"&gt;ASP.NET IIS Registration Tool&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms732012.aspx"&gt;ServiceModel Registration Tool&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Step 9: Cross Domain Support&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The idea behind the Cross Domain Support comes when I try to remove all HTML pages from&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;solution and created a new Empty Web Application (Adventure.Website) which includes only&amp;nbsp;&lt;strong&gt;.html, .Js and .css&lt;/strong&gt;files
 along with images. The structure for this application is as per below image:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/47.PNG" alt="Solution 1" width="300" height="500"&gt;&lt;/p&gt;
&lt;p&gt;Point all URL address to deployed code on IIS, after build and run application, output was null.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/48.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;To resolve this issue I would like to give my special thanks to Carlos&amp;rsquo; blog on MSDN&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2012/02/20/implementing-cors-support-in-asp-net-web-apis.aspx"&gt;Implementing CORS support in ASP.NET Web
 APIs&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;blockquote&gt;
&lt;div&gt;Quote:&lt;/div&gt;
&amp;ldquo;By default, a web page cannot make calls to services (APIs) on a domain other than the one where the page came from. This is a security measure against a group of cross-site forgery attacks in which browsing to a bad site could potentially use the browser
 cookies to get data from a good site which the user had previously logged on (think your bank). There are many situations, however, where getting data from different sites is a perfectly valid scenario, such as mash-up applications which need data from different
 sources.&amp;rdquo;&amp;nbsp;&amp;nbsp;&lt;/blockquote&gt;
&lt;h2&gt;&lt;strong&gt;Code Setup&lt;/strong&gt;&amp;nbsp;&lt;/h2&gt;
&lt;p&gt;Due to size restriction I have attached code in three parts :&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Part 1 : Application.Zip&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Part 2 : Packages.Zip&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Part 3 : AdventureSite.Zip&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Part 1 and Part 3 are independent applications. Whereas, for Part 2 we need to copy its content inside the package folder of Application (Part 1). Please refer below image :&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;img src="http://www.codeproject.com/KB/WCF/350488/Working/Code_setup.png" alt="" width="820" height="377"&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&amp;nbsp;&lt;/h2&gt;
&lt;p&gt;That's it !!! Hope you enjoy this article. I am not an expert, and also I have not followed the entire industry standard at the time of writing this article (time factor).&lt;/p&gt;
&lt;p&gt;All&amp;nbsp;&lt;strong&gt;comment/Vote&lt;/strong&gt;&amp;nbsp;are more than welcome&amp;hellip;.&amp;nbsp;&lt;img src="http://www.codeproject.com/script/Forums/Images/smiley_smile.gif" alt="Smile | :)" align="top"&gt;&amp;nbsp;, whenever, I get time, will try to modify this solution. You can
 also join/contribute to this project on&amp;nbsp;&lt;a href="http://pocwebapi.codeplex.com/"&gt;CodePlex&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Thank's for your time.&lt;/p&gt;
&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>anandranjanpandey</author><pubDate>Sat, 27 Oct 2012 18:49:05 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Documentation 20121027064905P</guid></item><item><title>Updated Wiki: Home</title><link>http://pocwebapi.codeplex.com/wikipage?version=8</link><description>&lt;div class="wikidoc"&gt;
&lt;h2&gt;&lt;strong&gt;Intr&lt;/strong&gt;&lt;strong&gt;oduction&amp;nbsp;&lt;/strong&gt;&amp;nbsp;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;The purpose of this article is to create a&lt;strong&gt;&amp;nbsp;proof of concept&amp;nbsp;&lt;/strong&gt;to demonstrate the feasibility of&amp;nbsp;&lt;a href="http://www.asp.net/web-api"&gt;ASP.NET WebAPI&lt;/a&gt;&amp;nbsp;final release.&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Update&amp;nbsp;&lt;/strong&gt;&amp;nbsp;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Modify code for Visual Studio 2012 &lt;/li&gt;&lt;li&gt;Replace Autofac with Castle Windsor for Dependency Injection&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Prerequisite:&lt;/strong&gt;&amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://msftdbprodsamples.codeplex.com/"&gt;AdventureWorksLT2008R2&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://www.asp.net/web-api"&gt;ASP.Net WebAPI&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://code.google.com/p/autofac/downloads/list"&gt;&lt;span style="text-decoration:line-through"&gt;Autofac for Dependency Injection&lt;/span&gt;&lt;/a&gt;&amp;nbsp; &amp;nbsp;&lt;a title="Castle Windsor" href="http://docs.castleproject.org/Default.aspx?Page=MainPage&amp;NS=Windsor&amp;AspxAutoDetectCookieSupport=1" target="_blank"&gt;Castle
 Windsor for DI&amp;nbsp;&lt;/a&gt;&amp;nbsp; &lt;/li&gt;&lt;li&gt;&lt;a href="http://logging.apache.org/log4net/download.html"&gt;Log4Net&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://www.microsoft.com/download/en/details.aspx?displaylang=en&amp;id=8363"&gt;&lt;span style="text-decoration:line-through"&gt;&amp;nbsp;EntityFramework 4.1&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;a title="Entity Framework 5" href="http://blogs.msdn.com/b/adonet/archive/2012/08/15/ef5-released.aspx" target="_blank"&gt;Entity
 Framework 5&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/li&gt;&lt;li&gt;&lt;a href="https://github.com/jquery/jquery-tmpl"&gt;jQuery Templates plugin (jquery-tmpl)&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a title="Visual Studio Express 2012 for Web" href="http://www.microsoft.com/visualstudio/eng/products/visual-studio-express-for-web" target="_blank"&gt;Visual Studio Express 2012&lt;/a&gt;&lt;a href="https://github.com/jquery/jquery-tmpl"&gt;&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Goals to achieve:&lt;/strong&gt;&amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Any user should be able to view products &lt;/li&gt;&lt;li&gt;Product would be filtered by Categories &lt;/li&gt;&lt;li&gt;User should be able to add products in cart &lt;/li&gt;&lt;li&gt;Only registered user will be able to submit cart &lt;/li&gt;&lt;li&gt;User should be able to register into system &lt;/li&gt;&lt;li&gt;User will get confirmation Invoice after generating order in system. &lt;/li&gt;&lt;/ul&gt;
&lt;h2&gt;&lt;strong&gt;Architecture for this POC&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;I am not following any specific Architecture Pattern, although while designing this POC, I&amp;nbsp;&lt;strong&gt;try to follow&lt;/strong&gt;&amp;nbsp;some of the key design principles like:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Separation_of_concerns"&gt;Separation of concerns&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Abstraction_(computer_science)"&gt;Abstraction&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself"&gt;Don't repeat yourself&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/KISS_principle"&gt;KISS principle&lt;/a&gt; &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;span&gt;Again I am repeating my word&amp;nbsp;&lt;strong&gt;try to follow&amp;hellip;..&amp;nbsp;&lt;img src="http://www.codeproject.com/script/Forums/Images/smiley_smile.gif" alt="Smile | :)" align="top"&gt;&amp;nbsp;&lt;/strong&gt;. So, all comments/suggestions are more than welcome to discuss
 and I am always ready to adopt changes, or you can do it yourself by join&amp;nbsp;&lt;a href="http://pocwebapi.codeplex.com/"&gt;@CodePlex&lt;/a&gt;. The initial Skeleton for this application is as per below diagram:&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/1.PNG" alt="Architecture" width="652" height="500"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Step-by-Step&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#step1"&gt;Step 1: Create a basic Application Structure Layout&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#step2"&gt;Step 2: Create the Data Access Layer&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#step3"&gt;Step 3: Create the Service Layer&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#step4"&gt;Step 4: Create the API Layer&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#step5"&gt;Step 5: Integration of Dependency Injection using Castle Windsor&lt;/a&gt;&amp;nbsp;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#step6"&gt;Step 6: Add Views to solution&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#step7"&gt;Step 7: Unit test and resolve issues&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#step8"&gt;Step 8: Deploy application on IIS&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#step9"&gt;Step 9: Provide Cross Domain Support&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;h2&gt;&lt;strong&gt;Step 1: Create a basic Application Structure Layout&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;For more information on ASP.NET WebAPI, watch Videos and Tutorials&amp;nbsp;&lt;a href="http://www.asp.net/web-api"&gt;here&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add a blank Solution named as&amp;nbsp;&lt;strong&gt;Application&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add a new Project (Class Library) named as&amp;nbsp;&lt;strong&gt;Application.DAL&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Repeat above process and create four more Class Library projects named as &amp;ndash;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Application.Model&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Repository&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Common&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Service&lt;/strong&gt; &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;span&gt;Now, application will look like below screen-shot&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/4.PNG" alt="Solution 1" width="252" height="352"&gt;&lt;/p&gt;
&lt;p&gt;Next, add a new Project named as&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;as ASP.Net MVC 4 Web Application. After click on OK, select template as Web API&lt;/p&gt;
&lt;p&gt;&lt;span&gt;This will add a full functional Web API template Application into our main solution.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/7.PNG" alt="Solution 1" width="232" height="352"&gt;&lt;/p&gt;
&lt;p&gt;Right click on Application.API project in Solution Explorer and go to properties, than assign a port to be use by this service application ( In my case its 30000). Hit F5 and we are ready with a dummy data as below screen:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/8.PNG" alt="Solution 1" width="652"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Step 2: Prepare Application.DAL, Application.Repository and Application.Model Layers&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Check&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/library/bb399182.aspx"&gt;@MSDN&lt;/a&gt;&amp;nbsp;for more information on Entity Framework&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add Entity Data Model to&amp;nbsp;&lt;strong&gt;Application.DAL&lt;/strong&gt;&amp;nbsp;project. To do this select ADO.NET Entity Data Model from the Data Templates list, and name it as&amp;nbsp;&lt;strong&gt;AdventureWorks.edmx&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Choose&amp;nbsp;&lt;strong&gt;&amp;ldquo;Generate from Database&amp;rdquo;&lt;/strong&gt;&amp;nbsp;and provide the connection string to read the database schema. This will add AdventureWorks.edmx into current project. Right click on the blank space in Entity Model surface and click
 on properties (or alternate press Alt &amp;#43;Enter on keyboard). Now set its Code Generation Strategy as&amp;nbsp;&lt;strong&gt;None&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/10.PNG" alt="Solution 1" width="552" height="300"&gt;&lt;/p&gt;
&lt;p&gt;Now create POCO entities for AdventureWorks Data Model into&amp;nbsp;&lt;strong&gt;Application.Model&lt;/strong&gt;&amp;nbsp;Solution. Check this article to do this job for you on MSDN to use&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/gg558520"&gt;T4 Templates and the Entity
 Framework&lt;/a&gt;&lt;br&gt;
Then, create all required repositories under Application.Repositories.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/11.PNG" alt="Solution 1" width="252" height="500"&gt;&lt;/p&gt;
&lt;p&gt;To build solution, add reference of&amp;nbsp;&lt;strong&gt;Application.Model.dll&lt;/strong&gt;&amp;nbsp;to&amp;nbsp;&lt;strong&gt;Application.DAL.dll&lt;/strong&gt;&amp;nbsp;and&lt;strong&gt;Application.Repository.dll&lt;/strong&gt;&amp;nbsp;projects, and add reference of&amp;nbsp;&lt;strong&gt;Application.DAL.dll&lt;/strong&gt;&amp;nbsp;to&amp;nbsp;&lt;strong&gt;Application.Repository.dll&lt;/strong&gt;project.
 (See below picture for reference)&lt;br&gt;
Before proceeding to next step (designing Application.Service and Application.API Layer), let us see what we have designed yet:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/12.PNG" alt="Solution 1" width="652"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Step 3: Add files to Application.Service Layer&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Before adding files to Service layer let us look at the Goals which we want to achieve.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Any user should be able to view products &lt;/li&gt;&lt;li&gt;Product would be filtered by Categories &lt;/li&gt;&lt;li&gt;User should be able to add products in cart &lt;/li&gt;&lt;li&gt;Only registered user will be able to submit cart &lt;/li&gt;&lt;li&gt;User should be able to register into system &lt;/li&gt;&lt;li&gt;User will get confirmation Invoice after generating order in system. &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To achieve the above mention Goals, we need to add three service classes to Application.Service as per below image&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/13.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/14.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;I am not going in deatils, as the implementation for each methods are clear and easy to understand.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Step 4: Add files to Application.API Layer&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To make this Web API accessed from a broad range of clients like any browsers which use JavaScript or any windows/Mobile platform which supports .dll files, we need to add Controllers with base class as&amp;nbsp;&lt;strong&gt;ApiController&lt;/strong&gt;.&lt;a href="http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api"&gt;More
 details here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;First, we remove the default controllers added by template (HomeController and ValuesController) and then add three new controllers as per below diagram:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/15.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;Again, nothing special in the implementation of these methods, they all jst push the data to service layer.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step5"&gt;Step 5: Integration of Dependency Injection with WebAPI using Castle Windsor&lt;/a&gt;&amp;nbsp;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The implementation is very much straight forward and clear.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;Solution Explorer, right-click the References node and click Manage NuGet Packages&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/16.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;It will open the below screen.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/Working/Nuget_Castle.png" alt="" width="892" height="184"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Click on install and it will add below two references in solution&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/Working/Nuget_Castle_Ref.png" alt="" width="380" height="288"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Create an adopter for Castle Windsor as&amp;nbsp;&lt;strong&gt;WindsorActivator&amp;nbsp;&lt;/strong&gt;to implement&amp;nbsp;&lt;strong&gt;IHttpControllerActivator&amp;nbsp;&lt;/strong&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div id="premain0"&gt;&lt;img id="preimg0" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse0"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre0" lang="cs"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;class&lt;/span&gt; WindsorActivator : IHttpControllerActivator
    {
        &lt;span&gt;private&lt;/span&gt; &lt;span&gt;readonly&lt;/span&gt; IWindsorContainer container;

        &lt;span&gt;public&lt;/span&gt; WindsorActivator(IWindsorContainer container)
        {
            &lt;span&gt;this&lt;/span&gt;.container = container;
        }

        &lt;span&gt;public&lt;/span&gt; IHttpController Create(
            HttpRequestMessage request,
            HttpControllerDescriptor controllerDescriptor,
            Type controllerType)
        {
            &lt;span&gt;var&lt;/span&gt; controller =
                (IHttpController)&lt;span&gt;this&lt;/span&gt;.container.Resolve(controllerType);

            request.RegisterForDispose(
                &lt;span&gt;new&lt;/span&gt; Release(
                    () =&amp;gt; &lt;span&gt;this&lt;/span&gt;.container.Release(controller)));

            &lt;span&gt;return&lt;/span&gt; controller;
        }

        &lt;span&gt;private&lt;/span&gt; &lt;span&gt;class&lt;/span&gt; Release : IDisposable
        {
            &lt;span&gt;private&lt;/span&gt; &lt;span&gt;readonly&lt;/span&gt; Action release;

            &lt;span&gt;public&lt;/span&gt; Release(Action release)
            {
                &lt;span&gt;this&lt;/span&gt;.release = release;
            }

            &lt;span&gt;public&lt;/span&gt; &lt;span&gt;void&lt;/span&gt; Dispose()
            {
                &lt;span&gt;this&lt;/span&gt;.release();
            }
        }

    } &lt;/pre&gt;
&lt;div&gt;
&lt;p&gt;&amp;nbsp;&lt;span&gt;The&amp;nbsp;&lt;/span&gt;&lt;strong&gt;installer&lt;/strong&gt;&lt;span&gt;&amp;nbsp;uses the&amp;nbsp;&lt;/span&gt;&lt;code&gt;container&lt;/code&gt;&lt;span&gt;&amp;nbsp;parameter of the&amp;nbsp;&lt;/span&gt;&lt;code&gt;Install&lt;/code&gt;&lt;span&gt;&amp;nbsp;method to&amp;nbsp;&lt;/span&gt;&lt;code&gt;Register&lt;/code&gt;&lt;span&gt;&amp;nbsp;controllers using
 Windsor's&amp;nbsp;&lt;/span&gt;&lt;a title="Fluent Registration API" href="http://docs.castleproject.org/Windsor.Fluent-Registration-API.ashx"&gt;Fluent Registration API&lt;/a&gt;&lt;span&gt;.&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Now we need to tell Castle Windsor to know about all dependencies for it to manage them. For that, we create a new class&amp;nbsp;&lt;strong&gt;DependencyInstaller&amp;nbsp;&lt;/strong&gt;to implement&amp;nbsp;&lt;strong&gt;IWindsorInstaller&lt;/strong&gt;. The installer uses the container
 parameter of the Install() method to Register dependencies using Windsor's Fluent Registration API. As per below implementation&amp;nbsp;every time&amp;nbsp;we add any new class to Controller/Service/Repository in our application, it will be automatically registered,
 the only thing we need follow is naming convention, i.e. all Controller class should end with Controller similarly Service and Repository classes should end with Service and Repository.&amp;nbsp;&lt;/p&gt;
&lt;div id="premain1"&gt;&lt;img id="preimg1" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse1"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre1" lang="cs"&gt;        &lt;span&gt;public&lt;/span&gt; &lt;span&gt;void&lt;/span&gt; Install(IWindsorContainer container, IConfigurationStore store)
        {
            container.Register(
                        Component.For&amp;lt;ILogService&amp;gt;()
                            .ImplementedBy&amp;lt;LogService&amp;gt;()
                            .LifeStyle.PerWebRequest,

                        Component.For&amp;lt;IDatabaseFactory&amp;gt;()
                            .ImplementedBy&amp;lt;DatabaseFactory&amp;gt;()
                            .LifeStyle.PerWebRequest,

                        Component.For&amp;lt;IUnitOfWork&amp;gt;()
                            .ImplementedBy&amp;lt;UnitOfWork&amp;gt;()
                            .LifeStyle.PerWebRequest,

                        AllTypes.FromThisAssembly().BasedOn&amp;lt;IHttpController&amp;gt;().LifestyleTransient(),

                        AllTypes.FromAssemblyNamed(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Application.Service&amp;quot;&lt;/span&gt;)
                            .Where(type =&amp;gt; type.Name.EndsWith(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Service&amp;quot;&lt;/span&gt;)).WithServiceAllInterfaces().LifestylePerWebRequest(),

                        AllTypes.FromAssemblyNamed(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Application.Repository&amp;quot;&lt;/span&gt;)
                            .Where(type =&amp;gt; type.Name.EndsWith(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Repository&amp;quot;&lt;/span&gt;)).WithServiceAllInterfaces().LifestylePerWebRequest()
                        );
        }
    } &lt;/pre&gt;
&lt;div&gt;
&lt;p&gt;&amp;nbsp;Next, in final step create and configure&amp;nbsp;the Windsor container in Application's constructor inside Global.asax.cs, &amp;nbsp;so that it will be automatically dispose when application exits.&amp;nbsp;&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div id="premain2"&gt;&lt;img id="preimg2" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse2"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre2" lang="cs"&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;class&lt;/span&gt; WebApiApplication : System.Web.HttpApplication
    {
        &lt;span&gt;private&lt;/span&gt; &lt;span&gt;readonly&lt;/span&gt; IWindsorContainer container;

        &lt;span&gt;public&lt;/span&gt; WebApiApplication()
        {
            &lt;span&gt;this&lt;/span&gt;.container =
                &lt;span&gt;new&lt;/span&gt; WindsorContainer().Install(&lt;span&gt;new&lt;/span&gt; DependencyInstaller());
        }

        &lt;span&gt;public&lt;/span&gt; &lt;span&gt;override&lt;/span&gt; &lt;span&gt;void&lt;/span&gt; Dispose()
        {
            &lt;span&gt;this&lt;/span&gt;.container.Dispose();
            &lt;span&gt;base&lt;/span&gt;.Dispose();
        }


        &lt;span&gt;protected&lt;/span&gt; &lt;span&gt;void&lt;/span&gt; Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            GlobalConfiguration.Configuration.Services.Replace(
                &lt;span&gt;typeof&lt;/span&gt;(IHttpControllerActivator),
                &lt;span&gt;new&lt;/span&gt; WindsorActivator(&lt;span&gt;this&lt;/span&gt;.container));
        }
    }&amp;lt;logservice&amp;gt;&amp;lt;ilogservice&amp;gt;&amp;lt;unitofwork&amp;gt;&amp;lt;iunitofwork&amp;gt;&amp;lt;databasefactory&amp;gt;&amp;lt;idatabasefactory&amp;gt;
            &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;idatabasefactory&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;databasefactory&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;iunitofwork&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;unitofwork&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;ilogservice&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;logservice&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Now we are ready to test our application. Hit F5 and check the browser with following url&amp;rsquo;s:&amp;nbsp;&lt;br&gt;
http://localhost:30000/api/products : will result all Product Categories&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/20.PNG" alt="Solution 1" width="652"&gt;&lt;/p&gt;
&lt;p&gt;http://localhost:30000/api/products/2 : will result all Products with ProductcategoryID as 2&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/21.PNG" alt="Solution 1" width="652"&gt;&lt;/p&gt;
&lt;p&gt;To check other methods, First we will add some Views in current solution.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Step 6: Add View to solution&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Delete all default files and folders from Views Folder, and add three Html and their supportive Javascript File as. For this POC we will use html files, and some jquery libraries like:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;jquery.tmpl.js :&lt;/strong&gt;&amp;nbsp;to create template based screen, and&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;jquery.validationEngine.js :&lt;/strong&gt;&amp;nbsp;to validate form data&lt;/p&gt;
&lt;p&gt;Now the structure will looks like below picture :&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/22.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;For details code in html and JS file please look into the code. In next step I am going to resolve problems.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Step 7: Resolve issues&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Before run the application Right Click on Products.htm and click on Set As start Page. Now hit F5&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/23.PNG" alt="Solution 1" width="700" height="300"&gt;&lt;/p&gt;
&lt;p&gt;It means, two WebAPI methods in ProductsController.cs are working perfectly. In JavaScript, on page load we are calling first method inside&amp;nbsp;&lt;strong&gt;product.js&lt;/strong&gt;&amp;nbsp;as:&lt;/p&gt;
&lt;div id="premain3"&gt;&lt;img id="preimg3" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse3"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre3" lang="js"&gt;                    var productcategoriesAddress = &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;/api/products/&amp;quot;&lt;/span&gt;;
                    $(function () {
                        $(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;#tblRight'&lt;/span&gt;).hide();
                        $.getJSON(
                                productcategoriesAddress,
                                function (data) {
                                    var parents = jQuery.grep(data, function (a) { &lt;span&gt;return&lt;/span&gt; a.ParentProductCategoryID == null });
                                    var childs = jQuery.grep(data, function (a) { &lt;span&gt;return&lt;/span&gt; a.ParentProductCategoryID != null });
                                    $.&lt;span&gt;each&lt;/span&gt;(parents,
                                        function (index, &lt;span&gt;value&lt;/span&gt;) {
                                            var categorydata = [];
                                            var subCategory = &lt;span&gt;'&lt;/span&gt;&lt;span&gt;'&lt;/span&gt;;
                                            var subChild = jQuery.grep(childs, function (a) { &lt;span&gt;return&lt;/span&gt; a.ParentProductCategoryID == &lt;span&gt;value&lt;/span&gt;.ProductCategoryID });
                                            $.&lt;span&gt;each&lt;/span&gt;(subChild,
                                                function (index, item) {
                                                    var serviceURL = productcategoriesAddress &amp;#43; item.ProductCategoryID;
                                                    subCategory = subCategory &amp;#43; &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;  &amp;quot;&lt;/span&gt; &amp;#43; &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;lt;a href=&amp;quot;&lt;/span&gt;%20&amp;#43;%20serviceURL%20&amp;#43;%20&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt; class=&amp;quot;&lt;/span&gt;menuButton&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;gt;&amp;quot;&lt;/span&gt; &amp;#43; item.Name &amp;#43; &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;lt;/a&amp;gt;&amp;quot;&lt;/span&gt;;
                                                });
                                            categorydata.push({
                                                &lt;span&gt;'&lt;/span&gt;&lt;span&gt;ProductCategoryID'&lt;/span&gt;: &lt;span&gt;value&lt;/span&gt;.ProductCategoryID,
                                                &lt;span&gt;'&lt;/span&gt;&lt;span&gt;ParentCategory'&lt;/span&gt;: &lt;span&gt;value&lt;/span&gt;.Name,
                                                &lt;span&gt;'&lt;/span&gt;&lt;span&gt;ChildCategory'&lt;/span&gt;: subCategory
                                            });
                                            $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#categoryTemplate&amp;quot;&lt;/span&gt;).tmpl(categorydata).appendTo(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#categories&amp;quot;&lt;/span&gt;);
                                            $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#&amp;quot;&lt;/span&gt; &amp;#43; &lt;span&gt;value&lt;/span&gt;.Name).html(subCategory);
                                        });

                                        GetProducts(&lt;span&gt;1&lt;/span&gt;);
                                }
                            );
                &lt;/pre&gt;
&lt;p&gt;This call hits below method in ProductsController, and returns all Product Category to create the Upper Menu Part&lt;/p&gt;
&lt;div id="premain4"&gt;&lt;img id="preimg4" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse4"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre4" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; IQueryable&amp;lt;productcategory&amp;gt; GetProductCategories()
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with null parameter&amp;quot;&lt;/span&gt;);
                        &lt;span&gt;return&lt;/span&gt; _productservice.GetProductCategories().AsQueryable&amp;lt;productcategory&amp;gt;();
                    }
                &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;productcategory&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;productcategory&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;In ProductService implementation is :&lt;/p&gt;
&lt;div id="premain5"&gt;&lt;img id="preimg5" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse5"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre5" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; IQueryable&amp;lt;productcategory&amp;gt; GetProductCategories()
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with null parameter&amp;quot;&lt;/span&gt;);
                        &lt;span&gt;return&lt;/span&gt; _productservice.GetProductCategories().AsQueryable&amp;lt;productcategory&amp;gt;();
                    }
                &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;productcategory&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;productcategory&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;The second call is to fetch all products depends on selected category. In javascript&lt;/p&gt;
&lt;div id="premain6"&gt;&lt;img id="preimg6" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse6"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre6" lang="js"&gt;                      function GetProducts(ProductCategoryID) {
                        var serviceURL = productcategoriesAddress &amp;#43; ProductCategoryID;
                        $(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;#categories li h1'&lt;/span&gt;).css(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;background'&lt;/span&gt;, &lt;span&gt;'&lt;/span&gt;&lt;span&gt;#736F6E'&lt;/span&gt;);
                        $(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;#mnu'&lt;/span&gt; &amp;#43; ProductCategoryID).css(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;background'&lt;/span&gt;, &lt;span&gt;'&lt;/span&gt;&lt;span&gt;#357EC7'&lt;/span&gt;);
                        $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#loader&amp;quot;&lt;/span&gt;).show();
                        $.ajax({
                            type: &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;GET&amp;quot;&lt;/span&gt;,
                            datatype: &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;json&amp;quot;&lt;/span&gt;,
                            url: serviceURL,
                            context: &lt;span&gt;this&lt;/span&gt;,
                            success: function (&lt;span&gt;value&lt;/span&gt;) {
                                $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#productData&amp;quot;&lt;/span&gt;).html(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;quot;&lt;/span&gt;);
                                $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#productTemplate&amp;quot;&lt;/span&gt;).tmpl(&lt;span&gt;value&lt;/span&gt;).appendTo(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#productData&amp;quot;&lt;/span&gt;);
                                $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#loader&amp;quot;&lt;/span&gt;).hide();
                            }
                        });
                        &lt;span&gt;return&lt;/span&gt; &lt;span&gt;false&lt;/span&gt;;
                    }
                &lt;/pre&gt;
&lt;p&gt;and in ProductsController it goes to&lt;/p&gt;
&lt;div id="premain7"&gt;&lt;img id="preimg7" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse7"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre7" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; IQueryable&amp;lt;product&amp;gt; GetProductByProductCategoryID(&lt;span&gt;int&lt;/span&gt; id)
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with null parameter as : id : &amp;quot;&lt;/span&gt; &amp;#43; id);
                        &lt;span&gt;return&lt;/span&gt; _productservice.GetProductByProductCategoryID(id).AsQueryable&amp;lt;product&amp;gt;();
                    }

                &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;product&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;product&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;In ProductService implementation is :&lt;/p&gt;
&lt;div id="premain8"&gt;&lt;img id="preimg8" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse8"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre8" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; IQueryable&amp;lt;product&amp;gt; GetProductByProductCategoryID(&lt;span&gt;int&lt;/span&gt; id)
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with null parameter as : id : &amp;quot;&lt;/span&gt; &amp;#43; id);
                        &lt;span&gt;return&lt;/span&gt; _productservice.GetProductByProductCategoryID(id).AsQueryable&amp;lt;product&amp;gt;();
                    }
                &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;product&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;product&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Next, let us try to add some products to Cart and Checkout cart&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/28.PNG" alt="Solution 1" width="400" height="300"&gt;&lt;/p&gt;
&lt;p&gt;On clicking on checkout It redirect to Checkout.htm page and asking for either Login using existing CustomerID or Register for a new Customer.&lt;br&gt;
Click on&amp;nbsp;&lt;strong&gt;Register&lt;/strong&gt;&amp;nbsp;link to create a new Customer.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/29.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;Submit form after clicking on Register button and see if Posting is working or not. Again its success!!!&lt;/p&gt;
&lt;p&gt;Now we will try to update records for AddressLine2, and Update is also working fine!!!&lt;/p&gt;
&lt;p&gt;In both scenario (Add or Update Customer) we are calling below method of CutomerControllers.cs&lt;/p&gt;
&lt;div id="premain9"&gt;&lt;img id="preimg9" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse9"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre9" lang="cs"&gt;                     &lt;span&gt;public&lt;/span&gt; &lt;span&gt;int&lt;/span&gt; PostCustomer(CustomerDTO customer)
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with parameter as : customer: &amp;quot;&lt;/span&gt; &amp;#43; customer);
                        &lt;span&gt;return&lt;/span&gt; _customerService.SaveOrUpdateCustomer(customer);
                    }
                &lt;/pre&gt;
&lt;p&gt;In CustomerService implementation is :&lt;/p&gt;
&lt;div id="premain10"&gt;&lt;img id="preimg10" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse10"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre10" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;int&lt;/span&gt; SaveOrUpdateCustomer(CustomerDTO customer)
                    {
                        &lt;span&gt;string&lt;/span&gt; passwordSalt = CreateSalt(&lt;span&gt;5&lt;/span&gt;);
                        &lt;span&gt;string&lt;/span&gt; pasword = CreatePasswordHash(customer.Password, passwordSalt);
                        Customer objCustomer;

                        &lt;span&gt;if&lt;/span&gt; (customer.CustomerID != &lt;span&gt;0&lt;/span&gt;)
                            objCustomer = _customerRepository.GetById(customer.CustomerID);
                        &lt;span&gt;else&lt;/span&gt;
                            objCustomer = &lt;span&gt;new&lt;/span&gt; Customer();

                        objCustomer.NameStyle = customer.NameStyle;
                        objCustomer.Title = customer.Title;
                        objCustomer.FirstName = customer.FirstName;
                        objCustomer.MiddleName = customer.MiddleName;
                        objCustomer.LastName = customer.LastName;
                        objCustomer.Suffix = customer.Suffix;
                        objCustomer.CompanyName = customer.CompanyName;
                        objCustomer.SalesPerson = customer.SalesPerson;
                        objCustomer.EmailAddress = customer.EmailAddress;
                        objCustomer.Phone = customer.Phone;
                        objCustomer.PasswordHash = pasword;
                        objCustomer.PasswordSalt = passwordSalt;
                        objCustomer.ModifiedDate = DateTime.Now;
                        objCustomer.rowguid = Guid.NewGuid();

                        &lt;span&gt;if&lt;/span&gt; (customer.CustomerID != &lt;span&gt;0&lt;/span&gt;)
                            _customerRepository.Update(objCustomer);
                        &lt;span&gt;else&lt;/span&gt;
                            _customerRepository.Add(objCustomer);

                        _unitOfWork.Commit();
                        SaveOrUpdateAddress(customer, objCustomer.CustomerID);
                        &lt;span&gt;return&lt;/span&gt; objCustomer.CustomerID;
                    }
                &lt;/pre&gt;
&lt;p&gt;Next, click on Submit Order Button, to make previously selected products as an Order and receive Order Invoice.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/33.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;!!!Hurray!!! Order is created in system and invoice is generated with a new Purchase Order. But, wait we got one BUG&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue 1. is fixed with the final release of Asp.Net WebAPI&amp;nbsp;&lt;/strong&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span style="text-decoration:line-through"&gt;&lt;strong&gt;Issue 1:&lt;/strong&gt;&amp;nbsp;we have an issue with Date Format.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/34.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="text-decoration:line-through"&gt;According to,&amp;nbsp;&lt;a href="http://www.hanselman.com/blog/OnTheNightmareThatIsJSONDatesPlusJSONNETAndASPNETWebAPI.aspx"&gt;Scott Hanselman&amp;rsquo;s post&lt;/a&gt;&amp;nbsp;this is a bug and will resolve in next release of ASP.Net
 WebAPI. This issue is resolved using&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/02/18/using-json-net-with-asp-net-web-api.aspx"&gt;solution provided in Henrik's Blog&lt;/a&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/35.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue 2:&lt;/strong&gt;&amp;nbsp;Another issue was, when I try to Checkout Cart using the last created Customer. The error was:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/36.PNG" alt="Solution 1" width="700" height="300"&gt;&lt;/p&gt;
&lt;p&gt;After looking this error, first thought comes that we missed the method in CustomersController.cs, but the method was already there. Further investigation make it clear, that, the reason behind this error was name of this method as ValidateCustomer():&lt;/p&gt;
&lt;div id="premain11"&gt;&lt;img id="preimg11" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse11"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre11" lang="cs"&gt;                     &lt;span&gt;public&lt;/span&gt; CustomerDTO ValidateCustomer(&lt;span&gt;int&lt;/span&gt; id, &lt;span&gt;string&lt;/span&gt; password)
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with parameter as : id and password: &amp;quot;&lt;/span&gt; &amp;#43; id &amp;#43; &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt; and &amp;quot;&lt;/span&gt; &amp;#43; password);
                        &lt;span&gt;return&lt;/span&gt; _customerService.ValidateCustomer(id, password);
                    }
                &lt;/pre&gt;
&lt;p&gt;In CustomerService implementation is :&lt;/p&gt;
&lt;div id="premain12"&gt;&lt;img id="preimg12" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse12"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre12" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; CustomerDTO ValidateCustomer(&lt;span&gt;int&lt;/span&gt; id, &lt;span&gt;string&lt;/span&gt; password)
                    {
                        Customer objCustomer = _customerRepository.GetById(id);
                        &lt;span&gt;if&lt;/span&gt; (objCustomer == &lt;span&gt;null&lt;/span&gt;)
                            &lt;span&gt;return&lt;/span&gt; &lt;span&gt;null&lt;/span&gt;;
                        &lt;span&gt;string&lt;/span&gt; strPasswordHash = objCustomer.PasswordHash;
                        &lt;span&gt;string&lt;/span&gt; strPasswordSalt = strPasswordHash.Substring(strPasswordHash.Length - &lt;span&gt;8&lt;/span&gt;);
                        &lt;span&gt;string&lt;/span&gt; strPasword = CreatePasswordHash(password, strPasswordSalt);

                        &lt;span&gt;if&lt;/span&gt; (strPasword.Equals(strPasswordHash))
                            &lt;span&gt;return&lt;/span&gt; CreateCustomerDTO(objCustomer);
                        &lt;span&gt;else&lt;/span&gt;
                            &lt;span&gt;return&lt;/span&gt; &lt;span&gt;null&lt;/span&gt;;
                    }
                &lt;/pre&gt;
&lt;p&gt;By default the&amp;nbsp;&lt;strong&gt;route configuration&lt;/strong&gt;&amp;nbsp;of Asp.Net WebAPI follows RESTFUL conventions meaning that it will accept only the&amp;nbsp;&lt;strong&gt;Get, Post, Put and Delete&lt;/strong&gt;&amp;nbsp;action names. So when we send a GET request to http://localhost:30000/api/customers/ValidateCustomer/30135/test
 we are basically calling the Get(int id) action and passing id=30135 which obviously crashes because we don&amp;rsquo;t have any method starting with Get which accept Id as parameter. To resolve this issue I need to add a new route definition in&amp;nbsp;&lt;strong&gt;Global.asax&lt;/strong&gt;&amp;nbsp;file
 as:&lt;/p&gt;
&lt;div id="premain13"&gt;&lt;img id="preimg13" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse13"&gt;&amp;nbsp;Collapse&lt;/span&gt;&lt;span&gt;&amp;nbsp;|&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=47568&amp;aid=350488#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre13" lang="cs"&gt;                     routes.MapHttpRoute(
                           name: &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;ValidateCustomer&amp;quot;&lt;/span&gt;,
                           routeTemplate: &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;api/{controller}/{action}/{id}/{password}&amp;quot;&lt;/span&gt;,
                           defaults: &lt;span&gt;new&lt;/span&gt; { action = &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;get&amp;quot;&lt;/span&gt; }
                       );
                &lt;/pre&gt;
&lt;p&gt;Adding this line done the magic and Login functinality start waorking&amp;hellip;.&amp;nbsp;&lt;img src="http://www.codeproject.com/script/Forums/Images/smiley_smile.gif" alt="Smile | :)" align="top"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Step 8: Deploy on IIS&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To deploy this API on IIS version 7.5, first, publish only&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;solution to a Folder.&lt;/p&gt;
&lt;p&gt;Next, open IIS Manager and create a new website and set path to Publish folder, and we are done with deployment.&lt;/p&gt;
&lt;p&gt;Now, check whether page is opening or not, in my case, initially I got below error, which is self-explanatory.&lt;br&gt;
The error comes because this application is running on Asp.Net Framework Version 2.0. So, we need to change it to Asp.Net Framework Version 4.0:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/40.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/41.PNG" alt="Solution 1" width="652"&gt;&lt;/p&gt;
&lt;p&gt;To change the Asp.Net Framework from 2.0 to 4.0, follow below steps.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/42.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/43.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;That was not the only reason not to run application, because after made above change in Application pool next error was:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/44.PNG" alt="Solution 1" width="700" height="200"&gt;&lt;/p&gt;
&lt;p&gt;To resolve this error again go to Advance Settings of Application pool and change the identity to Local System from ApplicationPoolIdentity&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/45.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;After modify the Application pool to use Local System, Application starts working on browser...&amp;nbsp;&lt;img src="http://www.codeproject.com/script/Forums/Images/smiley_smile.gif" alt="Smile | :)" align="top"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/46.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;Although IIS errors are depending on servers/Firewall/Network or system to system, so it is very difficult to assume that you will also get the same error as mine. Check these links which help me to resolve some of the IIS issues in
 my work environment.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en/wcf/thread/b990d3ea-3335-40a6-877f-7c295da67a85"&gt;HTTP Error 500.19&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/eu/wcf/thread/39571e42-aca7-469d-8c68-aa59c2da4fcc"&gt;Could Not Load Type &amp;lsquo;System.ServiceModel.Activation.HttpModule&amp;rsquo;&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/k6h9cz8h.aspx"&gt;ASP.NET IIS Registration Tool&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms732012.aspx"&gt;ServiceModel Registration Tool&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Step 9: Cross Domain Support&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The idea behind the Cross Domain Support comes when I try to remove all HTML pages from&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;solution and created a new Empty Web Application (Adventure.Website) which includes only&amp;nbsp;&lt;strong&gt;.html, .Js and .css&lt;/strong&gt;files
 along with images. The structure for this application is as per below image:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/47.PNG" alt="Solution 1" width="300" height="500"&gt;&lt;/p&gt;
&lt;p&gt;Point all URL address to deployed code on IIS, after build and run application, output was null.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/48.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;To resolve this issue I would like to give my special thanks to Carlos&amp;rsquo; blog on MSDN&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2012/02/20/implementing-cors-support-in-asp-net-web-apis.aspx"&gt;Implementing CORS support in ASP.NET Web
 APIs&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;blockquote&gt;
&lt;div&gt;Quote:&lt;/div&gt;
&amp;ldquo;By default, a web page cannot make calls to services (APIs) on a domain other than the one where the page came from. This is a security measure against a group of cross-site forgery attacks in which browsing to a bad site could potentially use the browser
 cookies to get data from a good site which the user had previously logged on (think your bank). There are many situations, however, where getting data from different sites is a perfectly valid scenario, such as mash-up applications which need data from different
 sources.&amp;rdquo;&amp;nbsp;&amp;nbsp;&lt;/blockquote&gt;
&lt;h2&gt;&lt;strong&gt;Code Setup&lt;/strong&gt;&amp;nbsp;&lt;/h2&gt;
&lt;p&gt;Due to size restriction I have attached code in three parts :&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Part 1 : Application.Zip&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Part 2 : Packages.Zip&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Part 3 : AdventureSite.Zip&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Part 1 and Part 3 are independent applications. Whereas, for Part 2 we need to copy its content inside the package folder of Application (Part 1). Please refer below image :&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;img src="http://www.codeproject.com/KB/WCF/350488/Working/Code_setup.png" alt="" width="820" height="377"&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&amp;nbsp;&lt;/h2&gt;
&lt;p&gt;That's it !!! Hope you enjoy this article. I am not an expert, and also I have not followed the entire industry standard at the time of writing this article (time factor).&lt;/p&gt;
&lt;p&gt;All&amp;nbsp;&lt;strong&gt;comment/Vote&lt;/strong&gt;&amp;nbsp;are more than welcome&amp;hellip;.&amp;nbsp;&lt;img src="http://www.codeproject.com/script/Forums/Images/smiley_smile.gif" alt="Smile | :)" align="top"&gt;&amp;nbsp;, whenever, I get time, will try to modify this solution. You can
 also join/contribute to this project on&amp;nbsp;&lt;a href="http://pocwebapi.codeplex.com/"&gt;CodePlex&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Thank's for your time.&lt;/p&gt;
&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>anandranjanpandey</author><pubDate>Sat, 27 Oct 2012 18:48:37 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20121027064837P</guid></item><item><title>Updated Wiki: Home</title><link>http://pocwebapi.codeplex.com/wikipage?version=7</link><description>&lt;div class="wikidoc"&gt;
&lt;h2&gt;&lt;strong&gt;Introduction&amp;nbsp;&lt;/strong&gt;&amp;nbsp;&lt;/h2&gt;
&lt;p&gt;The purpose of this article is to create a&lt;strong&gt;&amp;nbsp;proof of concept&amp;nbsp;&lt;/strong&gt;to demonstrate the feasibility of&amp;nbsp;&lt;a href="http://www.asp.net/web-api"&gt;ASP.NET WebAPI&lt;/a&gt;&amp;nbsp;Beta version.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Prerequisite:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://msftdbprodsamples.codeplex.com/"&gt;AdventureWorksLT2008R2&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://www.asp.net/web-api"&gt;ASP.Net WebAPI&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://code.google.com/p/autofac/downloads/list"&gt;Autofac for Dependency Injection&lt;/a&gt;&amp;nbsp;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://logging.apache.org/log4net/download.html"&gt;Log4Net&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://www.microsoft.com/download/en/details.aspx?displaylang=en&amp;id=8363"&gt;EntityFramework 4.1&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="https://github.com/jquery/jquery-tmpl"&gt;jQuery Templates plugin (jquery-tmpl)&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Goals to achieve:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Any user should be able to view products &lt;/li&gt;&lt;li&gt;Product would be filtered by Categories &lt;/li&gt;&lt;li&gt;User should be able to add products in cart &lt;/li&gt;&lt;li&gt;Only registered user will be able to submit cart &lt;/li&gt;&lt;li&gt;User should be able to register into system &lt;/li&gt;&lt;li&gt;User will get confirmation Invoice after generating order in system. &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Architecture for this POC&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;I am not following any specific Architecture Pattern, although while designing this POC, I&amp;nbsp;&lt;strong&gt;try to follow&lt;/strong&gt;&amp;nbsp;some of the key design principles like:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Separation_of_concerns"&gt;Separation of concerns&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Abstraction_(computer_science)"&gt;Abstraction&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself"&gt;Don't repeat yourself&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/KISS_principle"&gt;KISS principle&lt;/a&gt; &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Again I am repeating my word&amp;nbsp;&lt;strong&gt;try to follow&amp;hellip;.. :)&lt;/strong&gt;. So, all comments/suggestions are more than welcome to discuss and I am always ready to adopt changes, or you can do it yourself by join&amp;nbsp;&lt;a href="http://pocwebapi.codeplex.com/"&gt;@CodePlex&lt;/a&gt;.
 The initial Skeleton for this application is as per below diagram:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/1.PNG" alt="Architecture" width="650" height="500"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Step-by-Step&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Step 1: Create a basic Application Structure Layout &lt;/li&gt;&lt;li&gt;Step 2: Create the Data Access Layer &lt;/li&gt;&lt;li&gt;Step 3: Create the Service Layer &lt;/li&gt;&lt;li&gt;Step 4: Create the API Layer &lt;/li&gt;&lt;li&gt;Step 5: Integration of Dependency Injection using Autofac &lt;/li&gt;&lt;li&gt;Step 6: Add Views to solution &lt;/li&gt;&lt;li&gt;Step 7: Unit test and resolve issues &lt;/li&gt;&lt;li&gt;Step 8: Deploy application on IIS &lt;/li&gt;&lt;li&gt;Step 9: Provide Cross Domain Support &lt;/li&gt;&lt;/ul&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step1"&gt;Step 1: Create a basic Application Structure Layout&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;For more information on ASP.NET WebAPI, watch Videos and Tutorials&amp;nbsp;&lt;a href="http://www.asp.net/web-api"&gt;here&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add a blank Solution named as&amp;nbsp;&lt;strong&gt;Application&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add a new Project (Class Library) named as&amp;nbsp;&lt;strong&gt;Application.DAL&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Repeat above process and create four more Class Library projects named as &amp;ndash;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Application.Model&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Repository&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Common&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Service&lt;/strong&gt; &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Now, application will look like below screen-shot&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/4.PNG" alt="Solution 1" width="250" height="350"&gt;&lt;/p&gt;
&lt;p&gt;Next, add a new Project named as&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;as ASP.Net MVC 4 Web Application. After click on OK, select template as Web API&lt;/p&gt;
&lt;p&gt;This will add a full functional Web API template Application into our main solution.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/7.PNG" alt="Solution 1" width="230" height="350"&gt;&lt;/p&gt;
&lt;p&gt;Right click on Application.API project in Solution Explorer and go to properties, than assign a port to be use by this service application ( In my case its 30000). Hit F5 and we are ready with a dummy data as below screen:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/8.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step2"&gt;Step 2: Prepare Application.DAL, Application.Repository and Application.Model Layers&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Check&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/library/bb399182.aspx"&gt;@MSDN&lt;/a&gt;&amp;nbsp;for more information on Entity Framework&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add Entity Data Model to&amp;nbsp;&lt;strong&gt;Application.DAL&lt;/strong&gt;&amp;nbsp;project. To do this select ADO.NET Entity Data Model from the Data Templates list, and name it as&amp;nbsp;&lt;strong&gt;AdventureWorks.edmx&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Choose&amp;nbsp;&lt;strong&gt;&amp;ldquo;Generate from Database&amp;rdquo;&lt;/strong&gt;&amp;nbsp;and provide the connection string to read the database schema. This will add AdventureWorks.edmx into current project. Right click on the blank space in Entity Model surface and click
 on properties (or alternate press Alt &amp;#43;Enter on keyboard). Now set its Code Generation Strategy as&amp;nbsp;&lt;strong&gt;None&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/10.PNG" alt="Solution 1" width="550" height="300"&gt;&lt;/p&gt;
&lt;p&gt;Now create POCO entities for AdventureWorks Data Model into&amp;nbsp;&lt;strong&gt;Application.Model&lt;/strong&gt;&amp;nbsp;Solution. Check this article to do this job for you on MSDN to use&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/gg558520"&gt;T4 Templates and the Entity
 Framework&lt;/a&gt;&lt;br&gt;
Then, create all required repositories under Application.Repositories.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/11.PNG" alt="Solution 1" width="250" height="500"&gt;&lt;/p&gt;
&lt;p&gt;To build solution, add reference of&amp;nbsp;&lt;strong&gt;Application.Model.dll&lt;/strong&gt;&amp;nbsp;to&amp;nbsp;&lt;strong&gt;Application.DAL.dll&lt;/strong&gt;&amp;nbsp;and&amp;nbsp;&lt;strong&gt;Application.Repository.dll&lt;/strong&gt;projects, and add reference of&amp;nbsp;&lt;strong&gt;Application.DAL.dll&lt;/strong&gt;&amp;nbsp;to&amp;nbsp;&lt;strong&gt;Application.Repository.dll&lt;/strong&gt;&amp;nbsp;project.
 (See below picture for reference)&lt;br&gt;
Before proceeding to next step (designing Application.Service and Application.API Layer), let us see what we have designed yet:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/12.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step3"&gt;Step 3: Add files to Application.Service Layer&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Before adding files to Service layer let us look at the Goals which we want to achieve.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Any user should be able to view products &lt;/li&gt;&lt;li&gt;Product would be filtered by Categories &lt;/li&gt;&lt;li&gt;User should be able to add products in cart &lt;/li&gt;&lt;li&gt;Only registered user will be able to submit cart &lt;/li&gt;&lt;li&gt;User should be able to register into system &lt;/li&gt;&lt;li&gt;User will get confirmation Invoice after generating order in system. &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To achieve the above mention Goals, we need to add three service classes to Application.Service as per below image&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/13.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/14.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;I am not going in deatils, as the implementation for each methods are clear and easy to understand.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step4"&gt;Step 4: Add files to Application.API Layer&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To make this Web API accessed from a broad range of clients like any browsers which use JavaScript or any windows/Mobile platform which supports .dll files, we need to add Controllers with base class as&amp;nbsp;&lt;strong&gt;ApiController&lt;/strong&gt;.&amp;nbsp;&lt;a href="http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api"&gt;More
 details here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;First, we remove the default controllers added by template (HomeController and ValuesController) and then add three new controllers as per below diagram:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/15.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;Again, nothing special in the implementation of these methods, they all jst push the data to service layer.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step5"&gt;Step 5: Integration of Dependency Injection with WebAPI using Autofac&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The implementation is very much straight forward and clear.&amp;nbsp;&lt;a href="http://alexmg.com/post/2012/03/08/Autofac-ASPNET-Web-API-%28Beta%29-Integration.aspx"&gt;Check Alex post here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;Solution Explorer, right-click the References node and click Manage NuGet Packages&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/16.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;It will open the below screen.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/17.PNG" alt="Solution 1" width="700" height="200"&gt;&lt;/p&gt;
&lt;p&gt;Click on install and it will add below three references in solution&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/18.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;Next, go to Global.asax.cs and create a method named as ResolveDependency()&lt;/p&gt;
&lt;pre id="pre0" lang="cs"&gt;             protected void ResolveDependancy()
                {
                    var configuration = GlobalConfiguration.Configuration;
                    var builder = new ContainerBuilder();

                    // Configure the container with the integration implementations.
                    builder.ConfigureWebApi(configuration);

                    // Register API controllers using assembly scanning.
                    builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

                    builder.RegisterType&amp;lt;logservice&amp;gt;().As&amp;lt;ilogservice&amp;gt;().InstancePerLifetimeScope();
                    builder.RegisterType&amp;lt;unitofwork&amp;gt;().As&amp;lt;iunitofwork&amp;gt;().InstancePerDependency();
                    builder.RegisterType&amp;lt;databasefactory&amp;gt;().As&amp;lt;idatabasefactory&amp;gt;().InstancePerLifetimeScope();
                    builder.RegisterAssemblyTypes(typeof(ProductService).Assembly)
                    .Where(t =&amp;gt; t.Name.EndsWith(&amp;quot;Service&amp;quot;))
                    .AsImplementedInterfaces().InstancePerDependency();
                    builder.RegisterAssemblyTypes(typeof(CustomerRepository).Assembly)
                    .Where(t =&amp;gt; t.Name.EndsWith(&amp;quot;Repository&amp;quot;))
                    .AsImplementedInterfaces().InstancePerDependency();      

                    var container = builder.Build();

                    // Set the dependency resolver implementation.
                    var resolver = new AutofacWebApiDependencyResolver(container);
                    configuration.ServiceResolver.SetResolver(resolver);
                }
            &amp;lt;/idatabasefactory&amp;gt;&amp;lt;/databasefactory&amp;gt;&amp;lt;/iunitofwork&amp;gt;&amp;lt;/unitofwork&amp;gt;&amp;lt;/ilogservice&amp;gt;&amp;lt;/logservice&amp;gt;&lt;/pre&gt;
&lt;p&gt;Now we are ready to test our application. Hit F5 and check the browser with following url&amp;rsquo;s:&amp;nbsp;&lt;br&gt;
http://localhost:30000/api/products : will result all Product Categories&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/20.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;http://localhost:30000/api/products/2 : will result all Products with ProductcategoryID as 2&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/21.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;To check other methods, First we will add some Views in current solution.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step6"&gt;Step 6: Add View to solution&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Delete all default files and folders from Views Folder, and add three Html and their supportive Javascript File as. For this POC we will use html files, and some jquery libraries like:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;jquery.tmpl.js :&lt;/strong&gt;&amp;nbsp;to create template based screen, and&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;jquery.validationEngine.js :&lt;/strong&gt;&amp;nbsp;to validate form data&lt;/p&gt;
&lt;p&gt;Now the structure will looks like below picture :&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/22.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;For details code in html and JS file please look into the code. In next step I am going to resolve problems.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step7"&gt;Step 7: Resolve issues&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Before run the application Right Click on Products.htm and click on Set As start Page. Now hit F5&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/23.PNG" alt="Solution 1" width="700" height="300"&gt;&lt;/p&gt;
&lt;p&gt;It means, two WebAPI methods in ProductsController.cs are working perfectly. In JavaScript, on page load we are calling first method inside&amp;nbsp;&lt;strong&gt;product.js&lt;/strong&gt;&amp;nbsp;as:&lt;/p&gt;
&lt;pre id="pre1" lang="js"&gt;                    var productcategoriesAddress = &amp;quot;/api/products/&amp;quot;;
                    $(function () {
                        $('#tblRight').hide();
                        $.getJSON(
                                productcategoriesAddress,
                                function (data) {
                                    var parents = jQuery.grep(data, function (a) { return a.ParentProductCategoryID == null });
                                    var childs = jQuery.grep(data, function (a) { return a.ParentProductCategoryID != null });
                                    $.each(parents,
                                        function (index, value) {
                                            var categorydata = [];
                                            var subCategory = '';
                                            var subChild = jQuery.grep(childs, function (a) { return a.ParentProductCategoryID == value.ProductCategoryID });
                                            $.each(subChild,
                                                function (index, item) {
                                                    var serviceURL = productcategoriesAddress &amp;#43; item.ProductCategoryID;
                                                    subCategory = subCategory &amp;#43; &amp;quot;  &amp;quot; &amp;#43; &amp;quot;&amp;lt;a href=&amp;quot;%20&amp;#43;%20serviceURL%20&amp;#43;%20&amp;quot; class=&amp;quot;menuButton&amp;quot;&amp;gt;&amp;quot; &amp;#43; item.Name &amp;#43; &amp;quot;&amp;lt;/a&amp;gt;&amp;quot;;
                                                });
                                            categorydata.push({
                                                'ProductCategoryID': value.ProductCategoryID,
                                                'ParentCategory': value.Name,
                                                'ChildCategory': subCategory
                                            });
                                            $(&amp;quot;#categoryTemplate&amp;quot;).tmpl(categorydata).appendTo(&amp;quot;#categories&amp;quot;);
                                            $(&amp;quot;#&amp;quot; &amp;#43; value.Name).html(subCategory);
                                        });

                                        GetProducts(1);
                                }
                            );
                &lt;/pre&gt;
&lt;p&gt;This call hits below method in ProductsController, and returns all Product Category to create the Upper Menu Part&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;pre id="pre2" lang="cs"&gt;                    public IQueryable&amp;lt;productcategory&amp;gt; GetProductCategories()
                    {
                        loggerService.Logger().Info(&amp;quot;Calling with null parameter&amp;quot;);
                        return _productservice.GetProductCategories().AsQueryable&amp;lt;productcategory&amp;gt;();
                    }
                &amp;lt;/productcategory&amp;gt;&amp;lt;/productcategory&amp;gt;&lt;/pre&gt;
&lt;p&gt;In ProductService implementation is :&lt;/p&gt;
&lt;pre id="pre3" lang="cs"&gt;                    public IQueryable&amp;lt;productcategory&amp;gt; GetProductCategories()
                    {
                        loggerService.Logger().Info(&amp;quot;Calling with null parameter&amp;quot;);
                        return _productservice.GetProductCategories().AsQueryable&amp;lt;productcategory&amp;gt;();
                    }
                &amp;lt;/productcategory&amp;gt;&amp;lt;/productcategory&amp;gt;&lt;/pre&gt;
&lt;p&gt;The second call is to fetch all products depends on selected category. In javascript&lt;/p&gt;
&lt;pre id="pre4" lang="js"&gt;                      function GetProducts(ProductCategoryID) {
                        var serviceURL = productcategoriesAddress &amp;#43; ProductCategoryID;
                        $('#categories li h1').css('background', '#736F6E');
                        $('#mnu' &amp;#43; ProductCategoryID).css('background', '#357EC7');
                        $(&amp;quot;#loader&amp;quot;).show();
                        $.ajax({
                            type: &amp;quot;GET&amp;quot;,
                            datatype: &amp;quot;json&amp;quot;,
                            url: serviceURL,
                            context: this,
                            success: function (value) {
                                $(&amp;quot;#productData&amp;quot;).html(&amp;quot;&amp;quot;);
                                $(&amp;quot;#productTemplate&amp;quot;).tmpl(value).appendTo(&amp;quot;#productData&amp;quot;);
                                $(&amp;quot;#loader&amp;quot;).hide();
                            }
                        });
                        return false;
                    }
                &lt;/pre&gt;
&lt;p&gt;and in ProductsController it goes to&lt;/p&gt;
&lt;pre id="pre5" lang="cs"&gt;                    public IQueryable&amp;lt;product&amp;gt; GetProductByProductCategoryID(int id)
                    {
                        loggerService.Logger().Info(&amp;quot;Calling with null parameter as : id : &amp;quot; &amp;#43; id);
                        return _productservice.GetProductByProductCategoryID(id).AsQueryable&amp;lt;product&amp;gt;();
                    }

                &amp;lt;/product&amp;gt;&amp;lt;/product&amp;gt;&lt;/pre&gt;
&lt;p&gt;In ProductService implementation is :&lt;/p&gt;
&lt;pre id="pre6" lang="cs"&gt;                    public IQueryable&amp;lt;product&amp;gt; GetProductByProductCategoryID(int id)
                    {
                        loggerService.Logger().Info(&amp;quot;Calling with null parameter as : id : &amp;quot; &amp;#43; id);
                        return _productservice.GetProductByProductCategoryID(id).AsQueryable&amp;lt;product&amp;gt;();
                    }
                &amp;lt;/product&amp;gt;&amp;lt;/product&amp;gt;&lt;/pre&gt;
&lt;p&gt;Next, let us try to add some products to Cart and Checkout cart&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/28.PNG" alt="Solution 1" width="400" height="300"&gt;&lt;/p&gt;
&lt;p&gt;On clicking on checkout It redirect to Checkout.htm page and asking for either Login using existing CustomerID or Register for a new Customer.&lt;br&gt;
Click on&amp;nbsp;&lt;strong&gt;Register&lt;/strong&gt;&amp;nbsp;link to create a new Customer.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/29.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;Submit form after clicking on Register button and see if Posting is working or not. Again its success!!!&lt;/p&gt;
&lt;p&gt;Now we will try to update records for AddressLine2, and Update is also working fine!!!&lt;/p&gt;
&lt;p&gt;In both scenario (Add or Update Customer) we are calling below method of CutomerControllers.cs&lt;/p&gt;
&lt;pre id="pre7" lang="cs"&gt;                     public int PostCustomer(CustomerDTO customer)
                    {
                        loggerService.Logger().Info(&amp;quot;Calling with parameter as : customer: &amp;quot; &amp;#43; customer);
                        return _customerService.SaveOrUpdateCustomer(customer);
                    }
                &lt;/pre&gt;
&lt;p&gt;In CustomerService implementation is :&lt;/p&gt;
&lt;pre id="pre8" lang="cs"&gt;                    public int SaveOrUpdateCustomer(CustomerDTO customer)
                    {
                        string passwordSalt = CreateSalt(5);
                        string pasword = CreatePasswordHash(customer.Password, passwordSalt);
                        Customer objCustomer;

                        if (customer.CustomerID != 0)
                            objCustomer = _customerRepository.GetById(customer.CustomerID);
                        else
                            objCustomer = new Customer();

                        objCustomer.NameStyle = customer.NameStyle;
                        objCustomer.Title = customer.Title;
                        objCustomer.FirstName = customer.FirstName;
                        objCustomer.MiddleName = customer.MiddleName;
                        objCustomer.LastName = customer.LastName;
                        objCustomer.Suffix = customer.Suffix;
                        objCustomer.CompanyName = customer.CompanyName;
                        objCustomer.SalesPerson = customer.SalesPerson;
                        objCustomer.EmailAddress = customer.EmailAddress;
                        objCustomer.Phone = customer.Phone;
                        objCustomer.PasswordHash = pasword;
                        objCustomer.PasswordSalt = passwordSalt;
                        objCustomer.ModifiedDate = DateTime.Now;
                        objCustomer.rowguid = Guid.NewGuid();

                        if (customer.CustomerID != 0)
                            _customerRepository.Update(objCustomer);
                        else
                            _customerRepository.Add(objCustomer);

                        _unitOfWork.Commit();
                        SaveOrUpdateAddress(customer, objCustomer.CustomerID);
                        return objCustomer.CustomerID;
                    }
                &lt;/pre&gt;
&lt;p&gt;Next, click on Submit Order Button, to make previously selected products as an Order and receive Order Invoice.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/33.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;!!!Hurray!!! Order is created in system and invoice is generated with a new Purchase Order. But, wait we got one BUG&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue 1:&lt;/strong&gt;&amp;nbsp;we have an issue with Date Format.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/34.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;According to,&amp;nbsp;&lt;a href="http://www.hanselman.com/blog/OnTheNightmareThatIsJSONDatesPlusJSONNETAndASPNETWebAPI.aspx"&gt;Scott Hanselman&amp;rsquo;s post&lt;/a&gt;&amp;nbsp;this is a bug and will resolve in next release of ASP.Net WebAPI. This issue is resolved using&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/02/18/using-json-net-with-asp-net-web-api.aspx"&gt;solution
 provided in Henrik's Blog&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/35.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue 2:&lt;/strong&gt;&amp;nbsp;Another issue was, when I try to Checkout Cart using the last created Customer. The error was:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/36.PNG" alt="Solution 1" width="700" height="300"&gt;&lt;/p&gt;
&lt;p&gt;After looking this error, first thought comes that we missed the method in CustomersController.cs, but the method was already there. Further investigation make it clear, that, the reason behind this error was name of this method as ValidateCustomer():&lt;/p&gt;
&lt;pre id="pre9" lang="cs"&gt;                     public CustomerDTO ValidateCustomer(int id, string password)
                    {
                        loggerService.Logger().Info(&amp;quot;Calling with parameter as : id and password: &amp;quot; &amp;#43; id &amp;#43; &amp;quot; and &amp;quot; &amp;#43; password);
                        return _customerService.ValidateCustomer(id, password);
                    }
                &lt;/pre&gt;
&lt;p&gt;In CustomerService implementation is :&lt;/p&gt;
&lt;pre id="pre10" lang="cs"&gt;                    public CustomerDTO ValidateCustomer(int id, string password)
                    {
                        Customer objCustomer = _customerRepository.GetById(id);
                        if (objCustomer == null)
                            return null;
                        string strPasswordHash = objCustomer.PasswordHash;
                        string strPasswordSalt = strPasswordHash.Substring(strPasswordHash.Length - 8);
                        string strPasword = CreatePasswordHash(password, strPasswordSalt);

                        if (strPasword.Equals(strPasswordHash))
                            return CreateCustomerDTO(objCustomer);
                        else
                            return null;
                    }
                &lt;/pre&gt;
&lt;p&gt;By default the&amp;nbsp;&lt;strong&gt;route configuration&lt;/strong&gt;&amp;nbsp;of Asp.Net WebAPI follows RESTFUL conventions meaning that it will accept only the&amp;nbsp;&lt;strong&gt;Get, Post, Put and Delete&lt;/strong&gt;&amp;nbsp;action names. So when we send a GET request to http://localhost:30000/api/customers/ValidateCustomer/30135/test
 we are basically calling the Get(int id) action and passing id=30135 which obviously crashes because we don&amp;rsquo;t have any method starting with Get which accept Id as parameter. To resolve this issue I need to add a new route definition in&amp;nbsp;&lt;strong&gt;Global.asax&lt;/strong&gt;&amp;nbsp;file
 as:&lt;/p&gt;
&lt;pre id="pre11" lang="cs"&gt;                     routes.MapHttpRoute(
                           name: &amp;quot;ValidateCustomer&amp;quot;,
                           routeTemplate: &amp;quot;api/{controller}/{action}/{id}/{password}&amp;quot;,
                           defaults: new { action = &amp;quot;get&amp;quot; }
                       );
                &lt;/pre&gt;
&lt;p&gt;Adding this line done the magic and Login functinality start waorking&amp;hellip;. :)&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step8"&gt;Step 8: Deploy on IIS&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;To deploy this API on IIS version 7.5, first, publish only&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;solution to a Folder.&lt;/p&gt;
&lt;p&gt;Next, open IIS Manager and create a new website and set path to Publish folder, and we are done with deployment.&lt;/p&gt;
&lt;p&gt;Now, check whether page is opening or not, in my case, initially I got below error, which is self-explanatory.&lt;br&gt;
The error comes because this application is running on Asp.Net Framework Version 2.0. So, we need to change it to Asp.Net Framework Version 4.0:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/40.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/41.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;To change the Asp.Net Framework from 2.0 to 4.0, follow below steps.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/42.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/43.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;That was not the only reason not to run application, because after made above change in Application pool next error was:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/44.PNG" alt="Solution 1" width="700" height="200"&gt;&lt;/p&gt;
&lt;p&gt;To resolve this error again go to Advance Settings of Application pool and change the identity to Local System from ApplicationPoolIdentity&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/45.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;After modify the Application pool to use Local System, Application starts working on browser... :)&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/46.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;Although IIS errors are depending on servers/Firewall/Network or system to system, so it is very difficult to assume that you will also get the same error as mine. Check these links which help me to resolve some of the IIS issues in
 my work environment.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en/wcf/thread/b990d3ea-3335-40a6-877f-7c295da67a85"&gt;HTTP Error 500.19&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/eu/wcf/thread/39571e42-aca7-469d-8c68-aa59c2da4fcc"&gt;Could Not Load Type &amp;lsquo;System.ServiceModel.Activation.HttpModule&amp;rsquo;&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/k6h9cz8h.aspx"&gt;ASP.NET IIS Registration Tool&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms732012.aspx"&gt;ServiceModel Registration Tool&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step9"&gt;Step 9: Cross Domain Support&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The idea behind the Cross Domain Support comes when I try to remove all HTML pages from&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;solution and created a new Empty Web Application (Adventure.Website) which includes only&amp;nbsp;&lt;strong&gt;.html, .Js and .css&lt;/strong&gt;&amp;nbsp;files
 along with images. The structure for this application is as per below image:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/47.PNG" alt="Solution 1" width="300" height="500"&gt;&lt;/p&gt;
&lt;p&gt;Point all URL address to deployed code on IIS, after build and run application, output was null.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/48.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;To resolve this issue I would like to give my special thanks to Carlos&amp;rsquo; blog on MSDN&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2012/02/20/implementing-cors-support-in-asp-net-web-apis.aspx"&gt;Implementing CORS support in ASP.NET Web
 APIs&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;blockquote&gt;
&lt;div&gt;Quote:&lt;/div&gt;
&amp;ldquo;By default, a web page cannot make calls to services (APIs) on a domain other than the one where the page came from. This is a security measure against a group of cross-site forgery attacks in which browsing to a bad site could potentially use the browser
 cookies to get data from a good site which the user had previously logged on (think your bank). There are many situations, however, where getting data from different sites is a perfectly valid scenario, such as mash-up applications which need data from different
 sources.&amp;rdquo;&lt;/blockquote&gt;
&lt;h2&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;That's it !!! Hope you enjoy this article. I am not an expert, and also I have not followed the entire industry standard at the time of writing this article (time factor).&lt;/p&gt;
&lt;p&gt;All&amp;nbsp;&lt;strong&gt;comment/Vote&lt;/strong&gt;&amp;nbsp;are more than welcome&amp;hellip;. :), whenever, I get time, will try to modify this solution. You can also join/contribute to this project on&amp;nbsp;&lt;a href="http://pocwebapi.codeplex.com/"&gt;CodePlex&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Thank's for your time.&lt;/p&gt;
&lt;p&gt;Anand&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;br&gt;
&lt;/strong&gt;&lt;br&gt;
&lt;br&gt;
&lt;/p&gt;
&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>anandranjanpandey</author><pubDate>Thu, 22 Mar 2012 05:56:57 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20120322055657A</guid></item><item><title>Updated Wiki: Documentation</title><link>http://pocwebapi.codeplex.com/documentation?version=5</link><description>&lt;div class="wikidoc"&gt;
&lt;h2&gt;&lt;strong&gt;Introduction&amp;nbsp;&lt;/strong&gt;&amp;nbsp;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The purpose of this article is to create a&lt;strong&gt;&amp;nbsp;proof of concept&amp;nbsp;&lt;/strong&gt;to demonstrate the feasibility of&amp;nbsp;&lt;a href="http://www.asp.net/web-api"&gt;ASP.NET WebAPI&lt;/a&gt;&amp;nbsp;Beta version.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Prerequisite:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://msftdbprodsamples.codeplex.com/"&gt;AdventureWorksLT2008R2&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://www.asp.net/web-api"&gt;ASP.Net WebAPI&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://code.google.com/p/autofac/downloads/list"&gt;Autofac for Dependency Injection&lt;/a&gt;&amp;nbsp;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://logging.apache.org/log4net/download.html"&gt;Log4Net&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://www.microsoft.com/download/en/details.aspx?displaylang=en&amp;id=8363"&gt;EntityFramework 4.1&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="https://github.com/jquery/jquery-tmpl"&gt;jQuery Templates plugin (jquery-tmpl)&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Goals to achieve:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Any user should be able to view products &lt;/li&gt;&lt;li&gt;Product would be filtered by Categories &lt;/li&gt;&lt;li&gt;User should be able to add products in cart &lt;/li&gt;&lt;li&gt;Only registered user will be able to submit cart &lt;/li&gt;&lt;li&gt;User should be able to register into system &lt;/li&gt;&lt;li&gt;User will get confirmation Invoice after generating order in system. &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Architecture for this POC&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I am not following any specific Architecture Pattern, although while designing this POC, I&amp;nbsp;&lt;strong&gt;try to follow&lt;/strong&gt;&amp;nbsp;some of the key design principles like:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Separation_of_concerns"&gt;Separation of concerns&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Abstraction_(computer_science)"&gt;Abstraction&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself"&gt;Don't repeat yourself&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/KISS_principle"&gt;KISS principle&lt;/a&gt; &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;span&gt;Again I am repeating my word&amp;nbsp;&lt;strong&gt;try to follow&amp;hellip;.. :)&lt;/strong&gt;. So, all comments/suggestions are more than welcome to discuss and I am always ready to adopt changes, or you can do it yourself by join&amp;nbsp;&lt;a href="http://pocwebapi.codeplex.com/"&gt;@CodePlex&lt;/a&gt;.
 The initial Skeleton for this application is as per below diagram:&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/1.PNG" alt="Architecture" width="650" height="500"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Step-by-Step&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Step 1: Create a basic Application Structure Layout &lt;/li&gt;&lt;li&gt;Step 2: Create the Data Access Layer &lt;/li&gt;&lt;li&gt;Step 3: Create the Service Layer &lt;/li&gt;&lt;li&gt;Step 4: Create the API Layer &lt;/li&gt;&lt;li&gt;Step 5: Integration of Dependency Injection using Autofac &lt;/li&gt;&lt;li&gt;Step 6: Add Views to solution &lt;/li&gt;&lt;li&gt;Step 7: Unit test and resolve issues &lt;/li&gt;&lt;li&gt;Step 8: Deploy application on IIS &lt;/li&gt;&lt;li&gt;Step 9: Provide Cross Domain Support &lt;/li&gt;&lt;/ul&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step1"&gt;Step 1: Create a basic Application Structure Layout&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;For more information on ASP.NET WebAPI, watch Videos and Tutorials&amp;nbsp;&lt;a href="http://www.asp.net/web-api"&gt;here&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add a blank Solution named as&amp;nbsp;&lt;strong&gt;Application&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add a new Project (Class Library) named as&amp;nbsp;&lt;strong&gt;Application.DAL&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Repeat above process and create four more Class Library projects named as &amp;ndash;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Application.Model&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Repository&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Common&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Service&lt;/strong&gt; &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;span&gt;Now, application will look like below screen-shot&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/4.PNG" alt="Solution 1" width="250" height="350"&gt;&lt;/p&gt;
&lt;p&gt;Next, add a new Project named as&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;as ASP.Net MVC 4 Web Application. After click on OK, select template as Web API&lt;/p&gt;
&lt;p&gt;&lt;span&gt;This will add a full functional Web API template Application into our main solution.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/7.PNG" alt="Solution 1" width="230" height="350"&gt;&lt;/p&gt;
&lt;p&gt;Right click on Application.API project in Solution Explorer and go to properties, than assign a port to be use by this service application ( In my case its 30000). Hit F5 and we are ready with a dummy data as below screen:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/8.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step2"&gt;Step 2: Prepare Application.DAL, Application.Repository and Application.Model Layers&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Check&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/library/bb399182.aspx"&gt;@MSDN&lt;/a&gt;&amp;nbsp;for more information on Entity Framework&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add Entity Data Model to&amp;nbsp;&lt;strong&gt;Application.DAL&lt;/strong&gt;&amp;nbsp;project. To do this select ADO.NET Entity Data Model from the Data Templates list, and name it as&amp;nbsp;&lt;strong&gt;AdventureWorks.edmx&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Choose&amp;nbsp;&lt;strong&gt;&amp;ldquo;Generate from Database&amp;rdquo;&lt;/strong&gt;&amp;nbsp;and provide the connection string to read the database schema. This will add AdventureWorks.edmx into current project. Right click on the blank space in Entity Model surface and click
 on properties (or alternate press Alt &amp;#43;Enter on keyboard). Now set its Code Generation Strategy as&amp;nbsp;&lt;strong&gt;None&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/10.PNG" alt="Solution 1" width="550" height="300"&gt;&lt;/p&gt;
&lt;p&gt;Now create POCO entities for AdventureWorks Data Model into&amp;nbsp;&lt;strong&gt;Application.Model&lt;/strong&gt;&amp;nbsp;Solution. Check this article to do this job for you on MSDN to use&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/gg558520"&gt;T4 Templates and the Entity
 Framework&lt;/a&gt;&lt;br&gt;
Then, create all required repositories under Application.Repositories.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/11.PNG" alt="Solution 1" width="250" height="500"&gt;&lt;/p&gt;
&lt;p&gt;To build solution, add reference of&amp;nbsp;&lt;strong&gt;Application.Model.dll&lt;/strong&gt;&amp;nbsp;to&amp;nbsp;&lt;strong&gt;Application.DAL.dll&lt;/strong&gt;&amp;nbsp;and&amp;nbsp;&lt;strong&gt;Application.Repository.dll&lt;/strong&gt;projects, and add reference of&amp;nbsp;&lt;strong&gt;Application.DAL.dll&lt;/strong&gt;&amp;nbsp;to&amp;nbsp;&lt;strong&gt;Application.Repository.dll&lt;/strong&gt;&amp;nbsp;project.
 (See below picture for reference)&lt;br&gt;
Before proceeding to next step (designing Application.Service and Application.API Layer), let us see what we have designed yet:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/12.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step3"&gt;Step 3: Add files to Application.Service Layer&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Before adding files to Service layer let us look at the Goals which we want to achieve.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Any user should be able to view products &lt;/li&gt;&lt;li&gt;Product would be filtered by Categories &lt;/li&gt;&lt;li&gt;User should be able to add products in cart &lt;/li&gt;&lt;li&gt;Only registered user will be able to submit cart &lt;/li&gt;&lt;li&gt;User should be able to register into system &lt;/li&gt;&lt;li&gt;User will get confirmation Invoice after generating order in system. &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To achieve the above mention Goals, we need to add three service classes to Application.Service as per below image&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/13.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/14.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;I am not going in deatils, as the implementation for each methods are clear and easy to understand.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step4"&gt;Step 4: Add files to Application.API Layer&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To make this Web API accessed from a broad range of clients like any browsers which use JavaScript or any windows/Mobile platform which supports .dll files, we need to add Controllers with base class as&amp;nbsp;&lt;strong&gt;ApiController&lt;/strong&gt;.&amp;nbsp;&lt;a href="http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api"&gt;More
 details here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;First, we remove the default controllers added by template (HomeController and ValuesController) and then add three new controllers as per below diagram:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/15.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;Again, nothing special in the implementation of these methods, they all jst push the data to service layer.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step5"&gt;Step 5: Integration of Dependency Injection with WebAPI using Autofac&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The implementation is very much straight forward and clear.&amp;nbsp;&lt;a href="http://alexmg.com/post/2012/03/08/Autofac-ASPNET-Web-API-%28Beta%29-Integration.aspx"&gt;Check Alex post here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;Solution Explorer, right-click the References node and click Manage NuGet Packages&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/16.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;It will open the below screen.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/17.PNG" alt="Solution 1" width="700" height="200"&gt;&lt;/p&gt;
&lt;p&gt;Click on install and it will add below three references in solution&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/18.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;Next, go to Global.asax.cs and create a method named as ResolveDependency()&lt;/p&gt;
&lt;pre id="pre0" lang="cs"&gt;             &lt;span&gt;protected&lt;/span&gt; &lt;span&gt;void&lt;/span&gt; ResolveDependancy()
                {
                    &lt;span&gt;var&lt;/span&gt; configuration = GlobalConfiguration.Configuration;
                    &lt;span&gt;var&lt;/span&gt; builder = &lt;span&gt;new&lt;/span&gt; ContainerBuilder();

                    &lt;span&gt;//&lt;/span&gt;&lt;span&gt; Configure the container with the integration implementations.
&lt;/span&gt;                    builder.ConfigureWebApi(configuration);

                    &lt;span&gt;//&lt;/span&gt;&lt;span&gt; Register API controllers using assembly scanning.
&lt;/span&gt;                    builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

                    builder.RegisterType&amp;lt;logservice&amp;gt;().As&amp;lt;ilogservice&amp;gt;().InstancePerLifetimeScope();
                    builder.RegisterType&amp;lt;unitofwork&amp;gt;().As&amp;lt;iunitofwork&amp;gt;().InstancePerDependency();
                    builder.RegisterType&amp;lt;databasefactory&amp;gt;().As&amp;lt;idatabasefactory&amp;gt;().InstancePerLifetimeScope();
                    builder.RegisterAssemblyTypes(&lt;span&gt;typeof&lt;/span&gt;(ProductService).Assembly)
                    .Where(t =&amp;gt; t.Name.EndsWith(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Service&amp;quot;&lt;/span&gt;))
                    .AsImplementedInterfaces().InstancePerDependency();
                    builder.RegisterAssemblyTypes(&lt;span&gt;typeof&lt;/span&gt;(CustomerRepository).Assembly)
                    .Where(t =&amp;gt; t.Name.EndsWith(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Repository&amp;quot;&lt;/span&gt;))
                    .AsImplementedInterfaces().InstancePerDependency();      

                    &lt;span&gt;var&lt;/span&gt; container = builder.Build();

                    &lt;span&gt;//&lt;/span&gt;&lt;span&gt; Set the dependency resolver implementation.
&lt;/span&gt;                    &lt;span&gt;var&lt;/span&gt; resolver = &lt;span&gt;new&lt;/span&gt; AutofacWebApiDependencyResolver(container);
                    configuration.ServiceResolver.SetResolver(resolver);
                }
            &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;idatabasefactory&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;databasefactory&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;iunitofwork&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;unitofwork&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;ilogservice&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;logservice&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Now we are ready to test our application. Hit F5 and check the browser with following url&amp;rsquo;s:&amp;nbsp;&lt;br&gt;
http://localhost:30000/api/products : will result all Product Categories&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/20.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;http://localhost:30000/api/products/2 : will result all Products with ProductcategoryID as 2&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/21.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;To check other methods, First we will add some Views in current solution.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step6"&gt;Step 6: Add View to solution&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Delete all default files and folders from Views Folder, and add three Html and their supportive Javascript File as. For this POC we will use html files, and some jquery libraries like:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;jquery.tmpl.js :&lt;/strong&gt;&amp;nbsp;to create template based screen, and&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;jquery.validationEngine.js :&lt;/strong&gt;&amp;nbsp;to validate form data&lt;/p&gt;
&lt;p&gt;Now the structure will looks like below picture :&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/22.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;For details code in html and JS file please look into the code. In next step I am going to resolve problems.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step7"&gt;Step 7: Resolve issues&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Before run the application Right Click on Products.htm and click on Set As start Page. Now hit F5&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/23.PNG" alt="Solution 1" width="700" height="300"&gt;&lt;/p&gt;
&lt;p&gt;It means, two WebAPI methods in ProductsController.cs are working perfectly. In JavaScript, on page load we are calling first method inside&amp;nbsp;&lt;strong&gt;product.js&lt;/strong&gt;&amp;nbsp;as:&lt;/p&gt;
&lt;pre id="pre1" lang="js"&gt;                    var productcategoriesAddress = &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;/api/products/&amp;quot;&lt;/span&gt;;
                    $(function () {
                        $(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;#tblRight'&lt;/span&gt;).hide();
                        $.getJSON(
                                productcategoriesAddress,
                                function (data) {
                                    var parents = jQuery.grep(data, function (a) { &lt;span&gt;return&lt;/span&gt; a.ParentProductCategoryID == null });
                                    var childs = jQuery.grep(data, function (a) { &lt;span&gt;return&lt;/span&gt; a.ParentProductCategoryID != null });
                                    $.&lt;span&gt;each&lt;/span&gt;(parents,
                                        function (index, &lt;span&gt;value&lt;/span&gt;) {
                                            var categorydata = [];
                                            var subCategory = &lt;span&gt;'&lt;/span&gt;&lt;span&gt;'&lt;/span&gt;;
                                            var subChild = jQuery.grep(childs, function (a) { &lt;span&gt;return&lt;/span&gt; a.ParentProductCategoryID == &lt;span&gt;value&lt;/span&gt;.ProductCategoryID });
                                            $.&lt;span&gt;each&lt;/span&gt;(subChild,
                                                function (index, item) {
                                                    var serviceURL = productcategoriesAddress &amp;#43; item.ProductCategoryID;
                                                    subCategory = subCategory &amp;#43; &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;  &amp;quot;&lt;/span&gt; &amp;#43; &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;lt;a href=&amp;quot;&lt;/span&gt;%20&amp;#43;%20serviceURL%20&amp;#43;%20&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt; class=&amp;quot;&lt;/span&gt;menuButton&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;gt;&amp;quot;&lt;/span&gt; &amp;#43; item.Name &amp;#43; &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;lt;/a&amp;gt;&amp;quot;&lt;/span&gt;;
                                                });
                                            categorydata.push({
                                                &lt;span&gt;'&lt;/span&gt;&lt;span&gt;ProductCategoryID'&lt;/span&gt;: &lt;span&gt;value&lt;/span&gt;.ProductCategoryID,
                                                &lt;span&gt;'&lt;/span&gt;&lt;span&gt;ParentCategory'&lt;/span&gt;: &lt;span&gt;value&lt;/span&gt;.Name,
                                                &lt;span&gt;'&lt;/span&gt;&lt;span&gt;ChildCategory'&lt;/span&gt;: subCategory
                                            });
                                            $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#categoryTemplate&amp;quot;&lt;/span&gt;).tmpl(categorydata).appendTo(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#categories&amp;quot;&lt;/span&gt;);
                                            $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#&amp;quot;&lt;/span&gt; &amp;#43; &lt;span&gt;value&lt;/span&gt;.Name).html(subCategory);
                                        });

                                        GetProducts(&lt;span&gt;1&lt;/span&gt;);
                                }
                            );
                &lt;/pre&gt;
&lt;p&gt;This call hits below method in ProductsController, and returns all Product Category to create the Upper Menu Part&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;pre id="pre2" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; IQueryable&amp;lt;productcategory&amp;gt; GetProductCategories()
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with null parameter&amp;quot;&lt;/span&gt;);
                        &lt;span&gt;return&lt;/span&gt; _productservice.GetProductCategories().AsQueryable&amp;lt;productcategory&amp;gt;();
                    }
                &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;productcategory&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;productcategory&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;In ProductService implementation is :&lt;/p&gt;
&lt;pre id="pre3" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; IQueryable&amp;lt;productcategory&amp;gt; GetProductCategories()
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with null parameter&amp;quot;&lt;/span&gt;);
                        &lt;span&gt;return&lt;/span&gt; _productservice.GetProductCategories().AsQueryable&amp;lt;productcategory&amp;gt;();
                    }
                &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;productcategory&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;productcategory&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;The second call is to fetch all products depends on selected category. In javascript&lt;/p&gt;
&lt;pre id="pre4" lang="js"&gt;                      function GetProducts(ProductCategoryID) {
                        var serviceURL = productcategoriesAddress &amp;#43; ProductCategoryID;
                        $(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;#categories li h1'&lt;/span&gt;).css(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;background'&lt;/span&gt;, &lt;span&gt;'&lt;/span&gt;&lt;span&gt;#736F6E'&lt;/span&gt;);
                        $(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;#mnu'&lt;/span&gt; &amp;#43; ProductCategoryID).css(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;background'&lt;/span&gt;, &lt;span&gt;'&lt;/span&gt;&lt;span&gt;#357EC7'&lt;/span&gt;);
                        $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#loader&amp;quot;&lt;/span&gt;).show();
                        $.ajax({
                            type: &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;GET&amp;quot;&lt;/span&gt;,
                            datatype: &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;json&amp;quot;&lt;/span&gt;,
                            url: serviceURL,
                            context: &lt;span&gt;this&lt;/span&gt;,
                            success: function (&lt;span&gt;value&lt;/span&gt;) {
                                $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#productData&amp;quot;&lt;/span&gt;).html(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;quot;&lt;/span&gt;);
                                $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#productTemplate&amp;quot;&lt;/span&gt;).tmpl(&lt;span&gt;value&lt;/span&gt;).appendTo(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#productData&amp;quot;&lt;/span&gt;);
                                $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#loader&amp;quot;&lt;/span&gt;).hide();
                            }
                        });
                        &lt;span&gt;return&lt;/span&gt; &lt;span&gt;false&lt;/span&gt;;
                    }
                &lt;/pre&gt;
&lt;p&gt;and in ProductsController it goes to&lt;/p&gt;
&lt;pre id="pre5" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; IQueryable&amp;lt;product&amp;gt; GetProductByProductCategoryID(&lt;span&gt;int&lt;/span&gt; id)
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with null parameter as : id : &amp;quot;&lt;/span&gt; &amp;#43; id);
                        &lt;span&gt;return&lt;/span&gt; _productservice.GetProductByProductCategoryID(id).AsQueryable&amp;lt;product&amp;gt;();
                    }

                &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;product&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;product&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;In ProductService implementation is :&lt;/p&gt;
&lt;pre id="pre6" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; IQueryable&amp;lt;product&amp;gt; GetProductByProductCategoryID(&lt;span&gt;int&lt;/span&gt; id)
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with null parameter as : id : &amp;quot;&lt;/span&gt; &amp;#43; id);
                        &lt;span&gt;return&lt;/span&gt; _productservice.GetProductByProductCategoryID(id).AsQueryable&amp;lt;product&amp;gt;();
                    }
                &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;product&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;product&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Next, let us try to add some products to Cart and Checkout cart&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/28.PNG" alt="Solution 1" width="400" height="300"&gt;&lt;/p&gt;
&lt;p&gt;On clicking on checkout It redirect to Checkout.htm page and asking for either Login using existing CustomerID or Register for a new Customer.&lt;br&gt;
Click on&amp;nbsp;&lt;strong&gt;Register&lt;/strong&gt;&amp;nbsp;link to create a new Customer.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/29.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;Submit form after clicking on Register button and see if Posting is working or not. Again its success!!!&lt;/p&gt;
&lt;p&gt;Now we will try to update records for AddressLine2, and Update is also working fine!!!&lt;/p&gt;
&lt;p&gt;In both scenario (Add or Update Customer) we are calling below method of CutomerControllers.cs&lt;/p&gt;
&lt;pre id="pre7" lang="cs"&gt;                     &lt;span&gt;public&lt;/span&gt; &lt;span&gt;int&lt;/span&gt; PostCustomer(CustomerDTO customer)
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with parameter as : customer: &amp;quot;&lt;/span&gt; &amp;#43; customer);
                        &lt;span&gt;return&lt;/span&gt; _customerService.SaveOrUpdateCustomer(customer);
                    }
                &lt;/pre&gt;
&lt;p&gt;In CustomerService implementation is :&lt;/p&gt;
&lt;pre id="pre8" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;int&lt;/span&gt; SaveOrUpdateCustomer(CustomerDTO customer)
                    {
                        &lt;span&gt;string&lt;/span&gt; passwordSalt = CreateSalt(&lt;span&gt;5&lt;/span&gt;);
                        &lt;span&gt;string&lt;/span&gt; pasword = CreatePasswordHash(customer.Password, passwordSalt);
                        Customer objCustomer;

                        &lt;span&gt;if&lt;/span&gt; (customer.CustomerID != &lt;span&gt;0&lt;/span&gt;)
                            objCustomer = _customerRepository.GetById(customer.CustomerID);
                        &lt;span&gt;else&lt;/span&gt;
                            objCustomer = &lt;span&gt;new&lt;/span&gt; Customer();

                        objCustomer.NameStyle = customer.NameStyle;
                        objCustomer.Title = customer.Title;
                        objCustomer.FirstName = customer.FirstName;
                        objCustomer.MiddleName = customer.MiddleName;
                        objCustomer.LastName = customer.LastName;
                        objCustomer.Suffix = customer.Suffix;
                        objCustomer.CompanyName = customer.CompanyName;
                        objCustomer.SalesPerson = customer.SalesPerson;
                        objCustomer.EmailAddress = customer.EmailAddress;
                        objCustomer.Phone = customer.Phone;
                        objCustomer.PasswordHash = pasword;
                        objCustomer.PasswordSalt = passwordSalt;
                        objCustomer.ModifiedDate = DateTime.Now;
                        objCustomer.rowguid = Guid.NewGuid();

                        &lt;span&gt;if&lt;/span&gt; (customer.CustomerID != &lt;span&gt;0&lt;/span&gt;)
                            _customerRepository.Update(objCustomer);
                        &lt;span&gt;else&lt;/span&gt;
                            _customerRepository.Add(objCustomer);

                        _unitOfWork.Commit();
                        SaveOrUpdateAddress(customer, objCustomer.CustomerID);
                        &lt;span&gt;return&lt;/span&gt; objCustomer.CustomerID;
                    }
                &lt;/pre&gt;
&lt;p&gt;Next, click on Submit Order Button, to make previously selected products as an Order and receive Order Invoice.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/33.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;!!!Hurray!!! Order is created in system and invoice is generated with a new Purchase Order. But, wait we got one BUG&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue 1:&lt;/strong&gt;&amp;nbsp;we have an issue with Date Format.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/34.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;According to,&amp;nbsp;&lt;a href="http://www.hanselman.com/blog/OnTheNightmareThatIsJSONDatesPlusJSONNETAndASPNETWebAPI.aspx"&gt;Scott Hanselman&amp;rsquo;s post&lt;/a&gt;&amp;nbsp;this is a bug and will resolve in next release of ASP.Net WebAPI. This issue is resolved using&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/02/18/using-json-net-with-asp-net-web-api.aspx"&gt;solution
 provided in Henrik's Blog&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/35.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue 2:&lt;/strong&gt;&amp;nbsp;Another issue was, when I try to Checkout Cart using the last created Customer. The error was:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/36.PNG" alt="Solution 1" width="700" height="300"&gt;&lt;/p&gt;
&lt;p&gt;After looking this error, first thought comes that we missed the method in CustomersController.cs, but the method was already there. Further investigation make it clear, that, the reason behind this error was name of this method as ValidateCustomer():&lt;/p&gt;
&lt;pre id="pre9" lang="cs"&gt;                     &lt;span&gt;public&lt;/span&gt; CustomerDTO ValidateCustomer(&lt;span&gt;int&lt;/span&gt; id, &lt;span&gt;string&lt;/span&gt; password)
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with parameter as : id and password: &amp;quot;&lt;/span&gt; &amp;#43; id &amp;#43; &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt; and &amp;quot;&lt;/span&gt; &amp;#43; password);
                        &lt;span&gt;return&lt;/span&gt; _customerService.ValidateCustomer(id, password);
                    }
                &lt;/pre&gt;
&lt;p&gt;In CustomerService implementation is :&lt;/p&gt;
&lt;pre id="pre10" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; CustomerDTO ValidateCustomer(&lt;span&gt;int&lt;/span&gt; id, &lt;span&gt;string&lt;/span&gt; password)
                    {
                        Customer objCustomer = _customerRepository.GetById(id);
                        &lt;span&gt;if&lt;/span&gt; (objCustomer == &lt;span&gt;null&lt;/span&gt;)
                            &lt;span&gt;return&lt;/span&gt; &lt;span&gt;null&lt;/span&gt;;
                        &lt;span&gt;string&lt;/span&gt; strPasswordHash = objCustomer.PasswordHash;
                        &lt;span&gt;string&lt;/span&gt; strPasswordSalt = strPasswordHash.Substring(strPasswordHash.Length - &lt;span&gt;8&lt;/span&gt;);
                        &lt;span&gt;string&lt;/span&gt; strPasword = CreatePasswordHash(password, strPasswordSalt);

                        &lt;span&gt;if&lt;/span&gt; (strPasword.Equals(strPasswordHash))
                            &lt;span&gt;return&lt;/span&gt; CreateCustomerDTO(objCustomer);
                        &lt;span&gt;else&lt;/span&gt;
                            &lt;span&gt;return&lt;/span&gt; &lt;span&gt;null&lt;/span&gt;;
                    }
                &lt;/pre&gt;
&lt;p&gt;By default the&amp;nbsp;&lt;strong&gt;route configuration&lt;/strong&gt;&amp;nbsp;of Asp.Net WebAPI follows RESTFUL conventions meaning that it will accept only the&amp;nbsp;&lt;strong&gt;Get, Post, Put and Delete&lt;/strong&gt;&amp;nbsp;action names. So when we send a GET request to http://localhost:30000/api/customers/ValidateCustomer/30135/test
 we are basically calling the Get(int id) action and passing id=30135 which obviously crashes because we don&amp;rsquo;t have any method starting with Get which accept Id as parameter. To resolve this issue I need to add a new route definition in&amp;nbsp;&lt;strong&gt;Global.asax&lt;/strong&gt;&amp;nbsp;file
 as:&lt;/p&gt;
&lt;pre id="pre11" lang="cs"&gt;                     routes.MapHttpRoute(
                           name: &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;ValidateCustomer&amp;quot;&lt;/span&gt;,
                           routeTemplate: &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;api/{controller}/{action}/{id}/{password}&amp;quot;&lt;/span&gt;,
                           defaults: &lt;span&gt;new&lt;/span&gt; { action = &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;get&amp;quot;&lt;/span&gt; }
                       );
                &lt;/pre&gt;
&lt;p&gt;Adding this line done the magic and Login functinality start waorking&amp;hellip;. :)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step8"&gt;Step 8: Deploy on IIS&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To deploy this API on IIS version 7.5, first, publish only&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;solution to a Folder.&lt;/p&gt;
&lt;p&gt;Next, open IIS Manager and create a new website and set path to Publish folder, and we are done with deployment.&lt;/p&gt;
&lt;p&gt;Now, check whether page is opening or not, in my case, initially I got below error, which is self-explanatory.&lt;br&gt;
The error comes because this application is running on Asp.Net Framework Version 2.0. So, we need to change it to Asp.Net Framework Version 4.0:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/40.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/41.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;To change the Asp.Net Framework from 2.0 to 4.0, follow below steps.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/42.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/43.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;That was not the only reason not to run application, because after made above change in Application pool next error was:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/44.PNG" alt="Solution 1" width="700" height="200"&gt;&lt;/p&gt;
&lt;p&gt;To resolve this error again go to Advance Settings of Application pool and change the identity to Local System from ApplicationPoolIdentity&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/45.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;After modify the Application pool to use Local System, Application starts working on browser... :)&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/46.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;Although IIS errors are depending on servers/Firewall/Network or system to system, so it is very difficult to assume that you will also get the same error as mine. Check these links which help me to resolve some of the IIS issues in
 my work environment.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en/wcf/thread/b990d3ea-3335-40a6-877f-7c295da67a85"&gt;HTTP Error 500.19&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/eu/wcf/thread/39571e42-aca7-469d-8c68-aa59c2da4fcc"&gt;Could Not Load Type &amp;lsquo;System.ServiceModel.Activation.HttpModule&amp;rsquo;&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/k6h9cz8h.aspx"&gt;ASP.NET IIS Registration Tool&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms732012.aspx"&gt;ServiceModel Registration Tool&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step9"&gt;Step 9: Cross Domain Support&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The idea behind the Cross Domain Support comes when I try to remove all HTML pages from&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;solution and created a new Empty Web Application (Adventure.Website) which includes only&amp;nbsp;&lt;strong&gt;.html, .Js and .css&lt;/strong&gt;&amp;nbsp;files
 along with images. The structure for this application is as per below image:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/47.PNG" alt="Solution 1" width="300" height="500"&gt;&lt;/p&gt;
&lt;p&gt;Point all URL address to deployed code on IIS, after build and run application, output was null.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/48.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;To resolve this issue I would like to give my special thanks to Carlos&amp;rsquo; blog on MSDN&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2012/02/20/implementing-cors-support-in-asp-net-web-apis.aspx"&gt;Implementing CORS support in ASP.NET Web
 APIs&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;blockquote&gt;
&lt;div&gt;Quote:&lt;/div&gt;
&amp;ldquo;By default, a web page cannot make calls to services (APIs) on a domain other than the one where the page came from. This is a security measure against a group of cross-site forgery attacks in which browsing to a bad site could potentially use the browser
 cookies to get data from a good site which the user had previously logged on (think your bank). There are many situations, however, where getting data from different sites is a perfectly valid scenario, such as mash-up applications which need data from different
 sources.&amp;rdquo;&lt;/blockquote&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;That's it !!! Hope you enjoy this article. I am not an expert, and also I have not followed the entire industry standard at the time of writing this article (time factor).&lt;/p&gt;
&lt;p&gt;All&amp;nbsp;&lt;strong&gt;comment/Vote&lt;/strong&gt;&amp;nbsp;are more than welcome&amp;hellip;. :), whenever, I get time, will try to modify this solution. You can also join/contribute to this project on&amp;nbsp;&lt;a href="http://pocwebapi.codeplex.com/"&gt;CodePlex&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Thank's for your time.&lt;/p&gt;
&lt;p&gt;Anand&lt;/p&gt;
&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>anandranjanpandey</author><pubDate>Thu, 22 Mar 2012 05:55:57 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Documentation 20120322055557A</guid></item><item><title>Updated Wiki: Documentation</title><link>http://pocwebapi.codeplex.com/documentation?version=4</link><description>&lt;div class="wikidoc"&gt;
&lt;h2&gt;&lt;strong&gt;Introduction&amp;nbsp;&lt;/strong&gt;&amp;nbsp;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The purpose of this article is to create a&lt;strong&gt;&amp;nbsp;proof of concept&amp;nbsp;&lt;/strong&gt;to demonstrate the feasibility of&amp;nbsp;&lt;a href="http://www.asp.net/web-api"&gt;ASP.NET WebAPI&lt;/a&gt;&amp;nbsp;Beta version.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Prerequisite:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://msftdbprodsamples.codeplex.com/"&gt;AdventureWorksLT2008R2&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://www.asp.net/web-api"&gt;ASP.Net WebAPI&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://code.google.com/p/autofac/downloads/list"&gt;Autofac for Dependency Injection&lt;/a&gt;&amp;nbsp;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://logging.apache.org/log4net/download.html"&gt;Log4Net&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://www.microsoft.com/download/en/details.aspx?displaylang=en&amp;id=8363"&gt;EntityFramework 4.1&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="https://github.com/jquery/jquery-tmpl"&gt;jQuery Templates plugin (jquery-tmpl)&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Goals to achieve:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Any user should be able to view products &lt;/li&gt;&lt;li&gt;Product would be filtered by Categories &lt;/li&gt;&lt;li&gt;User should be able to add products in cart &lt;/li&gt;&lt;li&gt;Only registered user will be able to submit cart &lt;/li&gt;&lt;li&gt;User should be able to register into system &lt;/li&gt;&lt;li&gt;User will get confirmation Invoice after generating order in system. &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Architecture for this POC&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I am not following any specific Architecture Pattern, although while designing this POC, I&amp;nbsp;&lt;strong&gt;try to follow&lt;/strong&gt;&amp;nbsp;some of the key design principles like:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Separation_of_concerns"&gt;Separation of concerns&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Abstraction_(computer_science)"&gt;Abstraction&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself"&gt;Don't repeat yourself&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/KISS_principle"&gt;KISS principle&lt;/a&gt; &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;span&gt;Again I am repeating my word&amp;nbsp;&lt;strong&gt;try to follow&amp;hellip;.. :)&lt;/strong&gt;. So, all comments/suggestions are more than welcome to discuss and I am always ready to adopt changes, or you can do it yourself by join&amp;nbsp;&lt;a href="http://pocwebapi.codeplex.com/"&gt;@CodePlex&lt;/a&gt;.
 The initial Skeleton for this application is as per below diagram:&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/1.PNG" alt="Architecture" width="650" height="500"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Step-by-Step&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="#x_step1"&gt;Step 1: Create a basic Application Structure Layout&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="#x_step2"&gt;Step 2: Create the Data Access Layer&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="#x_step3"&gt;Step 3: Create the Service Layer&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="#x_step4"&gt;Step 4: Create the API Layer&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="#x_step5"&gt;Step 5: Integration of Dependency Injection using Autofac&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="#x_step6"&gt;Step 6: Add Views to solution&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="#x_step7"&gt;Step 7: Unit test and resolve issues&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="#x_step8"&gt;Step 8: Deploy application on IIS&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="#x_step9"&gt;Step 9: Provide Cross Domain Support&lt;/a&gt; &lt;/li&gt;&lt;/ul&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step1"&gt;Step 1: Create a basic Application Structure Layout&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;For more information on ASP.NET WebAPI, watch Videos and Tutorials&amp;nbsp;&lt;a href="http://www.asp.net/web-api"&gt;here&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add a blank Solution named as&amp;nbsp;&lt;strong&gt;Application&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add a new Project (Class Library) named as&amp;nbsp;&lt;strong&gt;Application.DAL&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Repeat above process and create four more Class Library projects named as &amp;ndash;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Application.Model&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Repository&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Common&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Service&lt;/strong&gt; &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;span&gt;Now, application will look like below screen-shot&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/4.PNG" alt="Solution 1" width="250" height="350"&gt;&lt;/p&gt;
&lt;p&gt;Next, add a new Project named as&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;as ASP.Net MVC 4 Web Application. After click on OK, select template as Web API&lt;/p&gt;
&lt;p&gt;&lt;span&gt;This will add a full functional Web API template Application into our main solution.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/7.PNG" alt="Solution 1" width="230" height="350"&gt;&lt;/p&gt;
&lt;p&gt;Right click on Application.API project in Solution Explorer and go to properties, than assign a port to be use by this service application ( In my case its 30000). Hit F5 and we are ready with a dummy data as below screen:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/8.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step2"&gt;Step 2: Prepare Application.DAL, Application.Repository and Application.Model Layers&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Check&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/library/bb399182.aspx"&gt;@MSDN&lt;/a&gt;&amp;nbsp;for more information on Entity Framework&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add Entity Data Model to&amp;nbsp;&lt;strong&gt;Application.DAL&lt;/strong&gt;&amp;nbsp;project. To do this select ADO.NET Entity Data Model from the Data Templates list, and name it as&amp;nbsp;&lt;strong&gt;AdventureWorks.edmx&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Choose&amp;nbsp;&lt;strong&gt;&amp;ldquo;Generate from Database&amp;rdquo;&lt;/strong&gt;&amp;nbsp;and provide the connection string to read the database schema. This will add AdventureWorks.edmx into current project. Right click on the blank space in Entity Model surface and click
 on properties (or alternate press Alt &amp;#43;Enter on keyboard). Now set its Code Generation Strategy as&amp;nbsp;&lt;strong&gt;None&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/10.PNG" alt="Solution 1" width="550" height="300"&gt;&lt;/p&gt;
&lt;p&gt;Now create POCO entities for AdventureWorks Data Model into&amp;nbsp;&lt;strong&gt;Application.Model&lt;/strong&gt;&amp;nbsp;Solution. Check this article to do this job for you on MSDN to use&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/gg558520"&gt;T4 Templates and the Entity
 Framework&lt;/a&gt;&lt;br&gt;
Then, create all required repositories under Application.Repositories.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/11.PNG" alt="Solution 1" width="250" height="500"&gt;&lt;/p&gt;
&lt;p&gt;To build solution, add reference of&amp;nbsp;&lt;strong&gt;Application.Model.dll&lt;/strong&gt;&amp;nbsp;to&amp;nbsp;&lt;strong&gt;Application.DAL.dll&lt;/strong&gt;&amp;nbsp;and&amp;nbsp;&lt;strong&gt;Application.Repository.dll&lt;/strong&gt;projects, and add reference of&amp;nbsp;&lt;strong&gt;Application.DAL.dll&lt;/strong&gt;&amp;nbsp;to&amp;nbsp;&lt;strong&gt;Application.Repository.dll&lt;/strong&gt;&amp;nbsp;project.
 (See below picture for reference)&lt;br&gt;
Before proceeding to next step (designing Application.Service and Application.API Layer), let us see what we have designed yet:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/12.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step3"&gt;Step 3: Add files to Application.Service Layer&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Before adding files to Service layer let us look at the Goals which we want to achieve.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Any user should be able to view products &lt;/li&gt;&lt;li&gt;Product would be filtered by Categories &lt;/li&gt;&lt;li&gt;User should be able to add products in cart &lt;/li&gt;&lt;li&gt;Only registered user will be able to submit cart &lt;/li&gt;&lt;li&gt;User should be able to register into system &lt;/li&gt;&lt;li&gt;User will get confirmation Invoice after generating order in system. &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To achieve the above mention Goals, we need to add three service classes to Application.Service as per below image&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/13.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/14.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;I am not going in deatils, as the implementation for each methods are clear and easy to understand.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step4"&gt;Step 4: Add files to Application.API Layer&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To make this Web API accessed from a broad range of clients like any browsers which use JavaScript or any windows/Mobile platform which supports .dll files, we need to add Controllers with base class as&amp;nbsp;&lt;strong&gt;ApiController&lt;/strong&gt;.&amp;nbsp;&lt;a href="http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api"&gt;More
 details here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;First, we remove the default controllers added by template (HomeController and ValuesController) and then add three new controllers as per below diagram:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/15.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;Again, nothing special in the implementation of these methods, they all jst push the data to service layer.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step5"&gt;Step 5: Integration of Dependency Injection with WebAPI using Autofac&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The implementation is very much straight forward and clear.&amp;nbsp;&lt;a href="http://alexmg.com/post/2012/03/08/Autofac-ASPNET-Web-API-%28Beta%29-Integration.aspx"&gt;Check Alex post here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;Solution Explorer, right-click the References node and click Manage NuGet Packages&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/16.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;It will open the below screen.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/17.PNG" alt="Solution 1" width="700" height="200"&gt;&lt;/p&gt;
&lt;p&gt;Click on install and it will add below three references in solution&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/18.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;Next, go to Global.asax.cs and create a method named as ResolveDependency()&lt;/p&gt;
&lt;pre id="pre0" lang="cs"&gt;             &lt;span&gt;protected&lt;/span&gt; &lt;span&gt;void&lt;/span&gt; ResolveDependancy()
                {
                    &lt;span&gt;var&lt;/span&gt; configuration = GlobalConfiguration.Configuration;
                    &lt;span&gt;var&lt;/span&gt; builder = &lt;span&gt;new&lt;/span&gt; ContainerBuilder();

                    &lt;span&gt;//&lt;/span&gt;&lt;span&gt; Configure the container with the integration implementations.
&lt;/span&gt;                    builder.ConfigureWebApi(configuration);

                    &lt;span&gt;//&lt;/span&gt;&lt;span&gt; Register API controllers using assembly scanning.
&lt;/span&gt;                    builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

                    builder.RegisterType&amp;lt;logservice&amp;gt;().As&amp;lt;ilogservice&amp;gt;().InstancePerLifetimeScope();
                    builder.RegisterType&amp;lt;unitofwork&amp;gt;().As&amp;lt;iunitofwork&amp;gt;().InstancePerDependency();
                    builder.RegisterType&amp;lt;databasefactory&amp;gt;().As&amp;lt;idatabasefactory&amp;gt;().InstancePerLifetimeScope();
                    builder.RegisterAssemblyTypes(&lt;span&gt;typeof&lt;/span&gt;(ProductService).Assembly)
                    .Where(t =&amp;gt; t.Name.EndsWith(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Service&amp;quot;&lt;/span&gt;))
                    .AsImplementedInterfaces().InstancePerDependency();
                    builder.RegisterAssemblyTypes(&lt;span&gt;typeof&lt;/span&gt;(CustomerRepository).Assembly)
                    .Where(t =&amp;gt; t.Name.EndsWith(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Repository&amp;quot;&lt;/span&gt;))
                    .AsImplementedInterfaces().InstancePerDependency();      

                    &lt;span&gt;var&lt;/span&gt; container = builder.Build();

                    &lt;span&gt;//&lt;/span&gt;&lt;span&gt; Set the dependency resolver implementation.
&lt;/span&gt;                    &lt;span&gt;var&lt;/span&gt; resolver = &lt;span&gt;new&lt;/span&gt; AutofacWebApiDependencyResolver(container);
                    configuration.ServiceResolver.SetResolver(resolver);
                }
            &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;idatabasefactory&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;databasefactory&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;iunitofwork&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;unitofwork&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;ilogservice&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;logservice&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Now we are ready to test our application. Hit F5 and check the browser with following url&amp;rsquo;s:&amp;nbsp;&lt;br&gt;
http://localhost:30000/api/products : will result all Product Categories&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/20.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;http://localhost:30000/api/products/2 : will result all Products with ProductcategoryID as 2&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/21.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;To check other methods, First we will add some Views in current solution.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step6"&gt;Step 6: Add View to solution&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Delete all default files and folders from Views Folder, and add three Html and their supportive Javascript File as. For this POC we will use html files, and some jquery libraries like:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;jquery.tmpl.js :&lt;/strong&gt;&amp;nbsp;to create template based screen, and&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;jquery.validationEngine.js :&lt;/strong&gt;&amp;nbsp;to validate form data&lt;/p&gt;
&lt;p&gt;Now the structure will looks like below picture :&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/22.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;For details code in html and JS file please look into the code. In next step I am going to resolve problems.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step7"&gt;Step 7: Resolve issues&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Before run the application Right Click on Products.htm and click on Set As start Page. Now hit F5&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/23.PNG" alt="Solution 1" width="700" height="300"&gt;&lt;/p&gt;
&lt;p&gt;It means, two WebAPI methods in ProductsController.cs are working perfectly. In JavaScript, on page load we are calling first method inside&amp;nbsp;&lt;strong&gt;product.js&lt;/strong&gt;&amp;nbsp;as:&lt;/p&gt;
&lt;pre id="pre1" lang="js"&gt;                    var productcategoriesAddress = &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;/api/products/&amp;quot;&lt;/span&gt;;
                    $(function () {
                        $(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;#tblRight'&lt;/span&gt;).hide();
                        $.getJSON(
                                productcategoriesAddress,
                                function (data) {
                                    var parents = jQuery.grep(data, function (a) { &lt;span&gt;return&lt;/span&gt; a.ParentProductCategoryID == null });
                                    var childs = jQuery.grep(data, function (a) { &lt;span&gt;return&lt;/span&gt; a.ParentProductCategoryID != null });
                                    $.&lt;span&gt;each&lt;/span&gt;(parents,
                                        function (index, &lt;span&gt;value&lt;/span&gt;) {
                                            var categorydata = [];
                                            var subCategory = &lt;span&gt;'&lt;/span&gt;&lt;span&gt;'&lt;/span&gt;;
                                            var subChild = jQuery.grep(childs, function (a) { &lt;span&gt;return&lt;/span&gt; a.ParentProductCategoryID == &lt;span&gt;value&lt;/span&gt;.ProductCategoryID });
                                            $.&lt;span&gt;each&lt;/span&gt;(subChild,
                                                function (index, item) {
                                                    var serviceURL = productcategoriesAddress &amp;#43; item.ProductCategoryID;
                                                    subCategory = subCategory &amp;#43; &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;  &amp;quot;&lt;/span&gt; &amp;#43; &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;lt;a href=&amp;quot;&lt;/span&gt;%20&amp;#43;%20serviceURL%20&amp;#43;%20&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt; class=&amp;quot;&lt;/span&gt;menuButton&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;gt;&amp;quot;&lt;/span&gt; &amp;#43; item.Name &amp;#43; &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;lt;/a&amp;gt;&amp;quot;&lt;/span&gt;;
                                                });
                                            categorydata.push({
                                                &lt;span&gt;'&lt;/span&gt;&lt;span&gt;ProductCategoryID'&lt;/span&gt;: &lt;span&gt;value&lt;/span&gt;.ProductCategoryID,
                                                &lt;span&gt;'&lt;/span&gt;&lt;span&gt;ParentCategory'&lt;/span&gt;: &lt;span&gt;value&lt;/span&gt;.Name,
                                                &lt;span&gt;'&lt;/span&gt;&lt;span&gt;ChildCategory'&lt;/span&gt;: subCategory
                                            });
                                            $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#categoryTemplate&amp;quot;&lt;/span&gt;).tmpl(categorydata).appendTo(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#categories&amp;quot;&lt;/span&gt;);
                                            $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#&amp;quot;&lt;/span&gt; &amp;#43; &lt;span&gt;value&lt;/span&gt;.Name).html(subCategory);
                                        });

                                        GetProducts(&lt;span&gt;1&lt;/span&gt;);
                                }
                            );
                &lt;/pre&gt;
&lt;p&gt;This call hits below method in ProductsController, and returns all Product Category to create the Upper Menu Part&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;pre id="pre2" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; IQueryable&amp;lt;productcategory&amp;gt; GetProductCategories()
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with null parameter&amp;quot;&lt;/span&gt;);
                        &lt;span&gt;return&lt;/span&gt; _productservice.GetProductCategories().AsQueryable&amp;lt;productcategory&amp;gt;();
                    }
                &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;productcategory&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;productcategory&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;In ProductService implementation is :&lt;/p&gt;
&lt;pre id="pre3" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; IQueryable&amp;lt;productcategory&amp;gt; GetProductCategories()
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with null parameter&amp;quot;&lt;/span&gt;);
                        &lt;span&gt;return&lt;/span&gt; _productservice.GetProductCategories().AsQueryable&amp;lt;productcategory&amp;gt;();
                    }
                &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;productcategory&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;productcategory&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;The second call is to fetch all products depends on selected category. In javascript&lt;/p&gt;
&lt;pre id="pre4" lang="js"&gt;                      function GetProducts(ProductCategoryID) {
                        var serviceURL = productcategoriesAddress &amp;#43; ProductCategoryID;
                        $(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;#categories li h1'&lt;/span&gt;).css(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;background'&lt;/span&gt;, &lt;span&gt;'&lt;/span&gt;&lt;span&gt;#736F6E'&lt;/span&gt;);
                        $(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;#mnu'&lt;/span&gt; &amp;#43; ProductCategoryID).css(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;background'&lt;/span&gt;, &lt;span&gt;'&lt;/span&gt;&lt;span&gt;#357EC7'&lt;/span&gt;);
                        $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#loader&amp;quot;&lt;/span&gt;).show();
                        $.ajax({
                            type: &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;GET&amp;quot;&lt;/span&gt;,
                            datatype: &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;json&amp;quot;&lt;/span&gt;,
                            url: serviceURL,
                            context: &lt;span&gt;this&lt;/span&gt;,
                            success: function (&lt;span&gt;value&lt;/span&gt;) {
                                $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#productData&amp;quot;&lt;/span&gt;).html(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;quot;&lt;/span&gt;);
                                $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#productTemplate&amp;quot;&lt;/span&gt;).tmpl(&lt;span&gt;value&lt;/span&gt;).appendTo(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#productData&amp;quot;&lt;/span&gt;);
                                $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#loader&amp;quot;&lt;/span&gt;).hide();
                            }
                        });
                        &lt;span&gt;return&lt;/span&gt; &lt;span&gt;false&lt;/span&gt;;
                    }
                &lt;/pre&gt;
&lt;p&gt;and in ProductsController it goes to&lt;/p&gt;
&lt;pre id="pre5" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; IQueryable&amp;lt;product&amp;gt; GetProductByProductCategoryID(&lt;span&gt;int&lt;/span&gt; id)
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with null parameter as : id : &amp;quot;&lt;/span&gt; &amp;#43; id);
                        &lt;span&gt;return&lt;/span&gt; _productservice.GetProductByProductCategoryID(id).AsQueryable&amp;lt;product&amp;gt;();
                    }

                &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;product&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;product&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;In ProductService implementation is :&lt;/p&gt;
&lt;pre id="pre6" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; IQueryable&amp;lt;product&amp;gt; GetProductByProductCategoryID(&lt;span&gt;int&lt;/span&gt; id)
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with null parameter as : id : &amp;quot;&lt;/span&gt; &amp;#43; id);
                        &lt;span&gt;return&lt;/span&gt; _productservice.GetProductByProductCategoryID(id).AsQueryable&amp;lt;product&amp;gt;();
                    }
                &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;product&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;product&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Next, let us try to add some products to Cart and Checkout cart&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/28.PNG" alt="Solution 1" width="400" height="300"&gt;&lt;/p&gt;
&lt;p&gt;On clicking on checkout It redirect to Checkout.htm page and asking for either Login using existing CustomerID or Register for a new Customer.&lt;br&gt;
Click on&amp;nbsp;&lt;strong&gt;Register&lt;/strong&gt;&amp;nbsp;link to create a new Customer.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/29.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;Submit form after clicking on Register button and see if Posting is working or not. Again its success!!!&lt;/p&gt;
&lt;p&gt;Now we will try to update records for AddressLine2, and Update is also working fine!!!&lt;/p&gt;
&lt;p&gt;In both scenario (Add or Update Customer) we are calling below method of CutomerControllers.cs&lt;/p&gt;
&lt;pre id="pre7" lang="cs"&gt;                     &lt;span&gt;public&lt;/span&gt; &lt;span&gt;int&lt;/span&gt; PostCustomer(CustomerDTO customer)
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with parameter as : customer: &amp;quot;&lt;/span&gt; &amp;#43; customer);
                        &lt;span&gt;return&lt;/span&gt; _customerService.SaveOrUpdateCustomer(customer);
                    }
                &lt;/pre&gt;
&lt;p&gt;In CustomerService implementation is :&lt;/p&gt;
&lt;pre id="pre8" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;int&lt;/span&gt; SaveOrUpdateCustomer(CustomerDTO customer)
                    {
                        &lt;span&gt;string&lt;/span&gt; passwordSalt = CreateSalt(&lt;span&gt;5&lt;/span&gt;);
                        &lt;span&gt;string&lt;/span&gt; pasword = CreatePasswordHash(customer.Password, passwordSalt);
                        Customer objCustomer;

                        &lt;span&gt;if&lt;/span&gt; (customer.CustomerID != &lt;span&gt;0&lt;/span&gt;)
                            objCustomer = _customerRepository.GetById(customer.CustomerID);
                        &lt;span&gt;else&lt;/span&gt;
                            objCustomer = &lt;span&gt;new&lt;/span&gt; Customer();

                        objCustomer.NameStyle = customer.NameStyle;
                        objCustomer.Title = customer.Title;
                        objCustomer.FirstName = customer.FirstName;
                        objCustomer.MiddleName = customer.MiddleName;
                        objCustomer.LastName = customer.LastName;
                        objCustomer.Suffix = customer.Suffix;
                        objCustomer.CompanyName = customer.CompanyName;
                        objCustomer.SalesPerson = customer.SalesPerson;
                        objCustomer.EmailAddress = customer.EmailAddress;
                        objCustomer.Phone = customer.Phone;
                        objCustomer.PasswordHash = pasword;
                        objCustomer.PasswordSalt = passwordSalt;
                        objCustomer.ModifiedDate = DateTime.Now;
                        objCustomer.rowguid = Guid.NewGuid();

                        &lt;span&gt;if&lt;/span&gt; (customer.CustomerID != &lt;span&gt;0&lt;/span&gt;)
                            _customerRepository.Update(objCustomer);
                        &lt;span&gt;else&lt;/span&gt;
                            _customerRepository.Add(objCustomer);

                        _unitOfWork.Commit();
                        SaveOrUpdateAddress(customer, objCustomer.CustomerID);
                        &lt;span&gt;return&lt;/span&gt; objCustomer.CustomerID;
                    }
                &lt;/pre&gt;
&lt;p&gt;Next, click on Submit Order Button, to make previously selected products as an Order and receive Order Invoice.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/33.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;!!!Hurray!!! Order is created in system and invoice is generated with a new Purchase Order. But, wait we got one BUG&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue 1:&lt;/strong&gt;&amp;nbsp;we have an issue with Date Format.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/34.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;According to,&amp;nbsp;&lt;a href="http://www.hanselman.com/blog/OnTheNightmareThatIsJSONDatesPlusJSONNETAndASPNETWebAPI.aspx"&gt;Scott Hanselman&amp;rsquo;s post&lt;/a&gt;&amp;nbsp;this is a bug and will resolve in next release of ASP.Net WebAPI. This issue is resolved using&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/02/18/using-json-net-with-asp-net-web-api.aspx"&gt;solution
 provided in Henrik's Blog&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/35.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue 2:&lt;/strong&gt;&amp;nbsp;Another issue was, when I try to Checkout Cart using the last created Customer. The error was:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/36.PNG" alt="Solution 1" width="700" height="300"&gt;&lt;/p&gt;
&lt;p&gt;After looking this error, first thought comes that we missed the method in CustomersController.cs, but the method was already there. Further investigation make it clear, that, the reason behind this error was name of this method as ValidateCustomer():&lt;/p&gt;
&lt;pre id="pre9" lang="cs"&gt;                     &lt;span&gt;public&lt;/span&gt; CustomerDTO ValidateCustomer(&lt;span&gt;int&lt;/span&gt; id, &lt;span&gt;string&lt;/span&gt; password)
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with parameter as : id and password: &amp;quot;&lt;/span&gt; &amp;#43; id &amp;#43; &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt; and &amp;quot;&lt;/span&gt; &amp;#43; password);
                        &lt;span&gt;return&lt;/span&gt; _customerService.ValidateCustomer(id, password);
                    }
                &lt;/pre&gt;
&lt;p&gt;In CustomerService implementation is :&lt;/p&gt;
&lt;pre id="pre10" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; CustomerDTO ValidateCustomer(&lt;span&gt;int&lt;/span&gt; id, &lt;span&gt;string&lt;/span&gt; password)
                    {
                        Customer objCustomer = _customerRepository.GetById(id);
                        &lt;span&gt;if&lt;/span&gt; (objCustomer == &lt;span&gt;null&lt;/span&gt;)
                            &lt;span&gt;return&lt;/span&gt; &lt;span&gt;null&lt;/span&gt;;
                        &lt;span&gt;string&lt;/span&gt; strPasswordHash = objCustomer.PasswordHash;
                        &lt;span&gt;string&lt;/span&gt; strPasswordSalt = strPasswordHash.Substring(strPasswordHash.Length - &lt;span&gt;8&lt;/span&gt;);
                        &lt;span&gt;string&lt;/span&gt; strPasword = CreatePasswordHash(password, strPasswordSalt);

                        &lt;span&gt;if&lt;/span&gt; (strPasword.Equals(strPasswordHash))
                            &lt;span&gt;return&lt;/span&gt; CreateCustomerDTO(objCustomer);
                        &lt;span&gt;else&lt;/span&gt;
                            &lt;span&gt;return&lt;/span&gt; &lt;span&gt;null&lt;/span&gt;;
                    }
                &lt;/pre&gt;
&lt;p&gt;By default the&amp;nbsp;&lt;strong&gt;route configuration&lt;/strong&gt;&amp;nbsp;of Asp.Net WebAPI follows RESTFUL conventions meaning that it will accept only the&amp;nbsp;&lt;strong&gt;Get, Post, Put and Delete&lt;/strong&gt;&amp;nbsp;action names. So when we send a GET request to http://localhost:30000/api/customers/ValidateCustomer/30135/test
 we are basically calling the Get(int id) action and passing id=30135 which obviously crashes because we don&amp;rsquo;t have any method starting with Get which accept Id as parameter. To resolve this issue I need to add a new route definition in&amp;nbsp;&lt;strong&gt;Global.asax&lt;/strong&gt;&amp;nbsp;file
 as:&lt;/p&gt;
&lt;pre id="pre11" lang="cs"&gt;                     routes.MapHttpRoute(
                           name: &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;ValidateCustomer&amp;quot;&lt;/span&gt;,
                           routeTemplate: &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;api/{controller}/{action}/{id}/{password}&amp;quot;&lt;/span&gt;,
                           defaults: &lt;span&gt;new&lt;/span&gt; { action = &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;get&amp;quot;&lt;/span&gt; }
                       );
                &lt;/pre&gt;
&lt;p&gt;Adding this line done the magic and Login functinality start waorking&amp;hellip;. :)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step8"&gt;Step 8: Deploy on IIS&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To deploy this API on IIS version 7.5, first, publish only&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;solution to a Folder.&lt;/p&gt;
&lt;p&gt;Next, open IIS Manager and create a new website and set path to Publish folder, and we are done with deployment.&lt;/p&gt;
&lt;p&gt;Now, check whether page is opening or not, in my case, initially I got below error, which is self-explanatory.&lt;br&gt;
The error comes because this application is running on Asp.Net Framework Version 2.0. So, we need to change it to Asp.Net Framework Version 4.0:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/40.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/41.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;To change the Asp.Net Framework from 2.0 to 4.0, follow below steps.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/42.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/43.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;That was not the only reason not to run application, because after made above change in Application pool next error was:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/44.PNG" alt="Solution 1" width="700" height="200"&gt;&lt;/p&gt;
&lt;p&gt;To resolve this error again go to Advance Settings of Application pool and change the identity to Local System from ApplicationPoolIdentity&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/45.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;After modify the Application pool to use Local System, Application starts working on browser... :)&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/46.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;Although IIS errors are depending on servers/Firewall/Network or system to system, so it is very difficult to assume that you will also get the same error as mine. Check these links which help me to resolve some of the IIS issues in
 my work environment.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en/wcf/thread/b990d3ea-3335-40a6-877f-7c295da67a85"&gt;HTTP Error 500.19&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/eu/wcf/thread/39571e42-aca7-469d-8c68-aa59c2da4fcc"&gt;Could Not Load Type &amp;lsquo;System.ServiceModel.Activation.HttpModule&amp;rsquo;&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/k6h9cz8h.aspx"&gt;ASP.NET IIS Registration Tool&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms732012.aspx"&gt;ServiceModel Registration Tool&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step9"&gt;Step 9: Cross Domain Support&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The idea behind the Cross Domain Support comes when I try to remove all HTML pages from&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;solution and created a new Empty Web Application (Adventure.Website) which includes only&amp;nbsp;&lt;strong&gt;.html, .Js and .css&lt;/strong&gt;&amp;nbsp;files
 along with images. The structure for this application is as per below image:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/47.PNG" alt="Solution 1" width="300" height="500"&gt;&lt;/p&gt;
&lt;p&gt;Point all URL address to deployed code on IIS, after build and run application, output was null.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/48.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;To resolve this issue I would like to give my special thanks to Carlos&amp;rsquo; blog on MSDN&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2012/02/20/implementing-cors-support-in-asp-net-web-apis.aspx"&gt;Implementing CORS support in ASP.NET Web
 APIs&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;blockquote&gt;
&lt;div&gt;Quote:&lt;/div&gt;
&amp;ldquo;By default, a web page cannot make calls to services (APIs) on a domain other than the one where the page came from. This is a security measure against a group of cross-site forgery attacks in which browsing to a bad site could potentially use the browser
 cookies to get data from a good site which the user had previously logged on (think your bank). There are many situations, however, where getting data from different sites is a perfectly valid scenario, such as mash-up applications which need data from different
 sources.&amp;rdquo;&lt;/blockquote&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;That's it !!! Hope you enjoy this article. I am not an expert, and also I have not followed the entire industry standard at the time of writing this article (time factor).&lt;/p&gt;
&lt;p&gt;All&amp;nbsp;&lt;strong&gt;comment/Vote&lt;/strong&gt;&amp;nbsp;are more than welcome&amp;hellip;. :), whenever, I get time, will try to modify this solution. You can also join/contribute to this project on&amp;nbsp;&lt;a href="http://pocwebapi.codeplex.com/"&gt;CodePlex&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Thank's for your time.&lt;/p&gt;
&lt;p&gt;Anand&lt;/p&gt;
&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>anandranjanpandey</author><pubDate>Thu, 22 Mar 2012 05:55:08 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Documentation 20120322055508A</guid></item><item><title>Updated Wiki: Documentation</title><link>http://pocwebapi.codeplex.com/documentation?version=3</link><description>&lt;div class="wikidoc"&gt;
&lt;h2&gt;&lt;strong&gt;Introduction&amp;nbsp;&lt;/strong&gt;&amp;nbsp;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The purpose of this article is to create a&lt;strong&gt;&amp;nbsp;proof of concept&amp;nbsp;&lt;/strong&gt;to demonstrate the feasibility of&amp;nbsp;&lt;a href="http://www.asp.net/web-api"&gt;ASP.NET WebAPI&lt;/a&gt;&amp;nbsp;Beta version.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Prerequisite:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://msftdbprodsamples.codeplex.com/"&gt;AdventureWorksLT2008R2&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://www.asp.net/web-api"&gt;ASP.Net WebAPI&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://code.google.com/p/autofac/downloads/list"&gt;Autofac for Dependency Injection&lt;/a&gt;&amp;nbsp;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://logging.apache.org/log4net/download.html"&gt;Log4Net&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://www.microsoft.com/download/en/details.aspx?displaylang=en&amp;id=8363"&gt;EntityFramework 4.1&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="https://github.com/jquery/jquery-tmpl"&gt;jQuery Templates plugin (jquery-tmpl)&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Goals to achieve:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Any user should be able to view products &lt;/li&gt;&lt;li&gt;Product would be filtered by Categories &lt;/li&gt;&lt;li&gt;User should be able to add products in cart &lt;/li&gt;&lt;li&gt;Only registered user will be able to submit cart &lt;/li&gt;&lt;li&gt;User should be able to register into system &lt;/li&gt;&lt;li&gt;User will get confirmation Invoice after generating order in system. &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Architecture for this POC&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I am not following any specific Architecture Pattern, although while designing this POC, I&amp;nbsp;&lt;strong&gt;try to follow&lt;/strong&gt;&amp;nbsp;some of the key design principles like:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Separation_of_concerns"&gt;Separation of concerns&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Abstraction_(computer_science)"&gt;Abstraction&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself"&gt;Don't repeat yourself&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/KISS_principle"&gt;KISS principle&lt;/a&gt; &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;span&gt;Again I am repeating my word&amp;nbsp;&lt;strong&gt;try to follow&amp;hellip;.. :)&lt;/strong&gt;. So, all comments/suggestions are more than welcome to discuss and I am always ready to adopt changes, or you can do it yourself by join&amp;nbsp;&lt;a href="http://pocwebapi.codeplex.com/"&gt;@CodePlex&lt;/a&gt;.
 The initial Skeleton for this application is as per below diagram:&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/1.PNG" alt="Architecture" width="650" height="500"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Step-by-Step&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="step1"&gt;Step 1: Create a basic Application Structure Layout&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="step2"&gt;Step 2: Create the Data Access Layer&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="step3"&gt;Step 3: Create the Service Layer&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="step4"&gt;Step 4: Create the API Layer&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="step5"&gt;Step 5: Integration of Dependency Injection using Autofac&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="step6"&gt;Step 6: Add Views to solution&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="step7"&gt;Step 7: Unit test and resolve issues&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="step8"&gt;Step 8: Deploy application on IIS&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="step9"&gt;Step 9: Provide Cross Domain Support&lt;/a&gt; &lt;/li&gt;&lt;/ul&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step1"&gt;Step 1: Create a basic Application Structure Layout&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;For more information on ASP.NET WebAPI, watch Videos and Tutorials&amp;nbsp;&lt;a href="http://www.asp.net/web-api"&gt;here&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add a blank Solution named as&amp;nbsp;&lt;strong&gt;Application&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add a new Project (Class Library) named as&amp;nbsp;&lt;strong&gt;Application.DAL&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Repeat above process and create four more Class Library projects named as &amp;ndash;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Application.Model&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Repository&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Common&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Service&lt;/strong&gt; &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;span&gt;Now, application will look like below screen-shot&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/4.PNG" alt="Solution 1" width="250" height="350"&gt;&lt;/p&gt;
&lt;p&gt;Next, add a new Project named as&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;as ASP.Net MVC 4 Web Application. After click on OK, select template as Web API&lt;/p&gt;
&lt;p&gt;&lt;span&gt;This will add a full functional Web API template Application into our main solution.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/7.PNG" alt="Solution 1" width="230" height="350"&gt;&lt;/p&gt;
&lt;p&gt;Right click on Application.API project in Solution Explorer and go to properties, than assign a port to be use by this service application ( In my case its 30000). Hit F5 and we are ready with a dummy data as below screen:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/8.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step2"&gt;Step 2: Prepare Application.DAL, Application.Repository and Application.Model Layers&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Check&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/library/bb399182.aspx"&gt;@MSDN&lt;/a&gt;&amp;nbsp;for more information on Entity Framework&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add Entity Data Model to&amp;nbsp;&lt;strong&gt;Application.DAL&lt;/strong&gt;&amp;nbsp;project. To do this select ADO.NET Entity Data Model from the Data Templates list, and name it as&amp;nbsp;&lt;strong&gt;AdventureWorks.edmx&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Choose&amp;nbsp;&lt;strong&gt;&amp;ldquo;Generate from Database&amp;rdquo;&lt;/strong&gt;&amp;nbsp;and provide the connection string to read the database schema. This will add AdventureWorks.edmx into current project. Right click on the blank space in Entity Model surface and click
 on properties (or alternate press Alt &amp;#43;Enter on keyboard). Now set its Code Generation Strategy as&amp;nbsp;&lt;strong&gt;None&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/10.PNG" alt="Solution 1" width="550" height="300"&gt;&lt;/p&gt;
&lt;p&gt;Now create POCO entities for AdventureWorks Data Model into&amp;nbsp;&lt;strong&gt;Application.Model&lt;/strong&gt;&amp;nbsp;Solution. Check this article to do this job for you on MSDN to use&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/gg558520"&gt;T4 Templates and the Entity
 Framework&lt;/a&gt;&lt;br&gt;
Then, create all required repositories under Application.Repositories.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/11.PNG" alt="Solution 1" width="250" height="500"&gt;&lt;/p&gt;
&lt;p&gt;To build solution, add reference of&amp;nbsp;&lt;strong&gt;Application.Model.dll&lt;/strong&gt;&amp;nbsp;to&amp;nbsp;&lt;strong&gt;Application.DAL.dll&lt;/strong&gt;&amp;nbsp;and&amp;nbsp;&lt;strong&gt;Application.Repository.dll&lt;/strong&gt;projects, and add reference of&amp;nbsp;&lt;strong&gt;Application.DAL.dll&lt;/strong&gt;&amp;nbsp;to&amp;nbsp;&lt;strong&gt;Application.Repository.dll&lt;/strong&gt;&amp;nbsp;project.
 (See below picture for reference)&lt;br&gt;
Before proceeding to next step (designing Application.Service and Application.API Layer), let us see what we have designed yet:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/12.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step3"&gt;Step 3: Add files to Application.Service Layer&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Before adding files to Service layer let us look at the Goals which we want to achieve.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Any user should be able to view products &lt;/li&gt;&lt;li&gt;Product would be filtered by Categories &lt;/li&gt;&lt;li&gt;User should be able to add products in cart &lt;/li&gt;&lt;li&gt;Only registered user will be able to submit cart &lt;/li&gt;&lt;li&gt;User should be able to register into system &lt;/li&gt;&lt;li&gt;User will get confirmation Invoice after generating order in system. &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To achieve the above mention Goals, we need to add three service classes to Application.Service as per below image&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/13.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/14.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;I am not going in deatils, as the implementation for each methods are clear and easy to understand.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step4"&gt;Step 4: Add files to Application.API Layer&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To make this Web API accessed from a broad range of clients like any browsers which use JavaScript or any windows/Mobile platform which supports .dll files, we need to add Controllers with base class as&amp;nbsp;&lt;strong&gt;ApiController&lt;/strong&gt;.&amp;nbsp;&lt;a href="http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api"&gt;More
 details here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;First, we remove the default controllers added by template (HomeController and ValuesController) and then add three new controllers as per below diagram:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/15.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;Again, nothing special in the implementation of these methods, they all jst push the data to service layer.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step5"&gt;Step 5: Integration of Dependency Injection with WebAPI using Autofac&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The implementation is very much straight forward and clear.&amp;nbsp;&lt;a href="http://alexmg.com/post/2012/03/08/Autofac-ASPNET-Web-API-%28Beta%29-Integration.aspx"&gt;Check Alex post here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;Solution Explorer, right-click the References node and click Manage NuGet Packages&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/16.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;It will open the below screen.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/17.PNG" alt="Solution 1" width="700" height="200"&gt;&lt;/p&gt;
&lt;p&gt;Click on install and it will add below three references in solution&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/18.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;Next, go to Global.asax.cs and create a method named as ResolveDependency()&lt;/p&gt;
&lt;pre id="pre0" lang="cs"&gt;             &lt;span&gt;protected&lt;/span&gt; &lt;span&gt;void&lt;/span&gt; ResolveDependancy()
                {
                    &lt;span&gt;var&lt;/span&gt; configuration = GlobalConfiguration.Configuration;
                    &lt;span&gt;var&lt;/span&gt; builder = &lt;span&gt;new&lt;/span&gt; ContainerBuilder();

                    &lt;span&gt;//&lt;/span&gt;&lt;span&gt; Configure the container with the integration implementations.
&lt;/span&gt;                    builder.ConfigureWebApi(configuration);

                    &lt;span&gt;//&lt;/span&gt;&lt;span&gt; Register API controllers using assembly scanning.
&lt;/span&gt;                    builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

                    builder.RegisterType&amp;lt;logservice&amp;gt;().As&amp;lt;ilogservice&amp;gt;().InstancePerLifetimeScope();
                    builder.RegisterType&amp;lt;unitofwork&amp;gt;().As&amp;lt;iunitofwork&amp;gt;().InstancePerDependency();
                    builder.RegisterType&amp;lt;databasefactory&amp;gt;().As&amp;lt;idatabasefactory&amp;gt;().InstancePerLifetimeScope();
                    builder.RegisterAssemblyTypes(&lt;span&gt;typeof&lt;/span&gt;(ProductService).Assembly)
                    .Where(t =&amp;gt; t.Name.EndsWith(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Service&amp;quot;&lt;/span&gt;))
                    .AsImplementedInterfaces().InstancePerDependency();
                    builder.RegisterAssemblyTypes(&lt;span&gt;typeof&lt;/span&gt;(CustomerRepository).Assembly)
                    .Where(t =&amp;gt; t.Name.EndsWith(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Repository&amp;quot;&lt;/span&gt;))
                    .AsImplementedInterfaces().InstancePerDependency();      

                    &lt;span&gt;var&lt;/span&gt; container = builder.Build();

                    &lt;span&gt;//&lt;/span&gt;&lt;span&gt; Set the dependency resolver implementation.
&lt;/span&gt;                    &lt;span&gt;var&lt;/span&gt; resolver = &lt;span&gt;new&lt;/span&gt; AutofacWebApiDependencyResolver(container);
                    configuration.ServiceResolver.SetResolver(resolver);
                }
            &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;idatabasefactory&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;databasefactory&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;iunitofwork&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;unitofwork&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;ilogservice&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;logservice&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Now we are ready to test our application. Hit F5 and check the browser with following url&amp;rsquo;s:&amp;nbsp;&lt;br&gt;
http://localhost:30000/api/products : will result all Product Categories&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/20.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;http://localhost:30000/api/products/2 : will result all Products with ProductcategoryID as 2&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/21.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;To check other methods, First we will add some Views in current solution.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step6"&gt;Step 6: Add View to solution&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Delete all default files and folders from Views Folder, and add three Html and their supportive Javascript File as. For this POC we will use html files, and some jquery libraries like:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;jquery.tmpl.js :&lt;/strong&gt;&amp;nbsp;to create template based screen, and&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;jquery.validationEngine.js :&lt;/strong&gt;&amp;nbsp;to validate form data&lt;/p&gt;
&lt;p&gt;Now the structure will looks like below picture :&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/22.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;For details code in html and JS file please look into the code. In next step I am going to resolve problems.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step7"&gt;Step 7: Resolve issues&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Before run the application Right Click on Products.htm and click on Set As start Page. Now hit F5&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/23.PNG" alt="Solution 1" width="700" height="300"&gt;&lt;/p&gt;
&lt;p&gt;It means, two WebAPI methods in ProductsController.cs are working perfectly. In JavaScript, on page load we are calling first method inside&amp;nbsp;&lt;strong&gt;product.js&lt;/strong&gt;&amp;nbsp;as:&lt;/p&gt;
&lt;pre id="pre1" lang="js"&gt;                    var productcategoriesAddress = &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;/api/products/&amp;quot;&lt;/span&gt;;
                    $(function () {
                        $(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;#tblRight'&lt;/span&gt;).hide();
                        $.getJSON(
                                productcategoriesAddress,
                                function (data) {
                                    var parents = jQuery.grep(data, function (a) { &lt;span&gt;return&lt;/span&gt; a.ParentProductCategoryID == null });
                                    var childs = jQuery.grep(data, function (a) { &lt;span&gt;return&lt;/span&gt; a.ParentProductCategoryID != null });
                                    $.&lt;span&gt;each&lt;/span&gt;(parents,
                                        function (index, &lt;span&gt;value&lt;/span&gt;) {
                                            var categorydata = [];
                                            var subCategory = &lt;span&gt;'&lt;/span&gt;&lt;span&gt;'&lt;/span&gt;;
                                            var subChild = jQuery.grep(childs, function (a) { &lt;span&gt;return&lt;/span&gt; a.ParentProductCategoryID == &lt;span&gt;value&lt;/span&gt;.ProductCategoryID });
                                            $.&lt;span&gt;each&lt;/span&gt;(subChild,
                                                function (index, item) {
                                                    var serviceURL = productcategoriesAddress &amp;#43; item.ProductCategoryID;
                                                    subCategory = subCategory &amp;#43; &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;  &amp;quot;&lt;/span&gt; &amp;#43; &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;lt;a href=&amp;quot;&lt;/span&gt;%20&amp;#43;%20serviceURL%20&amp;#43;%20&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt; class=&amp;quot;&lt;/span&gt;menuButton&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;gt;&amp;quot;&lt;/span&gt; &amp;#43; item.Name &amp;#43; &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;lt;/a&amp;gt;&amp;quot;&lt;/span&gt;;
                                                });
                                            categorydata.push({
                                                &lt;span&gt;'&lt;/span&gt;&lt;span&gt;ProductCategoryID'&lt;/span&gt;: &lt;span&gt;value&lt;/span&gt;.ProductCategoryID,
                                                &lt;span&gt;'&lt;/span&gt;&lt;span&gt;ParentCategory'&lt;/span&gt;: &lt;span&gt;value&lt;/span&gt;.Name,
                                                &lt;span&gt;'&lt;/span&gt;&lt;span&gt;ChildCategory'&lt;/span&gt;: subCategory
                                            });
                                            $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#categoryTemplate&amp;quot;&lt;/span&gt;).tmpl(categorydata).appendTo(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#categories&amp;quot;&lt;/span&gt;);
                                            $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#&amp;quot;&lt;/span&gt; &amp;#43; &lt;span&gt;value&lt;/span&gt;.Name).html(subCategory);
                                        });

                                        GetProducts(&lt;span&gt;1&lt;/span&gt;);
                                }
                            );
                &lt;/pre&gt;
&lt;p&gt;This call hits below method in ProductsController, and returns all Product Category to create the Upper Menu Part&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;pre id="pre2" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; IQueryable&amp;lt;productcategory&amp;gt; GetProductCategories()
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with null parameter&amp;quot;&lt;/span&gt;);
                        &lt;span&gt;return&lt;/span&gt; _productservice.GetProductCategories().AsQueryable&amp;lt;productcategory&amp;gt;();
                    }
                &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;productcategory&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;productcategory&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;In ProductService implementation is :&lt;/p&gt;
&lt;pre id="pre3" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; IQueryable&amp;lt;productcategory&amp;gt; GetProductCategories()
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with null parameter&amp;quot;&lt;/span&gt;);
                        &lt;span&gt;return&lt;/span&gt; _productservice.GetProductCategories().AsQueryable&amp;lt;productcategory&amp;gt;();
                    }
                &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;productcategory&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;productcategory&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;The second call is to fetch all products depends on selected category. In javascript&lt;/p&gt;
&lt;pre id="pre4" lang="js"&gt;                      function GetProducts(ProductCategoryID) {
                        var serviceURL = productcategoriesAddress &amp;#43; ProductCategoryID;
                        $(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;#categories li h1'&lt;/span&gt;).css(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;background'&lt;/span&gt;, &lt;span&gt;'&lt;/span&gt;&lt;span&gt;#736F6E'&lt;/span&gt;);
                        $(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;#mnu'&lt;/span&gt; &amp;#43; ProductCategoryID).css(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;background'&lt;/span&gt;, &lt;span&gt;'&lt;/span&gt;&lt;span&gt;#357EC7'&lt;/span&gt;);
                        $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#loader&amp;quot;&lt;/span&gt;).show();
                        $.ajax({
                            type: &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;GET&amp;quot;&lt;/span&gt;,
                            datatype: &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;json&amp;quot;&lt;/span&gt;,
                            url: serviceURL,
                            context: &lt;span&gt;this&lt;/span&gt;,
                            success: function (&lt;span&gt;value&lt;/span&gt;) {
                                $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#productData&amp;quot;&lt;/span&gt;).html(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;quot;&lt;/span&gt;);
                                $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#productTemplate&amp;quot;&lt;/span&gt;).tmpl(&lt;span&gt;value&lt;/span&gt;).appendTo(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#productData&amp;quot;&lt;/span&gt;);
                                $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#loader&amp;quot;&lt;/span&gt;).hide();
                            }
                        });
                        &lt;span&gt;return&lt;/span&gt; &lt;span&gt;false&lt;/span&gt;;
                    }
                &lt;/pre&gt;
&lt;p&gt;and in ProductsController it goes to&lt;/p&gt;
&lt;pre id="pre5" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; IQueryable&amp;lt;product&amp;gt; GetProductByProductCategoryID(&lt;span&gt;int&lt;/span&gt; id)
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with null parameter as : id : &amp;quot;&lt;/span&gt; &amp;#43; id);
                        &lt;span&gt;return&lt;/span&gt; _productservice.GetProductByProductCategoryID(id).AsQueryable&amp;lt;product&amp;gt;();
                    }

                &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;product&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;product&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;In ProductService implementation is :&lt;/p&gt;
&lt;pre id="pre6" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; IQueryable&amp;lt;product&amp;gt; GetProductByProductCategoryID(&lt;span&gt;int&lt;/span&gt; id)
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with null parameter as : id : &amp;quot;&lt;/span&gt; &amp;#43; id);
                        &lt;span&gt;return&lt;/span&gt; _productservice.GetProductByProductCategoryID(id).AsQueryable&amp;lt;product&amp;gt;();
                    }
                &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;product&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;product&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Next, let us try to add some products to Cart and Checkout cart&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/28.PNG" alt="Solution 1" width="400" height="300"&gt;&lt;/p&gt;
&lt;p&gt;On clicking on checkout It redirect to Checkout.htm page and asking for either Login using existing CustomerID or Register for a new Customer.&lt;br&gt;
Click on&amp;nbsp;&lt;strong&gt;Register&lt;/strong&gt;&amp;nbsp;link to create a new Customer.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/29.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;Submit form after clicking on Register button and see if Posting is working or not. Again its success!!!&lt;/p&gt;
&lt;p&gt;Now we will try to update records for AddressLine2, and Update is also working fine!!!&lt;/p&gt;
&lt;p&gt;In both scenario (Add or Update Customer) we are calling below method of CutomerControllers.cs&lt;/p&gt;
&lt;pre id="pre7" lang="cs"&gt;                     &lt;span&gt;public&lt;/span&gt; &lt;span&gt;int&lt;/span&gt; PostCustomer(CustomerDTO customer)
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with parameter as : customer: &amp;quot;&lt;/span&gt; &amp;#43; customer);
                        &lt;span&gt;return&lt;/span&gt; _customerService.SaveOrUpdateCustomer(customer);
                    }
                &lt;/pre&gt;
&lt;p&gt;In CustomerService implementation is :&lt;/p&gt;
&lt;pre id="pre8" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;int&lt;/span&gt; SaveOrUpdateCustomer(CustomerDTO customer)
                    {
                        &lt;span&gt;string&lt;/span&gt; passwordSalt = CreateSalt(&lt;span&gt;5&lt;/span&gt;);
                        &lt;span&gt;string&lt;/span&gt; pasword = CreatePasswordHash(customer.Password, passwordSalt);
                        Customer objCustomer;

                        &lt;span&gt;if&lt;/span&gt; (customer.CustomerID != &lt;span&gt;0&lt;/span&gt;)
                            objCustomer = _customerRepository.GetById(customer.CustomerID);
                        &lt;span&gt;else&lt;/span&gt;
                            objCustomer = &lt;span&gt;new&lt;/span&gt; Customer();

                        objCustomer.NameStyle = customer.NameStyle;
                        objCustomer.Title = customer.Title;
                        objCustomer.FirstName = customer.FirstName;
                        objCustomer.MiddleName = customer.MiddleName;
                        objCustomer.LastName = customer.LastName;
                        objCustomer.Suffix = customer.Suffix;
                        objCustomer.CompanyName = customer.CompanyName;
                        objCustomer.SalesPerson = customer.SalesPerson;
                        objCustomer.EmailAddress = customer.EmailAddress;
                        objCustomer.Phone = customer.Phone;
                        objCustomer.PasswordHash = pasword;
                        objCustomer.PasswordSalt = passwordSalt;
                        objCustomer.ModifiedDate = DateTime.Now;
                        objCustomer.rowguid = Guid.NewGuid();

                        &lt;span&gt;if&lt;/span&gt; (customer.CustomerID != &lt;span&gt;0&lt;/span&gt;)
                            _customerRepository.Update(objCustomer);
                        &lt;span&gt;else&lt;/span&gt;
                            _customerRepository.Add(objCustomer);

                        _unitOfWork.Commit();
                        SaveOrUpdateAddress(customer, objCustomer.CustomerID);
                        &lt;span&gt;return&lt;/span&gt; objCustomer.CustomerID;
                    }
                &lt;/pre&gt;
&lt;p&gt;Next, click on Submit Order Button, to make previously selected products as an Order and receive Order Invoice.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/33.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;!!!Hurray!!! Order is created in system and invoice is generated with a new Purchase Order. But, wait we got one BUG&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue 1:&lt;/strong&gt;&amp;nbsp;we have an issue with Date Format.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/34.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;According to,&amp;nbsp;&lt;a href="http://www.hanselman.com/blog/OnTheNightmareThatIsJSONDatesPlusJSONNETAndASPNETWebAPI.aspx"&gt;Scott Hanselman&amp;rsquo;s post&lt;/a&gt;&amp;nbsp;this is a bug and will resolve in next release of ASP.Net WebAPI. This issue is resolved using&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/02/18/using-json-net-with-asp-net-web-api.aspx"&gt;solution
 provided in Henrik's Blog&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/35.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue 2:&lt;/strong&gt;&amp;nbsp;Another issue was, when I try to Checkout Cart using the last created Customer. The error was:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/36.PNG" alt="Solution 1" width="700" height="300"&gt;&lt;/p&gt;
&lt;p&gt;After looking this error, first thought comes that we missed the method in CustomersController.cs, but the method was already there. Further investigation make it clear, that, the reason behind this error was name of this method as ValidateCustomer():&lt;/p&gt;
&lt;pre id="pre9" lang="cs"&gt;                     &lt;span&gt;public&lt;/span&gt; CustomerDTO ValidateCustomer(&lt;span&gt;int&lt;/span&gt; id, &lt;span&gt;string&lt;/span&gt; password)
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with parameter as : id and password: &amp;quot;&lt;/span&gt; &amp;#43; id &amp;#43; &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt; and &amp;quot;&lt;/span&gt; &amp;#43; password);
                        &lt;span&gt;return&lt;/span&gt; _customerService.ValidateCustomer(id, password);
                    }
                &lt;/pre&gt;
&lt;p&gt;In CustomerService implementation is :&lt;/p&gt;
&lt;pre id="pre10" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; CustomerDTO ValidateCustomer(&lt;span&gt;int&lt;/span&gt; id, &lt;span&gt;string&lt;/span&gt; password)
                    {
                        Customer objCustomer = _customerRepository.GetById(id);
                        &lt;span&gt;if&lt;/span&gt; (objCustomer == &lt;span&gt;null&lt;/span&gt;)
                            &lt;span&gt;return&lt;/span&gt; &lt;span&gt;null&lt;/span&gt;;
                        &lt;span&gt;string&lt;/span&gt; strPasswordHash = objCustomer.PasswordHash;
                        &lt;span&gt;string&lt;/span&gt; strPasswordSalt = strPasswordHash.Substring(strPasswordHash.Length - &lt;span&gt;8&lt;/span&gt;);
                        &lt;span&gt;string&lt;/span&gt; strPasword = CreatePasswordHash(password, strPasswordSalt);

                        &lt;span&gt;if&lt;/span&gt; (strPasword.Equals(strPasswordHash))
                            &lt;span&gt;return&lt;/span&gt; CreateCustomerDTO(objCustomer);
                        &lt;span&gt;else&lt;/span&gt;
                            &lt;span&gt;return&lt;/span&gt; &lt;span&gt;null&lt;/span&gt;;
                    }
                &lt;/pre&gt;
&lt;p&gt;By default the&amp;nbsp;&lt;strong&gt;route configuration&lt;/strong&gt;&amp;nbsp;of Asp.Net WebAPI follows RESTFUL conventions meaning that it will accept only the&amp;nbsp;&lt;strong&gt;Get, Post, Put and Delete&lt;/strong&gt;&amp;nbsp;action names. So when we send a GET request to http://localhost:30000/api/customers/ValidateCustomer/30135/test
 we are basically calling the Get(int id) action and passing id=30135 which obviously crashes because we don&amp;rsquo;t have any method starting with Get which accept Id as parameter. To resolve this issue I need to add a new route definition in&amp;nbsp;&lt;strong&gt;Global.asax&lt;/strong&gt;&amp;nbsp;file
 as:&lt;/p&gt;
&lt;pre id="pre11" lang="cs"&gt;                     routes.MapHttpRoute(
                           name: &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;ValidateCustomer&amp;quot;&lt;/span&gt;,
                           routeTemplate: &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;api/{controller}/{action}/{id}/{password}&amp;quot;&lt;/span&gt;,
                           defaults: &lt;span&gt;new&lt;/span&gt; { action = &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;get&amp;quot;&lt;/span&gt; }
                       );
                &lt;/pre&gt;
&lt;p&gt;Adding this line done the magic and Login functinality start waorking&amp;hellip;. :)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step8"&gt;Step 8: Deploy on IIS&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To deploy this API on IIS version 7.5, first, publish only&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;solution to a Folder.&lt;/p&gt;
&lt;p&gt;Next, open IIS Manager and create a new website and set path to Publish folder, and we are done with deployment.&lt;/p&gt;
&lt;p&gt;Now, check whether page is opening or not, in my case, initially I got below error, which is self-explanatory.&lt;br&gt;
The error comes because this application is running on Asp.Net Framework Version 2.0. So, we need to change it to Asp.Net Framework Version 4.0:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/40.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/41.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;To change the Asp.Net Framework from 2.0 to 4.0, follow below steps.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/42.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/43.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;That was not the only reason not to run application, because after made above change in Application pool next error was:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/44.PNG" alt="Solution 1" width="700" height="200"&gt;&lt;/p&gt;
&lt;p&gt;To resolve this error again go to Advance Settings of Application pool and change the identity to Local System from ApplicationPoolIdentity&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/45.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;After modify the Application pool to use Local System, Application starts working on browser... :)&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/46.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;Although IIS errors are depending on servers/Firewall/Network or system to system, so it is very difficult to assume that you will also get the same error as mine. Check these links which help me to resolve some of the IIS issues in
 my work environment.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en/wcf/thread/b990d3ea-3335-40a6-877f-7c295da67a85"&gt;HTTP Error 500.19&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/eu/wcf/thread/39571e42-aca7-469d-8c68-aa59c2da4fcc"&gt;Could Not Load Type &amp;lsquo;System.ServiceModel.Activation.HttpModule&amp;rsquo;&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/k6h9cz8h.aspx"&gt;ASP.NET IIS Registration Tool&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms732012.aspx"&gt;ServiceModel Registration Tool&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step9"&gt;Step 9: Cross Domain Support&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The idea behind the Cross Domain Support comes when I try to remove all HTML pages from&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;solution and created a new Empty Web Application (Adventure.Website) which includes only&amp;nbsp;&lt;strong&gt;.html, .Js and .css&lt;/strong&gt;&amp;nbsp;files
 along with images. The structure for this application is as per below image:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/47.PNG" alt="Solution 1" width="300" height="500"&gt;&lt;/p&gt;
&lt;p&gt;Point all URL address to deployed code on IIS, after build and run application, output was null.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/48.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;To resolve this issue I would like to give my special thanks to Carlos&amp;rsquo; blog on MSDN&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2012/02/20/implementing-cors-support-in-asp-net-web-apis.aspx"&gt;Implementing CORS support in ASP.NET Web
 APIs&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;blockquote&gt;
&lt;div&gt;Quote:&lt;/div&gt;
&amp;ldquo;By default, a web page cannot make calls to services (APIs) on a domain other than the one where the page came from. This is a security measure against a group of cross-site forgery attacks in which browsing to a bad site could potentially use the browser
 cookies to get data from a good site which the user had previously logged on (think your bank). There are many situations, however, where getting data from different sites is a perfectly valid scenario, such as mash-up applications which need data from different
 sources.&amp;rdquo;&lt;/blockquote&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;That's it !!! Hope you enjoy this article. I am not an expert, and also I have not followed the entire industry standard at the time of writing this article (time factor).&lt;/p&gt;
&lt;p&gt;All&amp;nbsp;&lt;strong&gt;comment/Vote&lt;/strong&gt;&amp;nbsp;are more than welcome&amp;hellip;. :), whenever, I get time, will try to modify this solution. You can also join/contribute to this project on&amp;nbsp;&lt;a href="http://pocwebapi.codeplex.com/"&gt;CodePlex&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Thank's for your time.&lt;/p&gt;
&lt;p&gt;Anand&lt;/p&gt;
&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>anandranjanpandey</author><pubDate>Thu, 22 Mar 2012 05:54:16 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Documentation 20120322055416A</guid></item><item><title>Updated Wiki: Home</title><link>http://pocwebapi.codeplex.com/wikipage?version=6</link><description>&lt;div class="wikidoc"&gt;
&lt;h2&gt;&lt;strong&gt;Introduction&amp;nbsp;&lt;/strong&gt;&amp;nbsp;&lt;/h2&gt;
&lt;p&gt;The purpose of this article is to create a&lt;strong&gt;&amp;nbsp;proof of concept&amp;nbsp;&lt;/strong&gt;to demonstrate the feasibility of&amp;nbsp;&lt;a href="http://www.asp.net/web-api"&gt;ASP.NET WebAPI&lt;/a&gt;&amp;nbsp;Beta version.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Prerequisite:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://msftdbprodsamples.codeplex.com/"&gt;AdventureWorksLT2008R2&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://www.asp.net/web-api"&gt;ASP.Net WebAPI&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://code.google.com/p/autofac/downloads/list"&gt;Autofac for Dependency Injection&lt;/a&gt;&amp;nbsp;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://logging.apache.org/log4net/download.html"&gt;Log4Net&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://www.microsoft.com/download/en/details.aspx?displaylang=en&amp;id=8363"&gt;EntityFramework 4.1&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="https://github.com/jquery/jquery-tmpl"&gt;jQuery Templates plugin (jquery-tmpl)&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Goals to achieve:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Any user should be able to view products &lt;/li&gt;&lt;li&gt;Product would be filtered by Categories &lt;/li&gt;&lt;li&gt;User should be able to add products in cart &lt;/li&gt;&lt;li&gt;Only registered user will be able to submit cart &lt;/li&gt;&lt;li&gt;User should be able to register into system &lt;/li&gt;&lt;li&gt;User will get confirmation Invoice after generating order in system. &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Architecture for this POC&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;I am not following any specific Architecture Pattern, although while designing this POC, I&amp;nbsp;&lt;strong&gt;try to follow&lt;/strong&gt;&amp;nbsp;some of the key design principles like:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Separation_of_concerns"&gt;Separation of concerns&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Abstraction_(computer_science)"&gt;Abstraction&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself"&gt;Don't repeat yourself&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/KISS_principle"&gt;KISS principle&lt;/a&gt; &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Again I am repeating my word&amp;nbsp;&lt;strong&gt;try to follow&amp;hellip;.. :)&lt;/strong&gt;. So, all comments/suggestions are more than welcome to discuss and I am always ready to adopt changes, or you can do it yourself by join&amp;nbsp;&lt;a href="http://pocwebapi.codeplex.com/"&gt;@CodePlex&lt;/a&gt;.
 The initial Skeleton for this application is as per below diagram:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/1.PNG" alt="Architecture" width="650" height="500"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Step-by-Step&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="#x_x_step1"&gt;Step 1: Create a basic Application Structure Layout&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="#x_x_step2"&gt;Step 2: Create the Data Access Layer&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="#x_x_step3"&gt;Step 3: Create the Service Layer&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="#x_x_step4"&gt;Step 4: Create the API Layer&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="#x_x_step5"&gt;Step 5: Integration of Dependency Injection using Autofac&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="#x_x_step6"&gt;Step 6: Add Views to solution&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="#x_x_step7"&gt;Step 7: Unit test and resolve issues&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="#x_x_step8"&gt;Step 8: Deploy application on IIS&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="#x_x_step9"&gt;Step 9: Provide Cross Domain Support&lt;/a&gt; &lt;/li&gt;&lt;/ul&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step1"&gt;Step 1: Create a basic Application Structure Layout&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;For more information on ASP.NET WebAPI, watch Videos and Tutorials&amp;nbsp;&lt;a href="http://www.asp.net/web-api"&gt;here&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add a blank Solution named as&amp;nbsp;&lt;strong&gt;Application&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add a new Project (Class Library) named as&amp;nbsp;&lt;strong&gt;Application.DAL&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Repeat above process and create four more Class Library projects named as &amp;ndash;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Application.Model&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Repository&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Common&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Service&lt;/strong&gt; &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Now, application will look like below screen-shot&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/4.PNG" alt="Solution 1" width="250" height="350"&gt;&lt;/p&gt;
&lt;p&gt;Next, add a new Project named as&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;as ASP.Net MVC 4 Web Application. After click on OK, select template as Web API&lt;/p&gt;
&lt;p&gt;This will add a full functional Web API template Application into our main solution.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/7.PNG" alt="Solution 1" width="230" height="350"&gt;&lt;/p&gt;
&lt;p&gt;Right click on Application.API project in Solution Explorer and go to properties, than assign a port to be use by this service application ( In my case its 30000). Hit F5 and we are ready with a dummy data as below screen:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/8.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step2"&gt;Step 2: Prepare Application.DAL, Application.Repository and Application.Model Layers&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Check&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/library/bb399182.aspx"&gt;@MSDN&lt;/a&gt;&amp;nbsp;for more information on Entity Framework&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add Entity Data Model to&amp;nbsp;&lt;strong&gt;Application.DAL&lt;/strong&gt;&amp;nbsp;project. To do this select ADO.NET Entity Data Model from the Data Templates list, and name it as&amp;nbsp;&lt;strong&gt;AdventureWorks.edmx&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Choose&amp;nbsp;&lt;strong&gt;&amp;ldquo;Generate from Database&amp;rdquo;&lt;/strong&gt;&amp;nbsp;and provide the connection string to read the database schema. This will add AdventureWorks.edmx into current project. Right click on the blank space in Entity Model surface and click
 on properties (or alternate press Alt &amp;#43;Enter on keyboard). Now set its Code Generation Strategy as&amp;nbsp;&lt;strong&gt;None&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/10.PNG" alt="Solution 1" width="550" height="300"&gt;&lt;/p&gt;
&lt;p&gt;Now create POCO entities for AdventureWorks Data Model into&amp;nbsp;&lt;strong&gt;Application.Model&lt;/strong&gt;&amp;nbsp;Solution. Check this article to do this job for you on MSDN to use&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/gg558520"&gt;T4 Templates and the Entity
 Framework&lt;/a&gt;&lt;br&gt;
Then, create all required repositories under Application.Repositories.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/11.PNG" alt="Solution 1" width="250" height="500"&gt;&lt;/p&gt;
&lt;p&gt;To build solution, add reference of&amp;nbsp;&lt;strong&gt;Application.Model.dll&lt;/strong&gt;&amp;nbsp;to&amp;nbsp;&lt;strong&gt;Application.DAL.dll&lt;/strong&gt;&amp;nbsp;and&amp;nbsp;&lt;strong&gt;Application.Repository.dll&lt;/strong&gt;projects, and add reference of&amp;nbsp;&lt;strong&gt;Application.DAL.dll&lt;/strong&gt;&amp;nbsp;to&amp;nbsp;&lt;strong&gt;Application.Repository.dll&lt;/strong&gt;&amp;nbsp;project.
 (See below picture for reference)&lt;br&gt;
Before proceeding to next step (designing Application.Service and Application.API Layer), let us see what we have designed yet:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/12.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step3"&gt;Step 3: Add files to Application.Service Layer&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Before adding files to Service layer let us look at the Goals which we want to achieve.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Any user should be able to view products &lt;/li&gt;&lt;li&gt;Product would be filtered by Categories &lt;/li&gt;&lt;li&gt;User should be able to add products in cart &lt;/li&gt;&lt;li&gt;Only registered user will be able to submit cart &lt;/li&gt;&lt;li&gt;User should be able to register into system &lt;/li&gt;&lt;li&gt;User will get confirmation Invoice after generating order in system. &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To achieve the above mention Goals, we need to add three service classes to Application.Service as per below image&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/13.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/14.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;I am not going in deatils, as the implementation for each methods are clear and easy to understand.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step4"&gt;Step 4: Add files to Application.API Layer&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To make this Web API accessed from a broad range of clients like any browsers which use JavaScript or any windows/Mobile platform which supports .dll files, we need to add Controllers with base class as&amp;nbsp;&lt;strong&gt;ApiController&lt;/strong&gt;.&amp;nbsp;&lt;a href="http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api"&gt;More
 details here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;First, we remove the default controllers added by template (HomeController and ValuesController) and then add three new controllers as per below diagram:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/15.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;Again, nothing special in the implementation of these methods, they all jst push the data to service layer.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step5"&gt;Step 5: Integration of Dependency Injection with WebAPI using Autofac&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The implementation is very much straight forward and clear.&amp;nbsp;&lt;a href="http://alexmg.com/post/2012/03/08/Autofac-ASPNET-Web-API-%28Beta%29-Integration.aspx"&gt;Check Alex post here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;Solution Explorer, right-click the References node and click Manage NuGet Packages&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/16.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;It will open the below screen.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/17.PNG" alt="Solution 1" width="700" height="200"&gt;&lt;/p&gt;
&lt;p&gt;Click on install and it will add below three references in solution&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/18.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;Next, go to Global.asax.cs and create a method named as ResolveDependency()&lt;/p&gt;
&lt;pre id="pre0" lang="cs"&gt;             protected void ResolveDependancy()
                {
                    var configuration = GlobalConfiguration.Configuration;
                    var builder = new ContainerBuilder();

                    // Configure the container with the integration implementations.
                    builder.ConfigureWebApi(configuration);

                    // Register API controllers using assembly scanning.
                    builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

                    builder.RegisterType&amp;lt;logservice&amp;gt;().As&amp;lt;ilogservice&amp;gt;().InstancePerLifetimeScope();
                    builder.RegisterType&amp;lt;unitofwork&amp;gt;().As&amp;lt;iunitofwork&amp;gt;().InstancePerDependency();
                    builder.RegisterType&amp;lt;databasefactory&amp;gt;().As&amp;lt;idatabasefactory&amp;gt;().InstancePerLifetimeScope();
                    builder.RegisterAssemblyTypes(typeof(ProductService).Assembly)
                    .Where(t =&amp;gt; t.Name.EndsWith(&amp;quot;Service&amp;quot;))
                    .AsImplementedInterfaces().InstancePerDependency();
                    builder.RegisterAssemblyTypes(typeof(CustomerRepository).Assembly)
                    .Where(t =&amp;gt; t.Name.EndsWith(&amp;quot;Repository&amp;quot;))
                    .AsImplementedInterfaces().InstancePerDependency();      

                    var container = builder.Build();

                    // Set the dependency resolver implementation.
                    var resolver = new AutofacWebApiDependencyResolver(container);
                    configuration.ServiceResolver.SetResolver(resolver);
                }
            &amp;lt;/idatabasefactory&amp;gt;&amp;lt;/databasefactory&amp;gt;&amp;lt;/iunitofwork&amp;gt;&amp;lt;/unitofwork&amp;gt;&amp;lt;/ilogservice&amp;gt;&amp;lt;/logservice&amp;gt;&lt;/pre&gt;
&lt;p&gt;Now we are ready to test our application. Hit F5 and check the browser with following url&amp;rsquo;s:&amp;nbsp;&lt;br&gt;
http://localhost:30000/api/products : will result all Product Categories&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/20.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;http://localhost:30000/api/products/2 : will result all Products with ProductcategoryID as 2&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/21.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;To check other methods, First we will add some Views in current solution.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step6"&gt;Step 6: Add View to solution&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Delete all default files and folders from Views Folder, and add three Html and their supportive Javascript File as. For this POC we will use html files, and some jquery libraries like:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;jquery.tmpl.js :&lt;/strong&gt;&amp;nbsp;to create template based screen, and&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;jquery.validationEngine.js :&lt;/strong&gt;&amp;nbsp;to validate form data&lt;/p&gt;
&lt;p&gt;Now the structure will looks like below picture :&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/22.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;For details code in html and JS file please look into the code. In next step I am going to resolve problems.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step7"&gt;Step 7: Resolve issues&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Before run the application Right Click on Products.htm and click on Set As start Page. Now hit F5&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/23.PNG" alt="Solution 1" width="700" height="300"&gt;&lt;/p&gt;
&lt;p&gt;It means, two WebAPI methods in ProductsController.cs are working perfectly. In JavaScript, on page load we are calling first method inside&amp;nbsp;&lt;strong&gt;product.js&lt;/strong&gt;&amp;nbsp;as:&lt;/p&gt;
&lt;pre id="pre1" lang="js"&gt;                    var productcategoriesAddress = &amp;quot;/api/products/&amp;quot;;
                    $(function () {
                        $('#tblRight').hide();
                        $.getJSON(
                                productcategoriesAddress,
                                function (data) {
                                    var parents = jQuery.grep(data, function (a) { return a.ParentProductCategoryID == null });
                                    var childs = jQuery.grep(data, function (a) { return a.ParentProductCategoryID != null });
                                    $.each(parents,
                                        function (index, value) {
                                            var categorydata = [];
                                            var subCategory = '';
                                            var subChild = jQuery.grep(childs, function (a) { return a.ParentProductCategoryID == value.ProductCategoryID });
                                            $.each(subChild,
                                                function (index, item) {
                                                    var serviceURL = productcategoriesAddress &amp;#43; item.ProductCategoryID;
                                                    subCategory = subCategory &amp;#43; &amp;quot;  &amp;quot; &amp;#43; &amp;quot;&amp;lt;a href=&amp;quot;%20&amp;#43;%20serviceURL%20&amp;#43;%20&amp;quot; class=&amp;quot;menuButton&amp;quot;&amp;gt;&amp;quot; &amp;#43; item.Name &amp;#43; &amp;quot;&amp;lt;/a&amp;gt;&amp;quot;;
                                                });
                                            categorydata.push({
                                                'ProductCategoryID': value.ProductCategoryID,
                                                'ParentCategory': value.Name,
                                                'ChildCategory': subCategory
                                            });
                                            $(&amp;quot;#categoryTemplate&amp;quot;).tmpl(categorydata).appendTo(&amp;quot;#categories&amp;quot;);
                                            $(&amp;quot;#&amp;quot; &amp;#43; value.Name).html(subCategory);
                                        });

                                        GetProducts(1);
                                }
                            );
                &lt;/pre&gt;
&lt;p&gt;This call hits below method in ProductsController, and returns all Product Category to create the Upper Menu Part&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;pre id="pre2" lang="cs"&gt;                    public IQueryable&amp;lt;productcategory&amp;gt; GetProductCategories()
                    {
                        loggerService.Logger().Info(&amp;quot;Calling with null parameter&amp;quot;);
                        return _productservice.GetProductCategories().AsQueryable&amp;lt;productcategory&amp;gt;();
                    }
                &amp;lt;/productcategory&amp;gt;&amp;lt;/productcategory&amp;gt;&lt;/pre&gt;
&lt;p&gt;In ProductService implementation is :&lt;/p&gt;
&lt;pre id="pre3" lang="cs"&gt;                    public IQueryable&amp;lt;productcategory&amp;gt; GetProductCategories()
                    {
                        loggerService.Logger().Info(&amp;quot;Calling with null parameter&amp;quot;);
                        return _productservice.GetProductCategories().AsQueryable&amp;lt;productcategory&amp;gt;();
                    }
                &amp;lt;/productcategory&amp;gt;&amp;lt;/productcategory&amp;gt;&lt;/pre&gt;
&lt;p&gt;The second call is to fetch all products depends on selected category. In javascript&lt;/p&gt;
&lt;pre id="pre4" lang="js"&gt;                      function GetProducts(ProductCategoryID) {
                        var serviceURL = productcategoriesAddress &amp;#43; ProductCategoryID;
                        $('#categories li h1').css('background', '#736F6E');
                        $('#mnu' &amp;#43; ProductCategoryID).css('background', '#357EC7');
                        $(&amp;quot;#loader&amp;quot;).show();
                        $.ajax({
                            type: &amp;quot;GET&amp;quot;,
                            datatype: &amp;quot;json&amp;quot;,
                            url: serviceURL,
                            context: this,
                            success: function (value) {
                                $(&amp;quot;#productData&amp;quot;).html(&amp;quot;&amp;quot;);
                                $(&amp;quot;#productTemplate&amp;quot;).tmpl(value).appendTo(&amp;quot;#productData&amp;quot;);
                                $(&amp;quot;#loader&amp;quot;).hide();
                            }
                        });
                        return false;
                    }
                &lt;/pre&gt;
&lt;p&gt;and in ProductsController it goes to&lt;/p&gt;
&lt;pre id="pre5" lang="cs"&gt;                    public IQueryable&amp;lt;product&amp;gt; GetProductByProductCategoryID(int id)
                    {
                        loggerService.Logger().Info(&amp;quot;Calling with null parameter as : id : &amp;quot; &amp;#43; id);
                        return _productservice.GetProductByProductCategoryID(id).AsQueryable&amp;lt;product&amp;gt;();
                    }

                &amp;lt;/product&amp;gt;&amp;lt;/product&amp;gt;&lt;/pre&gt;
&lt;p&gt;In ProductService implementation is :&lt;/p&gt;
&lt;pre id="pre6" lang="cs"&gt;                    public IQueryable&amp;lt;product&amp;gt; GetProductByProductCategoryID(int id)
                    {
                        loggerService.Logger().Info(&amp;quot;Calling with null parameter as : id : &amp;quot; &amp;#43; id);
                        return _productservice.GetProductByProductCategoryID(id).AsQueryable&amp;lt;product&amp;gt;();
                    }
                &amp;lt;/product&amp;gt;&amp;lt;/product&amp;gt;&lt;/pre&gt;
&lt;p&gt;Next, let us try to add some products to Cart and Checkout cart&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/28.PNG" alt="Solution 1" width="400" height="300"&gt;&lt;/p&gt;
&lt;p&gt;On clicking on checkout It redirect to Checkout.htm page and asking for either Login using existing CustomerID or Register for a new Customer.&lt;br&gt;
Click on&amp;nbsp;&lt;strong&gt;Register&lt;/strong&gt;&amp;nbsp;link to create a new Customer.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/29.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;Submit form after clicking on Register button and see if Posting is working or not. Again its success!!!&lt;/p&gt;
&lt;p&gt;Now we will try to update records for AddressLine2, and Update is also working fine!!!&lt;/p&gt;
&lt;p&gt;In both scenario (Add or Update Customer) we are calling below method of CutomerControllers.cs&lt;/p&gt;
&lt;pre id="pre7" lang="cs"&gt;                     public int PostCustomer(CustomerDTO customer)
                    {
                        loggerService.Logger().Info(&amp;quot;Calling with parameter as : customer: &amp;quot; &amp;#43; customer);
                        return _customerService.SaveOrUpdateCustomer(customer);
                    }
                &lt;/pre&gt;
&lt;p&gt;In CustomerService implementation is :&lt;/p&gt;
&lt;pre id="pre8" lang="cs"&gt;                    public int SaveOrUpdateCustomer(CustomerDTO customer)
                    {
                        string passwordSalt = CreateSalt(5);
                        string pasword = CreatePasswordHash(customer.Password, passwordSalt);
                        Customer objCustomer;

                        if (customer.CustomerID != 0)
                            objCustomer = _customerRepository.GetById(customer.CustomerID);
                        else
                            objCustomer = new Customer();

                        objCustomer.NameStyle = customer.NameStyle;
                        objCustomer.Title = customer.Title;
                        objCustomer.FirstName = customer.FirstName;
                        objCustomer.MiddleName = customer.MiddleName;
                        objCustomer.LastName = customer.LastName;
                        objCustomer.Suffix = customer.Suffix;
                        objCustomer.CompanyName = customer.CompanyName;
                        objCustomer.SalesPerson = customer.SalesPerson;
                        objCustomer.EmailAddress = customer.EmailAddress;
                        objCustomer.Phone = customer.Phone;
                        objCustomer.PasswordHash = pasword;
                        objCustomer.PasswordSalt = passwordSalt;
                        objCustomer.ModifiedDate = DateTime.Now;
                        objCustomer.rowguid = Guid.NewGuid();

                        if (customer.CustomerID != 0)
                            _customerRepository.Update(objCustomer);
                        else
                            _customerRepository.Add(objCustomer);

                        _unitOfWork.Commit();
                        SaveOrUpdateAddress(customer, objCustomer.CustomerID);
                        return objCustomer.CustomerID;
                    }
                &lt;/pre&gt;
&lt;p&gt;Next, click on Submit Order Button, to make previously selected products as an Order and receive Order Invoice.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/33.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;!!!Hurray!!! Order is created in system and invoice is generated with a new Purchase Order. But, wait we got one BUG&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue 1:&lt;/strong&gt;&amp;nbsp;we have an issue with Date Format.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/34.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;According to,&amp;nbsp;&lt;a href="http://www.hanselman.com/blog/OnTheNightmareThatIsJSONDatesPlusJSONNETAndASPNETWebAPI.aspx"&gt;Scott Hanselman&amp;rsquo;s post&lt;/a&gt;&amp;nbsp;this is a bug and will resolve in next release of ASP.Net WebAPI. This issue is resolved using&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/02/18/using-json-net-with-asp-net-web-api.aspx"&gt;solution
 provided in Henrik's Blog&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/35.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue 2:&lt;/strong&gt;&amp;nbsp;Another issue was, when I try to Checkout Cart using the last created Customer. The error was:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/36.PNG" alt="Solution 1" width="700" height="300"&gt;&lt;/p&gt;
&lt;p&gt;After looking this error, first thought comes that we missed the method in CustomersController.cs, but the method was already there. Further investigation make it clear, that, the reason behind this error was name of this method as ValidateCustomer():&lt;/p&gt;
&lt;pre id="pre9" lang="cs"&gt;                     public CustomerDTO ValidateCustomer(int id, string password)
                    {
                        loggerService.Logger().Info(&amp;quot;Calling with parameter as : id and password: &amp;quot; &amp;#43; id &amp;#43; &amp;quot; and &amp;quot; &amp;#43; password);
                        return _customerService.ValidateCustomer(id, password);
                    }
                &lt;/pre&gt;
&lt;p&gt;In CustomerService implementation is :&lt;/p&gt;
&lt;pre id="pre10" lang="cs"&gt;                    public CustomerDTO ValidateCustomer(int id, string password)
                    {
                        Customer objCustomer = _customerRepository.GetById(id);
                        if (objCustomer == null)
                            return null;
                        string strPasswordHash = objCustomer.PasswordHash;
                        string strPasswordSalt = strPasswordHash.Substring(strPasswordHash.Length - 8);
                        string strPasword = CreatePasswordHash(password, strPasswordSalt);

                        if (strPasword.Equals(strPasswordHash))
                            return CreateCustomerDTO(objCustomer);
                        else
                            return null;
                    }
                &lt;/pre&gt;
&lt;p&gt;By default the&amp;nbsp;&lt;strong&gt;route configuration&lt;/strong&gt;&amp;nbsp;of Asp.Net WebAPI follows RESTFUL conventions meaning that it will accept only the&amp;nbsp;&lt;strong&gt;Get, Post, Put and Delete&lt;/strong&gt;&amp;nbsp;action names. So when we send a GET request to http://localhost:30000/api/customers/ValidateCustomer/30135/test
 we are basically calling the Get(int id) action and passing id=30135 which obviously crashes because we don&amp;rsquo;t have any method starting with Get which accept Id as parameter. To resolve this issue I need to add a new route definition in&amp;nbsp;&lt;strong&gt;Global.asax&lt;/strong&gt;&amp;nbsp;file
 as:&lt;/p&gt;
&lt;pre id="pre11" lang="cs"&gt;                     routes.MapHttpRoute(
                           name: &amp;quot;ValidateCustomer&amp;quot;,
                           routeTemplate: &amp;quot;api/{controller}/{action}/{id}/{password}&amp;quot;,
                           defaults: new { action = &amp;quot;get&amp;quot; }
                       );
                &lt;/pre&gt;
&lt;p&gt;Adding this line done the magic and Login functinality start waorking&amp;hellip;. :)&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step8"&gt;Step 8: Deploy on IIS&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;To deploy this API on IIS version 7.5, first, publish only&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;solution to a Folder.&lt;/p&gt;
&lt;p&gt;Next, open IIS Manager and create a new website and set path to Publish folder, and we are done with deployment.&lt;/p&gt;
&lt;p&gt;Now, check whether page is opening or not, in my case, initially I got below error, which is self-explanatory.&lt;br&gt;
The error comes because this application is running on Asp.Net Framework Version 2.0. So, we need to change it to Asp.Net Framework Version 4.0:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/40.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/41.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;To change the Asp.Net Framework from 2.0 to 4.0, follow below steps.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/42.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/43.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;That was not the only reason not to run application, because after made above change in Application pool next error was:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/44.PNG" alt="Solution 1" width="700" height="200"&gt;&lt;/p&gt;
&lt;p&gt;To resolve this error again go to Advance Settings of Application pool and change the identity to Local System from ApplicationPoolIdentity&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/45.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;After modify the Application pool to use Local System, Application starts working on browser... :)&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/46.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;Although IIS errors are depending on servers/Firewall/Network or system to system, so it is very difficult to assume that you will also get the same error as mine. Check these links which help me to resolve some of the IIS issues in
 my work environment.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en/wcf/thread/b990d3ea-3335-40a6-877f-7c295da67a85"&gt;HTTP Error 500.19&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/eu/wcf/thread/39571e42-aca7-469d-8c68-aa59c2da4fcc"&gt;Could Not Load Type &amp;lsquo;System.ServiceModel.Activation.HttpModule&amp;rsquo;&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/k6h9cz8h.aspx"&gt;ASP.NET IIS Registration Tool&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms732012.aspx"&gt;ServiceModel Registration Tool&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step9"&gt;Step 9: Cross Domain Support&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The idea behind the Cross Domain Support comes when I try to remove all HTML pages from&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;solution and created a new Empty Web Application (Adventure.Website) which includes only&amp;nbsp;&lt;strong&gt;.html, .Js and .css&lt;/strong&gt;&amp;nbsp;files
 along with images. The structure for this application is as per below image:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/47.PNG" alt="Solution 1" width="300" height="500"&gt;&lt;/p&gt;
&lt;p&gt;Point all URL address to deployed code on IIS, after build and run application, output was null.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/48.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;To resolve this issue I would like to give my special thanks to Carlos&amp;rsquo; blog on MSDN&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2012/02/20/implementing-cors-support-in-asp-net-web-apis.aspx"&gt;Implementing CORS support in ASP.NET Web
 APIs&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;blockquote&gt;
&lt;div&gt;Quote:&lt;/div&gt;
&amp;ldquo;By default, a web page cannot make calls to services (APIs) on a domain other than the one where the page came from. This is a security measure against a group of cross-site forgery attacks in which browsing to a bad site could potentially use the browser
 cookies to get data from a good site which the user had previously logged on (think your bank). There are many situations, however, where getting data from different sites is a perfectly valid scenario, such as mash-up applications which need data from different
 sources.&amp;rdquo;&lt;/blockquote&gt;
&lt;h2&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;That's it !!! Hope you enjoy this article. I am not an expert, and also I have not followed the entire industry standard at the time of writing this article (time factor).&lt;/p&gt;
&lt;p&gt;All&amp;nbsp;&lt;strong&gt;comment/Vote&lt;/strong&gt;&amp;nbsp;are more than welcome&amp;hellip;. :), whenever, I get time, will try to modify this solution. You can also join/contribute to this project on&amp;nbsp;&lt;a href="http://pocwebapi.codeplex.com/"&gt;CodePlex&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Thank's for your time.&lt;/p&gt;
&lt;p&gt;Anand&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;br&gt;
&lt;/strong&gt;&lt;br&gt;
&lt;br&gt;
&lt;/p&gt;
&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>anandranjanpandey</author><pubDate>Thu, 22 Mar 2012 05:52:54 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20120322055254A</guid></item><item><title>Updated Wiki: Home</title><link>http://pocwebapi.codeplex.com/wikipage?version=5</link><description>&lt;div class="wikidoc"&gt;
&lt;h2&gt;&lt;strong&gt;Introduction&amp;nbsp;&lt;/strong&gt;&amp;nbsp;&lt;/h2&gt;
&lt;p&gt;The purpose of this article is to create a&lt;strong&gt;&amp;nbsp;proof of concept&amp;nbsp;&lt;/strong&gt;to demonstrate the feasibility of&amp;nbsp;&lt;a href="http://www.asp.net/web-api"&gt;ASP.NET WebAPI&lt;/a&gt;&amp;nbsp;Beta version.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Prerequisite:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://msftdbprodsamples.codeplex.com/"&gt;AdventureWorksLT2008R2&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://www.asp.net/web-api"&gt;ASP.Net WebAPI&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://code.google.com/p/autofac/downloads/list"&gt;Autofac for Dependency Injection&lt;/a&gt;&amp;nbsp;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://logging.apache.org/log4net/download.html"&gt;Log4Net&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://www.microsoft.com/download/en/details.aspx?displaylang=en&amp;id=8363"&gt;EntityFramework 4.1&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="https://github.com/jquery/jquery-tmpl"&gt;jQuery Templates plugin (jquery-tmpl)&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Goals to achieve:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Any user should be able to view products &lt;/li&gt;&lt;li&gt;Product would be filtered by Categories &lt;/li&gt;&lt;li&gt;User should be able to add products in cart &lt;/li&gt;&lt;li&gt;Only registered user will be able to submit cart &lt;/li&gt;&lt;li&gt;User should be able to register into system &lt;/li&gt;&lt;li&gt;User will get confirmation Invoice after generating order in system. &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Architecture for this POC&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;I am not following any specific Architecture Pattern, although while designing this POC, I&amp;nbsp;&lt;strong&gt;try to follow&lt;/strong&gt;&amp;nbsp;some of the key design principles like:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Separation_of_concerns"&gt;Separation of concerns&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Abstraction_(computer_science)"&gt;Abstraction&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself"&gt;Don't repeat yourself&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/KISS_principle"&gt;KISS principle&lt;/a&gt; &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Again I am repeating my word&amp;nbsp;&lt;strong&gt;try to follow&amp;hellip;.. :)&lt;/strong&gt;. So, all comments/suggestions are more than welcome to discuss and I am always ready to adopt changes, or you can do it yourself by join&amp;nbsp;&lt;a href="http://pocwebapi.codeplex.com/"&gt;@CodePlex&lt;/a&gt;.
 The initial Skeleton for this application is as per below diagram:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/1.PNG" alt="Architecture" width="650" height="500"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Step-by-Step&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="#x_step1"&gt;Step 1: Create a basic Application Structure Layout&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="#x_step2"&gt;Step 2: Create the Data Access Layer&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="#x_step3"&gt;Step 3: Create the Service Layer&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="#x_step4"&gt;Step 4: Create the API Layer&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="#x_step5"&gt;Step 5: Integration of Dependency Injection using Autofac&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="#x_step6"&gt;Step 6: Add Views to solution&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="#x_step7"&gt;Step 7: Unit test and resolve issues&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="#x_step8"&gt;Step 8: Deploy application on IIS&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="#x_step9"&gt;Step 9: Provide Cross Domain Support&lt;/a&gt; &lt;/li&gt;&lt;/ul&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step1"&gt;Step 1: Create a basic Application Structure Layout&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;For more information on ASP.NET WebAPI, watch Videos and Tutorials&amp;nbsp;&lt;a href="http://www.asp.net/web-api"&gt;here&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add a blank Solution named as&amp;nbsp;&lt;strong&gt;Application&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add a new Project (Class Library) named as&amp;nbsp;&lt;strong&gt;Application.DAL&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Repeat above process and create four more Class Library projects named as &amp;ndash;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Application.Model&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Repository&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Common&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Service&lt;/strong&gt; &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Now, application will look like below screen-shot&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/4.PNG" alt="Solution 1" width="250" height="350"&gt;&lt;/p&gt;
&lt;p&gt;Next, add a new Project named as&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;as ASP.Net MVC 4 Web Application. After click on OK, select template as Web API&lt;/p&gt;
&lt;p&gt;This will add a full functional Web API template Application into our main solution.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/7.PNG" alt="Solution 1" width="230" height="350"&gt;&lt;/p&gt;
&lt;p&gt;Right click on Application.API project in Solution Explorer and go to properties, than assign a port to be use by this service application ( In my case its 30000). Hit F5 and we are ready with a dummy data as below screen:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/8.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step2"&gt;Step 2: Prepare Application.DAL, Application.Repository and Application.Model Layers&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Check&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/library/bb399182.aspx"&gt;@MSDN&lt;/a&gt;&amp;nbsp;for more information on Entity Framework&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add Entity Data Model to&amp;nbsp;&lt;strong&gt;Application.DAL&lt;/strong&gt;&amp;nbsp;project. To do this select ADO.NET Entity Data Model from the Data Templates list, and name it as&amp;nbsp;&lt;strong&gt;AdventureWorks.edmx&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Choose&amp;nbsp;&lt;strong&gt;&amp;ldquo;Generate from Database&amp;rdquo;&lt;/strong&gt;&amp;nbsp;and provide the connection string to read the database schema. This will add AdventureWorks.edmx into current project. Right click on the blank space in Entity Model surface and click
 on properties (or alternate press Alt &amp;#43;Enter on keyboard). Now set its Code Generation Strategy as&amp;nbsp;&lt;strong&gt;None&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/10.PNG" alt="Solution 1" width="550" height="300"&gt;&lt;/p&gt;
&lt;p&gt;Now create POCO entities for AdventureWorks Data Model into&amp;nbsp;&lt;strong&gt;Application.Model&lt;/strong&gt;&amp;nbsp;Solution. Check this article to do this job for you on MSDN to use&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/gg558520"&gt;T4 Templates and the Entity
 Framework&lt;/a&gt;&lt;br&gt;
Then, create all required repositories under Application.Repositories.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/11.PNG" alt="Solution 1" width="250" height="500"&gt;&lt;/p&gt;
&lt;p&gt;To build solution, add reference of&amp;nbsp;&lt;strong&gt;Application.Model.dll&lt;/strong&gt;&amp;nbsp;to&amp;nbsp;&lt;strong&gt;Application.DAL.dll&lt;/strong&gt;&amp;nbsp;and&amp;nbsp;&lt;strong&gt;Application.Repository.dll&lt;/strong&gt;projects, and add reference of&amp;nbsp;&lt;strong&gt;Application.DAL.dll&lt;/strong&gt;&amp;nbsp;to&amp;nbsp;&lt;strong&gt;Application.Repository.dll&lt;/strong&gt;&amp;nbsp;project.
 (See below picture for reference)&lt;br&gt;
Before proceeding to next step (designing Application.Service and Application.API Layer), let us see what we have designed yet:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/12.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step3"&gt;Step 3: Add files to Application.Service Layer&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Before adding files to Service layer let us look at the Goals which we want to achieve.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Any user should be able to view products &lt;/li&gt;&lt;li&gt;Product would be filtered by Categories &lt;/li&gt;&lt;li&gt;User should be able to add products in cart &lt;/li&gt;&lt;li&gt;Only registered user will be able to submit cart &lt;/li&gt;&lt;li&gt;User should be able to register into system &lt;/li&gt;&lt;li&gt;User will get confirmation Invoice after generating order in system. &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To achieve the above mention Goals, we need to add three service classes to Application.Service as per below image&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/13.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/14.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;I am not going in deatils, as the implementation for each methods are clear and easy to understand.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step4"&gt;Step 4: Add files to Application.API Layer&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To make this Web API accessed from a broad range of clients like any browsers which use JavaScript or any windows/Mobile platform which supports .dll files, we need to add Controllers with base class as&amp;nbsp;&lt;strong&gt;ApiController&lt;/strong&gt;.&amp;nbsp;&lt;a href="http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api"&gt;More
 details here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;First, we remove the default controllers added by template (HomeController and ValuesController) and then add three new controllers as per below diagram:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/15.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;Again, nothing special in the implementation of these methods, they all jst push the data to service layer.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step5"&gt;Step 5: Integration of Dependency Injection with WebAPI using Autofac&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The implementation is very much straight forward and clear.&amp;nbsp;&lt;a href="http://alexmg.com/post/2012/03/08/Autofac-ASPNET-Web-API-%28Beta%29-Integration.aspx"&gt;Check Alex post here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;Solution Explorer, right-click the References node and click Manage NuGet Packages&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/16.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;It will open the below screen.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/17.PNG" alt="Solution 1" width="700" height="200"&gt;&lt;/p&gt;
&lt;p&gt;Click on install and it will add below three references in solution&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/18.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;Next, go to Global.asax.cs and create a method named as ResolveDependency()&lt;/p&gt;
&lt;pre id="pre0" lang="cs"&gt;             protected void ResolveDependancy()
                {
                    var configuration = GlobalConfiguration.Configuration;
                    var builder = new ContainerBuilder();

                    // Configure the container with the integration implementations.
                    builder.ConfigureWebApi(configuration);

                    // Register API controllers using assembly scanning.
                    builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

                    builder.RegisterType&amp;lt;logservice&amp;gt;().As&amp;lt;ilogservice&amp;gt;().InstancePerLifetimeScope();
                    builder.RegisterType&amp;lt;unitofwork&amp;gt;().As&amp;lt;iunitofwork&amp;gt;().InstancePerDependency();
                    builder.RegisterType&amp;lt;databasefactory&amp;gt;().As&amp;lt;idatabasefactory&amp;gt;().InstancePerLifetimeScope();
                    builder.RegisterAssemblyTypes(typeof(ProductService).Assembly)
                    .Where(t =&amp;gt; t.Name.EndsWith(&amp;quot;Service&amp;quot;))
                    .AsImplementedInterfaces().InstancePerDependency();
                    builder.RegisterAssemblyTypes(typeof(CustomerRepository).Assembly)
                    .Where(t =&amp;gt; t.Name.EndsWith(&amp;quot;Repository&amp;quot;))
                    .AsImplementedInterfaces().InstancePerDependency();      

                    var container = builder.Build();

                    // Set the dependency resolver implementation.
                    var resolver = new AutofacWebApiDependencyResolver(container);
                    configuration.ServiceResolver.SetResolver(resolver);
                }
            &amp;lt;/idatabasefactory&amp;gt;&amp;lt;/databasefactory&amp;gt;&amp;lt;/iunitofwork&amp;gt;&amp;lt;/unitofwork&amp;gt;&amp;lt;/ilogservice&amp;gt;&amp;lt;/logservice&amp;gt;&lt;/pre&gt;
&lt;p&gt;Now we are ready to test our application. Hit F5 and check the browser with following url&amp;rsquo;s:&amp;nbsp;&lt;br&gt;
http://localhost:30000/api/products : will result all Product Categories&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/20.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;http://localhost:30000/api/products/2 : will result all Products with ProductcategoryID as 2&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/21.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;To check other methods, First we will add some Views in current solution.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step6"&gt;Step 6: Add View to solution&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Delete all default files and folders from Views Folder, and add three Html and their supportive Javascript File as. For this POC we will use html files, and some jquery libraries like:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;jquery.tmpl.js :&lt;/strong&gt;&amp;nbsp;to create template based screen, and&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;jquery.validationEngine.js :&lt;/strong&gt;&amp;nbsp;to validate form data&lt;/p&gt;
&lt;p&gt;Now the structure will looks like below picture :&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/22.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;For details code in html and JS file please look into the code. In next step I am going to resolve problems.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step7"&gt;Step 7: Resolve issues&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Before run the application Right Click on Products.htm and click on Set As start Page. Now hit F5&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/23.PNG" alt="Solution 1" width="700" height="300"&gt;&lt;/p&gt;
&lt;p&gt;It means, two WebAPI methods in ProductsController.cs are working perfectly. In JavaScript, on page load we are calling first method inside&amp;nbsp;&lt;strong&gt;product.js&lt;/strong&gt;&amp;nbsp;as:&lt;/p&gt;
&lt;pre id="pre1" lang="js"&gt;                    var productcategoriesAddress = &amp;quot;/api/products/&amp;quot;;
                    $(function () {
                        $('#tblRight').hide();
                        $.getJSON(
                                productcategoriesAddress,
                                function (data) {
                                    var parents = jQuery.grep(data, function (a) { return a.ParentProductCategoryID == null });
                                    var childs = jQuery.grep(data, function (a) { return a.ParentProductCategoryID != null });
                                    $.each(parents,
                                        function (index, value) {
                                            var categorydata = [];
                                            var subCategory = '';
                                            var subChild = jQuery.grep(childs, function (a) { return a.ParentProductCategoryID == value.ProductCategoryID });
                                            $.each(subChild,
                                                function (index, item) {
                                                    var serviceURL = productcategoriesAddress &amp;#43; item.ProductCategoryID;
                                                    subCategory = subCategory &amp;#43; &amp;quot;  &amp;quot; &amp;#43; &amp;quot;&amp;lt;a href=&amp;quot;%20&amp;#43;%20serviceURL%20&amp;#43;%20&amp;quot; class=&amp;quot;menuButton&amp;quot;&amp;gt;&amp;quot; &amp;#43; item.Name &amp;#43; &amp;quot;&amp;lt;/a&amp;gt;&amp;quot;;
                                                });
                                            categorydata.push({
                                                'ProductCategoryID': value.ProductCategoryID,
                                                'ParentCategory': value.Name,
                                                'ChildCategory': subCategory
                                            });
                                            $(&amp;quot;#categoryTemplate&amp;quot;).tmpl(categorydata).appendTo(&amp;quot;#categories&amp;quot;);
                                            $(&amp;quot;#&amp;quot; &amp;#43; value.Name).html(subCategory);
                                        });

                                        GetProducts(1);
                                }
                            );
                &lt;/pre&gt;
&lt;p&gt;This call hits below method in ProductsController, and returns all Product Category to create the Upper Menu Part&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;pre id="pre2" lang="cs"&gt;                    public IQueryable&amp;lt;productcategory&amp;gt; GetProductCategories()
                    {
                        loggerService.Logger().Info(&amp;quot;Calling with null parameter&amp;quot;);
                        return _productservice.GetProductCategories().AsQueryable&amp;lt;productcategory&amp;gt;();
                    }
                &amp;lt;/productcategory&amp;gt;&amp;lt;/productcategory&amp;gt;&lt;/pre&gt;
&lt;p&gt;In ProductService implementation is :&lt;/p&gt;
&lt;pre id="pre3" lang="cs"&gt;                    public IQueryable&amp;lt;productcategory&amp;gt; GetProductCategories()
                    {
                        loggerService.Logger().Info(&amp;quot;Calling with null parameter&amp;quot;);
                        return _productservice.GetProductCategories().AsQueryable&amp;lt;productcategory&amp;gt;();
                    }
                &amp;lt;/productcategory&amp;gt;&amp;lt;/productcategory&amp;gt;&lt;/pre&gt;
&lt;p&gt;The second call is to fetch all products depends on selected category. In javascript&lt;/p&gt;
&lt;pre id="pre4" lang="js"&gt;                      function GetProducts(ProductCategoryID) {
                        var serviceURL = productcategoriesAddress &amp;#43; ProductCategoryID;
                        $('#categories li h1').css('background', '#736F6E');
                        $('#mnu' &amp;#43; ProductCategoryID).css('background', '#357EC7');
                        $(&amp;quot;#loader&amp;quot;).show();
                        $.ajax({
                            type: &amp;quot;GET&amp;quot;,
                            datatype: &amp;quot;json&amp;quot;,
                            url: serviceURL,
                            context: this,
                            success: function (value) {
                                $(&amp;quot;#productData&amp;quot;).html(&amp;quot;&amp;quot;);
                                $(&amp;quot;#productTemplate&amp;quot;).tmpl(value).appendTo(&amp;quot;#productData&amp;quot;);
                                $(&amp;quot;#loader&amp;quot;).hide();
                            }
                        });
                        return false;
                    }
                &lt;/pre&gt;
&lt;p&gt;and in ProductsController it goes to&lt;/p&gt;
&lt;pre id="pre5" lang="cs"&gt;                    public IQueryable&amp;lt;product&amp;gt; GetProductByProductCategoryID(int id)
                    {
                        loggerService.Logger().Info(&amp;quot;Calling with null parameter as : id : &amp;quot; &amp;#43; id);
                        return _productservice.GetProductByProductCategoryID(id).AsQueryable&amp;lt;product&amp;gt;();
                    }

                &amp;lt;/product&amp;gt;&amp;lt;/product&amp;gt;&lt;/pre&gt;
&lt;p&gt;In ProductService implementation is :&lt;/p&gt;
&lt;pre id="pre6" lang="cs"&gt;                    public IQueryable&amp;lt;product&amp;gt; GetProductByProductCategoryID(int id)
                    {
                        loggerService.Logger().Info(&amp;quot;Calling with null parameter as : id : &amp;quot; &amp;#43; id);
                        return _productservice.GetProductByProductCategoryID(id).AsQueryable&amp;lt;product&amp;gt;();
                    }
                &amp;lt;/product&amp;gt;&amp;lt;/product&amp;gt;&lt;/pre&gt;
&lt;p&gt;Next, let us try to add some products to Cart and Checkout cart&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/28.PNG" alt="Solution 1" width="400" height="300"&gt;&lt;/p&gt;
&lt;p&gt;On clicking on checkout It redirect to Checkout.htm page and asking for either Login using existing CustomerID or Register for a new Customer.&lt;br&gt;
Click on&amp;nbsp;&lt;strong&gt;Register&lt;/strong&gt;&amp;nbsp;link to create a new Customer.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/29.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;Submit form after clicking on Register button and see if Posting is working or not. Again its success!!!&lt;/p&gt;
&lt;p&gt;Now we will try to update records for AddressLine2, and Update is also working fine!!!&lt;/p&gt;
&lt;p&gt;In both scenario (Add or Update Customer) we are calling below method of CutomerControllers.cs&lt;/p&gt;
&lt;pre id="pre7" lang="cs"&gt;                     public int PostCustomer(CustomerDTO customer)
                    {
                        loggerService.Logger().Info(&amp;quot;Calling with parameter as : customer: &amp;quot; &amp;#43; customer);
                        return _customerService.SaveOrUpdateCustomer(customer);
                    }
                &lt;/pre&gt;
&lt;p&gt;In CustomerService implementation is :&lt;/p&gt;
&lt;pre id="pre8" lang="cs"&gt;                    public int SaveOrUpdateCustomer(CustomerDTO customer)
                    {
                        string passwordSalt = CreateSalt(5);
                        string pasword = CreatePasswordHash(customer.Password, passwordSalt);
                        Customer objCustomer;

                        if (customer.CustomerID != 0)
                            objCustomer = _customerRepository.GetById(customer.CustomerID);
                        else
                            objCustomer = new Customer();

                        objCustomer.NameStyle = customer.NameStyle;
                        objCustomer.Title = customer.Title;
                        objCustomer.FirstName = customer.FirstName;
                        objCustomer.MiddleName = customer.MiddleName;
                        objCustomer.LastName = customer.LastName;
                        objCustomer.Suffix = customer.Suffix;
                        objCustomer.CompanyName = customer.CompanyName;
                        objCustomer.SalesPerson = customer.SalesPerson;
                        objCustomer.EmailAddress = customer.EmailAddress;
                        objCustomer.Phone = customer.Phone;
                        objCustomer.PasswordHash = pasword;
                        objCustomer.PasswordSalt = passwordSalt;
                        objCustomer.ModifiedDate = DateTime.Now;
                        objCustomer.rowguid = Guid.NewGuid();

                        if (customer.CustomerID != 0)
                            _customerRepository.Update(objCustomer);
                        else
                            _customerRepository.Add(objCustomer);

                        _unitOfWork.Commit();
                        SaveOrUpdateAddress(customer, objCustomer.CustomerID);
                        return objCustomer.CustomerID;
                    }
                &lt;/pre&gt;
&lt;p&gt;Next, click on Submit Order Button, to make previously selected products as an Order and receive Order Invoice.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/33.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;!!!Hurray!!! Order is created in system and invoice is generated with a new Purchase Order. But, wait we got one BUG&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue 1:&lt;/strong&gt;&amp;nbsp;we have an issue with Date Format.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/34.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;According to,&amp;nbsp;&lt;a href="http://www.hanselman.com/blog/OnTheNightmareThatIsJSONDatesPlusJSONNETAndASPNETWebAPI.aspx"&gt;Scott Hanselman&amp;rsquo;s post&lt;/a&gt;&amp;nbsp;this is a bug and will resolve in next release of ASP.Net WebAPI. This issue is resolved using&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/02/18/using-json-net-with-asp-net-web-api.aspx"&gt;solution
 provided in Henrik's Blog&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/35.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue 2:&lt;/strong&gt;&amp;nbsp;Another issue was, when I try to Checkout Cart using the last created Customer. The error was:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/36.PNG" alt="Solution 1" width="700" height="300"&gt;&lt;/p&gt;
&lt;p&gt;After looking this error, first thought comes that we missed the method in CustomersController.cs, but the method was already there. Further investigation make it clear, that, the reason behind this error was name of this method as ValidateCustomer():&lt;/p&gt;
&lt;pre id="pre9" lang="cs"&gt;                     public CustomerDTO ValidateCustomer(int id, string password)
                    {
                        loggerService.Logger().Info(&amp;quot;Calling with parameter as : id and password: &amp;quot; &amp;#43; id &amp;#43; &amp;quot; and &amp;quot; &amp;#43; password);
                        return _customerService.ValidateCustomer(id, password);
                    }
                &lt;/pre&gt;
&lt;p&gt;In CustomerService implementation is :&lt;/p&gt;
&lt;pre id="pre10" lang="cs"&gt;                    public CustomerDTO ValidateCustomer(int id, string password)
                    {
                        Customer objCustomer = _customerRepository.GetById(id);
                        if (objCustomer == null)
                            return null;
                        string strPasswordHash = objCustomer.PasswordHash;
                        string strPasswordSalt = strPasswordHash.Substring(strPasswordHash.Length - 8);
                        string strPasword = CreatePasswordHash(password, strPasswordSalt);

                        if (strPasword.Equals(strPasswordHash))
                            return CreateCustomerDTO(objCustomer);
                        else
                            return null;
                    }
                &lt;/pre&gt;
&lt;p&gt;By default the&amp;nbsp;&lt;strong&gt;route configuration&lt;/strong&gt;&amp;nbsp;of Asp.Net WebAPI follows RESTFUL conventions meaning that it will accept only the&amp;nbsp;&lt;strong&gt;Get, Post, Put and Delete&lt;/strong&gt;&amp;nbsp;action names. So when we send a GET request to http://localhost:30000/api/customers/ValidateCustomer/30135/test
 we are basically calling the Get(int id) action and passing id=30135 which obviously crashes because we don&amp;rsquo;t have any method starting with Get which accept Id as parameter. To resolve this issue I need to add a new route definition in&amp;nbsp;&lt;strong&gt;Global.asax&lt;/strong&gt;&amp;nbsp;file
 as:&lt;/p&gt;
&lt;pre id="pre11" lang="cs"&gt;                     routes.MapHttpRoute(
                           name: &amp;quot;ValidateCustomer&amp;quot;,
                           routeTemplate: &amp;quot;api/{controller}/{action}/{id}/{password}&amp;quot;,
                           defaults: new { action = &amp;quot;get&amp;quot; }
                       );
                &lt;/pre&gt;
&lt;p&gt;Adding this line done the magic and Login functinality start waorking&amp;hellip;. :)&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step8"&gt;Step 8: Deploy on IIS&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;To deploy this API on IIS version 7.5, first, publish only&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;solution to a Folder.&lt;/p&gt;
&lt;p&gt;Next, open IIS Manager and create a new website and set path to Publish folder, and we are done with deployment.&lt;/p&gt;
&lt;p&gt;Now, check whether page is opening or not, in my case, initially I got below error, which is self-explanatory.&lt;br&gt;
The error comes because this application is running on Asp.Net Framework Version 2.0. So, we need to change it to Asp.Net Framework Version 4.0:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/40.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/41.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;To change the Asp.Net Framework from 2.0 to 4.0, follow below steps.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/42.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/43.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;That was not the only reason not to run application, because after made above change in Application pool next error was:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/44.PNG" alt="Solution 1" width="700" height="200"&gt;&lt;/p&gt;
&lt;p&gt;To resolve this error again go to Advance Settings of Application pool and change the identity to Local System from ApplicationPoolIdentity&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/45.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;After modify the Application pool to use Local System, Application starts working on browser... :)&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/46.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;Although IIS errors are depending on servers/Firewall/Network or system to system, so it is very difficult to assume that you will also get the same error as mine. Check these links which help me to resolve some of the IIS issues in
 my work environment.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en/wcf/thread/b990d3ea-3335-40a6-877f-7c295da67a85"&gt;HTTP Error 500.19&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/eu/wcf/thread/39571e42-aca7-469d-8c68-aa59c2da4fcc"&gt;Could Not Load Type &amp;lsquo;System.ServiceModel.Activation.HttpModule&amp;rsquo;&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/k6h9cz8h.aspx"&gt;ASP.NET IIS Registration Tool&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms732012.aspx"&gt;ServiceModel Registration Tool&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step9"&gt;Step 9: Cross Domain Support&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The idea behind the Cross Domain Support comes when I try to remove all HTML pages from&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;solution and created a new Empty Web Application (Adventure.Website) which includes only&amp;nbsp;&lt;strong&gt;.html, .Js and .css&lt;/strong&gt;&amp;nbsp;files
 along with images. The structure for this application is as per below image:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/47.PNG" alt="Solution 1" width="300" height="500"&gt;&lt;/p&gt;
&lt;p&gt;Point all URL address to deployed code on IIS, after build and run application, output was null.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/48.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;To resolve this issue I would like to give my special thanks to Carlos&amp;rsquo; blog on MSDN&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2012/02/20/implementing-cors-support-in-asp-net-web-apis.aspx"&gt;Implementing CORS support in ASP.NET Web
 APIs&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;blockquote&gt;
&lt;div&gt;Quote:&lt;/div&gt;
&amp;ldquo;By default, a web page cannot make calls to services (APIs) on a domain other than the one where the page came from. This is a security measure against a group of cross-site forgery attacks in which browsing to a bad site could potentially use the browser
 cookies to get data from a good site which the user had previously logged on (think your bank). There are many situations, however, where getting data from different sites is a perfectly valid scenario, such as mash-up applications which need data from different
 sources.&amp;rdquo;&lt;/blockquote&gt;
&lt;h2&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;That's it !!! Hope you enjoy this article. I am not an expert, and also I have not followed the entire industry standard at the time of writing this article (time factor).&lt;/p&gt;
&lt;p&gt;All&amp;nbsp;&lt;strong&gt;comment/Vote&lt;/strong&gt;&amp;nbsp;are more than welcome&amp;hellip;. :), whenever, I get time, will try to modify this solution. You can also join/contribute to this project on&amp;nbsp;&lt;a href="http://pocwebapi.codeplex.com/"&gt;CodePlex&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Thank's for your time.&lt;/p&gt;
&lt;p&gt;Anand&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;br&gt;
&lt;/strong&gt;&lt;br&gt;
&lt;br&gt;
&lt;/p&gt;
&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>anandranjanpandey</author><pubDate>Thu, 22 Mar 2012 05:49:16 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20120322054916A</guid></item><item><title>Updated Wiki: Home</title><link>http://pocwebapi.codeplex.com/wikipage?version=4</link><description>&lt;div class="wikidoc"&gt;
&lt;h2&gt;&lt;strong&gt;Introduction&amp;nbsp;&lt;/strong&gt;&amp;nbsp;&lt;/h2&gt;
&lt;p&gt;The purpose of this article is to create a&lt;strong&gt;&amp;nbsp;proof of concept&amp;nbsp;&lt;/strong&gt;to demonstrate the feasibility of&amp;nbsp;&lt;a href="http://www.asp.net/web-api"&gt;ASP.NET WebAPI&lt;/a&gt;&amp;nbsp;Beta version.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Prerequisite:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://msftdbprodsamples.codeplex.com/"&gt;AdventureWorksLT2008R2&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://www.asp.net/web-api"&gt;ASP.Net WebAPI&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://code.google.com/p/autofac/downloads/list"&gt;Autofac for Dependency Injection&lt;/a&gt;&amp;nbsp;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://logging.apache.org/log4net/download.html"&gt;Log4Net&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://www.microsoft.com/download/en/details.aspx?displaylang=en&amp;id=8363"&gt;EntityFramework 4.1&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="https://github.com/jquery/jquery-tmpl"&gt;jQuery Templates plugin (jquery-tmpl)&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Goals to achieve:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Any user should be able to view products &lt;/li&gt;&lt;li&gt;Product would be filtered by Categories &lt;/li&gt;&lt;li&gt;User should be able to add products in cart &lt;/li&gt;&lt;li&gt;Only registered user will be able to submit cart &lt;/li&gt;&lt;li&gt;User should be able to register into system &lt;/li&gt;&lt;li&gt;User will get confirmation Invoice after generating order in system. &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Architecture for this POC&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;I am not following any specific Architecture Pattern, although while designing this POC, I&amp;nbsp;&lt;strong&gt;try to follow&lt;/strong&gt;&amp;nbsp;some of the key design principles like:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Separation_of_concerns"&gt;Separation of concerns&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Abstraction_(computer_science)"&gt;Abstraction&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself"&gt;Don't repeat yourself&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/KISS_principle"&gt;KISS principle&lt;/a&gt; &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Again I am repeating my word&amp;nbsp;&lt;strong&gt;try to follow&amp;hellip;.. :)&lt;/strong&gt;. So, all comments/suggestions are more than welcome to discuss and I am always ready to adopt changes, or you can do it yourself by join&amp;nbsp;&lt;a href="http://pocwebapi.codeplex.com/"&gt;@CodePlex&lt;/a&gt;.
 The initial Skeleton for this application is as per below diagram:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/1.PNG" alt="Architecture" width="650" height="500"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Step-by-Step&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="#x_step1"&gt;Step 1: Create a basic Application Structure Layout&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="#x_step2"&gt;Step 2: Create the Data Access Layer&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="#x_step3"&gt;Step 3: Create the Service Layer&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="#x_step4"&gt;Step 4: Create the API Layer&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="#x_step5"&gt;Step 5: Integration of Dependency Injection using Autofac&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="#x_step6"&gt;Step 6: Add Views to solution&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="#x_step7"&gt;Step 7: Unit test and resolve issues&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="#x_step8"&gt;Step 8: Deploy application on IIS&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="#x_step9"&gt;Step 9: Provide Cross Domain Support&lt;/a&gt; &lt;/li&gt;&lt;/ul&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step1"&gt;Step 1: Create a basic Application Structure Layout&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;For more information on ASP.NET WebAPI, watch Videos and Tutorials&amp;nbsp;&lt;a href="http://www.asp.net/web-api"&gt;here&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add a blank Solution named as&amp;nbsp;&lt;strong&gt;Application&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add a new Project (Class Library) named as&amp;nbsp;&lt;strong&gt;Application.DAL&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Repeat above process and create four more Class Library projects named as &amp;ndash;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Application.Model&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Repository&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Common&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Service&lt;/strong&gt; &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Now, application will look like below screen-shot&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/4.PNG" alt="Solution 1" width="250" height="350"&gt;&lt;/p&gt;
&lt;p&gt;Next, add a new Project named as&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;as ASP.Net MVC 4 Web Application. After click on OK, select template as Web API&lt;/p&gt;
&lt;p&gt;This will add a full functional Web API template Application into our main solution.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/7.PNG" alt="Solution 1" width="230" height="350"&gt;&lt;/p&gt;
&lt;p&gt;Right click on Application.API project in Solution Explorer and go to properties, than assign a port to be use by this service application ( In my case its 30000). Hit F5 and we are ready with a dummy data as below screen:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/8.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step2"&gt;Step 2: Prepare Application.DAL, Application.Repository and Application.Model Layers&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Check&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/library/bb399182.aspx"&gt;@MSDN&lt;/a&gt;&amp;nbsp;for more information on Entity Framework&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add Entity Data Model to&amp;nbsp;&lt;strong&gt;Application.DAL&lt;/strong&gt;&amp;nbsp;project. To do this select ADO.NET Entity Data Model from the Data Templates list, and name it as&amp;nbsp;&lt;strong&gt;AdventureWorks.edmx&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Choose&amp;nbsp;&lt;strong&gt;&amp;ldquo;Generate from Database&amp;rdquo;&lt;/strong&gt;&amp;nbsp;and provide the connection string to read the database schema. This will add AdventureWorks.edmx into current project. Right click on the blank space in Entity Model surface and click
 on properties (or alternate press Alt &amp;#43;Enter on keyboard). Now set its Code Generation Strategy as&amp;nbsp;&lt;strong&gt;None&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/10.PNG" alt="Solution 1" width="550" height="300"&gt;&lt;/p&gt;
&lt;p&gt;Now create POCO entities for AdventureWorks Data Model into&amp;nbsp;&lt;strong&gt;Application.Model&lt;/strong&gt;&amp;nbsp;Solution. Check this article to do this job for you on MSDN to use&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/gg558520"&gt;T4 Templates and the Entity
 Framework&lt;/a&gt;&lt;br&gt;
Then, create all required repositories under Application.Repositories.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/11.PNG" alt="Solution 1" width="250" height="500"&gt;&lt;/p&gt;
&lt;p&gt;To build solution, add reference of&amp;nbsp;&lt;strong&gt;Application.Model.dll&lt;/strong&gt;&amp;nbsp;to&amp;nbsp;&lt;strong&gt;Application.DAL.dll&lt;/strong&gt;&amp;nbsp;and&amp;nbsp;&lt;strong&gt;Application.Repository.dll&lt;/strong&gt;projects, and add reference of&amp;nbsp;&lt;strong&gt;Application.DAL.dll&lt;/strong&gt;&amp;nbsp;to&amp;nbsp;&lt;strong&gt;Application.Repository.dll&lt;/strong&gt;&amp;nbsp;project.
 (See below picture for reference)&lt;br&gt;
Before proceeding to next step (designing Application.Service and Application.API Layer), let us see what we have designed yet:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/12.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step3"&gt;Step 3: Add files to Application.Service Layer&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Before adding files to Service layer let us look at the Goals which we want to achieve.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Any user should be able to view products &lt;/li&gt;&lt;li&gt;Product would be filtered by Categories &lt;/li&gt;&lt;li&gt;User should be able to add products in cart &lt;/li&gt;&lt;li&gt;Only registered user will be able to submit cart &lt;/li&gt;&lt;li&gt;User should be able to register into system &lt;/li&gt;&lt;li&gt;User will get confirmation Invoice after generating order in system. &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To achieve the above mention Goals, we need to add three service classes to Application.Service as per below image&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/13.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/14.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;I am not going in deatils, as the implementation for each methods are clear and easy to understand.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step4"&gt;Step 4: Add files to Application.API Layer&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To make this Web API accessed from a broad range of clients like any browsers which use JavaScript or any windows/Mobile platform which supports .dll files, we need to add Controllers with base class as&amp;nbsp;&lt;strong&gt;ApiController&lt;/strong&gt;.&amp;nbsp;&lt;a href="http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api"&gt;More
 details here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;First, we remove the default controllers added by template (HomeController and ValuesController) and then add three new controllers as per below diagram:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/15.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;Again, nothing special in the implementation of these methods, they all jst push the data to service layer.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step5"&gt;Step 5: Integration of Dependency Injection with WebAPI using Autofac&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The implementation is very much straight forward and clear.&amp;nbsp;&lt;a href="http://alexmg.com/post/2012/03/08/Autofac-ASPNET-Web-API-%28Beta%29-Integration.aspx"&gt;Check Alex post here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;Solution Explorer, right-click the References node and click Manage NuGet Packages&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/16.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;It will open the below screen.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/17.PNG" alt="Solution 1" width="700" height="200"&gt;&lt;/p&gt;
&lt;p&gt;Click on install and it will add below three references in solution&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/18.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;Next, go to Global.asax.cs and create a method named as ResolveDependency()&lt;/p&gt;
&lt;pre id="pre0" lang="cs"&gt;             protected void ResolveDependancy()
                {
                    var configuration = GlobalConfiguration.Configuration;
                    var builder = new ContainerBuilder();

                    // Configure the container with the integration implementations.
                    builder.ConfigureWebApi(configuration);

                    // Register API controllers using assembly scanning.
                    builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

                    builder.RegisterType&amp;lt;logservice&amp;gt;().As&amp;lt;ilogservice&amp;gt;().InstancePerLifetimeScope();
                    builder.RegisterType&amp;lt;unitofwork&amp;gt;().As&amp;lt;iunitofwork&amp;gt;().InstancePerDependency();
                    builder.RegisterType&amp;lt;databasefactory&amp;gt;().As&amp;lt;idatabasefactory&amp;gt;().InstancePerLifetimeScope();
                    builder.RegisterAssemblyTypes(typeof(ProductService).Assembly)
                    .Where(t =&amp;gt; t.Name.EndsWith(&amp;quot;Service&amp;quot;))
                    .AsImplementedInterfaces().InstancePerDependency();
                    builder.RegisterAssemblyTypes(typeof(CustomerRepository).Assembly)
                    .Where(t =&amp;gt; t.Name.EndsWith(&amp;quot;Repository&amp;quot;))
                    .AsImplementedInterfaces().InstancePerDependency();      

                    var container = builder.Build();

                    // Set the dependency resolver implementation.
                    var resolver = new AutofacWebApiDependencyResolver(container);
                    configuration.ServiceResolver.SetResolver(resolver);
                }
            &amp;lt;/idatabasefactory&amp;gt;&amp;lt;/databasefactory&amp;gt;&amp;lt;/iunitofwork&amp;gt;&amp;lt;/unitofwork&amp;gt;&amp;lt;/ilogservice&amp;gt;&amp;lt;/logservice&amp;gt;&lt;/pre&gt;
&lt;p&gt;Now we are ready to test our application. Hit F5 and check the browser with following url&amp;rsquo;s:&amp;nbsp;&lt;br&gt;
http://localhost:30000/api/products : will result all Product Categories&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/20.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;http://localhost:30000/api/products/2 : will result all Products with ProductcategoryID as 2&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/21.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;To check other methods, First we will add some Views in current solution.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step6"&gt;Step 6: Add View to solution&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Delete all default files and folders from Views Folder, and add three Html and their supportive Javascript File as. For this POC we will use html files, and some jquery libraries like:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;jquery.tmpl.js :&lt;/strong&gt;&amp;nbsp;to create template based screen, and&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;jquery.validationEngine.js :&lt;/strong&gt;&amp;nbsp;to validate form data&lt;/p&gt;
&lt;p&gt;Now the structure will looks like below picture :&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/22.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;For details code in html and JS file please look into the code. In next step I am going to resolve problems.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step7"&gt;Step 7: Resolve issues&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Before run the application Right Click on Products.htm and click on Set As start Page. Now hit F5&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/23.PNG" alt="Solution 1" width="700" height="300"&gt;&lt;/p&gt;
&lt;p&gt;It means, two WebAPI methods in ProductsController.cs are working perfectly. In JavaScript, on page load we are calling first method inside&amp;nbsp;&lt;strong&gt;product.js&lt;/strong&gt;&amp;nbsp;as:&lt;/p&gt;
&lt;pre id="pre1" lang="js"&gt;                    var productcategoriesAddress = &amp;quot;/api/products/&amp;quot;;
                    $(function () {
                        $('#tblRight').hide();
                        $.getJSON(
                                productcategoriesAddress,
                                function (data) {
                                    var parents = jQuery.grep(data, function (a) { return a.ParentProductCategoryID == null });
                                    var childs = jQuery.grep(data, function (a) { return a.ParentProductCategoryID != null });
                                    $.each(parents,
                                        function (index, value) {
                                            var categorydata = [];
                                            var subCategory = '';
                                            var subChild = jQuery.grep(childs, function (a) { return a.ParentProductCategoryID == value.ProductCategoryID });
                                            $.each(subChild,
                                                function (index, item) {
                                                    var serviceURL = productcategoriesAddress &amp;#43; item.ProductCategoryID;
                                                    subCategory = subCategory &amp;#43; &amp;quot;  &amp;quot; &amp;#43; &amp;quot;&amp;lt;a href=&amp;quot;%20&amp;#43;%20serviceURL%20&amp;#43;%20&amp;quot; class=&amp;quot;menuButton&amp;quot;&amp;gt;&amp;quot; &amp;#43; item.Name &amp;#43; &amp;quot;&amp;lt;/a&amp;gt;&amp;quot;;
                                                });
                                            categorydata.push({
                                                'ProductCategoryID': value.ProductCategoryID,
                                                'ParentCategory': value.Name,
                                                'ChildCategory': subCategory
                                            });
                                            $(&amp;quot;#categoryTemplate&amp;quot;).tmpl(categorydata).appendTo(&amp;quot;#categories&amp;quot;);
                                            $(&amp;quot;#&amp;quot; &amp;#43; value.Name).html(subCategory);
                                        });

                                        GetProducts(1);
                                }
                            );
                &lt;/pre&gt;
&lt;p&gt;This call hits below method in ProductsController, and returns all Product Category to create the Upper Menu Part&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;pre id="pre2" lang="cs"&gt;                    public IQueryable&amp;lt;productcategory&amp;gt; GetProductCategories()
                    {
                        loggerService.Logger().Info(&amp;quot;Calling with null parameter&amp;quot;);
                        return _productservice.GetProductCategories().AsQueryable&amp;lt;productcategory&amp;gt;();
                    }
                &amp;lt;/productcategory&amp;gt;&amp;lt;/productcategory&amp;gt;&lt;/pre&gt;
&lt;p&gt;In ProductService implementation is :&lt;/p&gt;
&lt;pre id="pre3" lang="cs"&gt;                    public IQueryable&amp;lt;productcategory&amp;gt; GetProductCategories()
                    {
                        loggerService.Logger().Info(&amp;quot;Calling with null parameter&amp;quot;);
                        return _productservice.GetProductCategories().AsQueryable&amp;lt;productcategory&amp;gt;();
                    }
                &amp;lt;/productcategory&amp;gt;&amp;lt;/productcategory&amp;gt;&lt;/pre&gt;
&lt;p&gt;The second call is to fetch all products depends on selected category. In javascript&lt;/p&gt;
&lt;pre id="pre4" lang="js"&gt;                      function GetProducts(ProductCategoryID) {
                        var serviceURL = productcategoriesAddress &amp;#43; ProductCategoryID;
                        $('#categories li h1').css('background', '#736F6E');
                        $('#mnu' &amp;#43; ProductCategoryID).css('background', '#357EC7');
                        $(&amp;quot;#loader&amp;quot;).show();
                        $.ajax({
                            type: &amp;quot;GET&amp;quot;,
                            datatype: &amp;quot;json&amp;quot;,
                            url: serviceURL,
                            context: this,
                            success: function (value) {
                                $(&amp;quot;#productData&amp;quot;).html(&amp;quot;&amp;quot;);
                                $(&amp;quot;#productTemplate&amp;quot;).tmpl(value).appendTo(&amp;quot;#productData&amp;quot;);
                                $(&amp;quot;#loader&amp;quot;).hide();
                            }
                        });
                        return false;
                    }
                &lt;/pre&gt;
&lt;p&gt;and in ProductsController it goes to&lt;/p&gt;
&lt;pre id="pre5" lang="cs"&gt;                    public IQueryable&amp;lt;product&amp;gt; GetProductByProductCategoryID(int id)
                    {
                        loggerService.Logger().Info(&amp;quot;Calling with null parameter as : id : &amp;quot; &amp;#43; id);
                        return _productservice.GetProductByProductCategoryID(id).AsQueryable&amp;lt;product&amp;gt;();
                    }

                &amp;lt;/product&amp;gt;&amp;lt;/product&amp;gt;&lt;/pre&gt;
&lt;p&gt;In ProductService implementation is :&lt;/p&gt;
&lt;pre id="pre6" lang="cs"&gt;                    public IQueryable&amp;lt;product&amp;gt; GetProductByProductCategoryID(int id)
                    {
                        loggerService.Logger().Info(&amp;quot;Calling with null parameter as : id : &amp;quot; &amp;#43; id);
                        return _productservice.GetProductByProductCategoryID(id).AsQueryable&amp;lt;product&amp;gt;();
                    }
                &amp;lt;/product&amp;gt;&amp;lt;/product&amp;gt;&lt;/pre&gt;
&lt;p&gt;Next, let us try to add some products to Cart and Checkout cart&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/28.PNG" alt="Solution 1" width="400" height="300"&gt;&lt;/p&gt;
&lt;p&gt;On clicking on checkout It redirect to Checkout.htm page and asking for either Login using existing CustomerID or Register for a new Customer.&lt;br&gt;
Click on&amp;nbsp;&lt;strong&gt;Register&lt;/strong&gt;&amp;nbsp;link to create a new Customer.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/29.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;Submit form after clicking on Register button and see if Posting is working or not. Again its success!!!&lt;/p&gt;
&lt;p&gt;Now we will try to update records for AddressLine2, and Update is also working fine!!!&lt;/p&gt;
&lt;p&gt;In both scenario (Add or Update Customer) we are calling below method of CutomerControllers.cs&lt;/p&gt;
&lt;pre id="pre7" lang="cs"&gt;                     public int PostCustomer(CustomerDTO customer)
                    {
                        loggerService.Logger().Info(&amp;quot;Calling with parameter as : customer: &amp;quot; &amp;#43; customer);
                        return _customerService.SaveOrUpdateCustomer(customer);
                    }
                &lt;/pre&gt;
&lt;p&gt;In CustomerService implementation is :&lt;/p&gt;
&lt;pre id="pre8" lang="cs"&gt;                    public int SaveOrUpdateCustomer(CustomerDTO customer)
                    {
                        string passwordSalt = CreateSalt(5);
                        string pasword = CreatePasswordHash(customer.Password, passwordSalt);
                        Customer objCustomer;

                        if (customer.CustomerID != 0)
                            objCustomer = _customerRepository.GetById(customer.CustomerID);
                        else
                            objCustomer = new Customer();

                        objCustomer.NameStyle = customer.NameStyle;
                        objCustomer.Title = customer.Title;
                        objCustomer.FirstName = customer.FirstName;
                        objCustomer.MiddleName = customer.MiddleName;
                        objCustomer.LastName = customer.LastName;
                        objCustomer.Suffix = customer.Suffix;
                        objCustomer.CompanyName = customer.CompanyName;
                        objCustomer.SalesPerson = customer.SalesPerson;
                        objCustomer.EmailAddress = customer.EmailAddress;
                        objCustomer.Phone = customer.Phone;
                        objCustomer.PasswordHash = pasword;
                        objCustomer.PasswordSalt = passwordSalt;
                        objCustomer.ModifiedDate = DateTime.Now;
                        objCustomer.rowguid = Guid.NewGuid();

                        if (customer.CustomerID != 0)
                            _customerRepository.Update(objCustomer);
                        else
                            _customerRepository.Add(objCustomer);

                        _unitOfWork.Commit();
                        SaveOrUpdateAddress(customer, objCustomer.CustomerID);
                        return objCustomer.CustomerID;
                    }
                &lt;/pre&gt;
&lt;p&gt;Next, click on Submit Order Button, to make previously selected products as an Order and receive Order Invoice.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/33.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;!!!Hurray!!! Order is created in system and invoice is generated with a new Purchase Order. But, wait we got one BUG&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue 1:&lt;/strong&gt;&amp;nbsp;we have an issue with Date Format.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/34.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;According to,&amp;nbsp;&lt;a href="http://www.hanselman.com/blog/OnTheNightmareThatIsJSONDatesPlusJSONNETAndASPNETWebAPI.aspx"&gt;Scott Hanselman&amp;rsquo;s post&lt;/a&gt;&amp;nbsp;this is a bug and will resolve in next release of ASP.Net WebAPI. This issue is resolved using&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/02/18/using-json-net-with-asp-net-web-api.aspx"&gt;solution
 provided in Henrik's Blog&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/35.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue 2:&lt;/strong&gt;&amp;nbsp;Another issue was, when I try to Checkout Cart using the last created Customer. The error was:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/36.PNG" alt="Solution 1" width="700" height="300"&gt;&lt;/p&gt;
&lt;p&gt;After looking this error, first thought comes that we missed the method in CustomersController.cs, but the method was already there. Further investigation make it clear, that, the reason behind this error was name of this method as ValidateCustomer():&lt;/p&gt;
&lt;pre id="pre9" lang="cs"&gt;                     public CustomerDTO ValidateCustomer(int id, string password)
                    {
                        loggerService.Logger().Info(&amp;quot;Calling with parameter as : id and password: &amp;quot; &amp;#43; id &amp;#43; &amp;quot; and &amp;quot; &amp;#43; password);
                        return _customerService.ValidateCustomer(id, password);
                    }
                &lt;/pre&gt;
&lt;p&gt;In CustomerService implementation is :&lt;/p&gt;
&lt;pre id="pre10" lang="cs"&gt;                    public CustomerDTO ValidateCustomer(int id, string password)
                    {
                        Customer objCustomer = _customerRepository.GetById(id);
                        if (objCustomer == null)
                            return null;
                        string strPasswordHash = objCustomer.PasswordHash;
                        string strPasswordSalt = strPasswordHash.Substring(strPasswordHash.Length - 8);
                        string strPasword = CreatePasswordHash(password, strPasswordSalt);

                        if (strPasword.Equals(strPasswordHash))
                            return CreateCustomerDTO(objCustomer);
                        else
                            return null;
                    }
                &lt;/pre&gt;
&lt;p&gt;By default the&amp;nbsp;&lt;strong&gt;route configuration&lt;/strong&gt;&amp;nbsp;of Asp.Net WebAPI follows RESTFUL conventions meaning that it will accept only the&amp;nbsp;&lt;strong&gt;Get, Post, Put and Delete&lt;/strong&gt;&amp;nbsp;action names. So when we send a GET request to http://localhost:30000/api/customers/ValidateCustomer/30135/test
 we are basically calling the Get(int id) action and passing id=30135 which obviously crashes because we don&amp;rsquo;t have any method starting with Get which accept Id as parameter. To resolve this issue I need to add a new route definition in&amp;nbsp;&lt;strong&gt;Global.asax&lt;/strong&gt;&amp;nbsp;file
 as:&lt;/p&gt;
&lt;pre id="pre11" lang="cs"&gt;                     routes.MapHttpRoute(
                           name: &amp;quot;ValidateCustomer&amp;quot;,
                           routeTemplate: &amp;quot;api/{controller}/{action}/{id}/{password}&amp;quot;,
                           defaults: new { action = &amp;quot;get&amp;quot; }
                       );
                &lt;/pre&gt;
&lt;p&gt;Adding this line done the magic and Login functinality start waorking&amp;hellip;. :)&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step8"&gt;Step 8: Deploy on IIS&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;To deploy this API on IIS version 7.5, first, publish only&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;solution to a Folder.&lt;/p&gt;
&lt;p&gt;Next, open IIS Manager and create a new website and set path to Publish folder, and we are done with deployment.&lt;/p&gt;
&lt;p&gt;Now, check whether page is opening or not, in my case, initially I got below error, which is self-explanatory.&lt;br&gt;
The error comes because this application is running on Asp.Net Framework Version 2.0. So, we need to change it to Asp.Net Framework Version 4.0:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/40.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/41.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;To change the Asp.Net Framework from 2.0 to 4.0, follow below steps.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/42.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/43.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;That was not the only reason not to run application, because after made above change in Application pool next error was:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/44.PNG" alt="Solution 1" width="700" height="200"&gt;&lt;/p&gt;
&lt;p&gt;To resolve this error again go to Advance Settings of Application pool and change the identity to Local System from ApplicationPoolIdentity&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/45.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;After modify the Application pool to use Local System, Application starts working on browser... :)&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/46.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;Although IIS errors are depending on servers/Firewall/Network or system to system, so it is very difficult to assume that you will also get the same error as mine. Check these links which help me to resolve some of the IIS issues in
 my work environment.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en/wcf/thread/b990d3ea-3335-40a6-877f-7c295da67a85"&gt;HTTP Error 500.19&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/eu/wcf/thread/39571e42-aca7-469d-8c68-aa59c2da4fcc"&gt;Could Not Load Type &amp;lsquo;System.ServiceModel.Activation.HttpModule&amp;rsquo;&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/k6h9cz8h.aspx"&gt;ASP.NET IIS Registration Tool&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms732012.aspx"&gt;ServiceModel Registration Tool&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step9"&gt;Step 9: Cross Domain Support&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The idea behind the Cross Domain Support comes when I try to remove all HTML pages from&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;solution and created a new Empty Web Application (Adventure.Website) which includes only&amp;nbsp;&lt;strong&gt;.html, .Js and .css&lt;/strong&gt;&amp;nbsp;files
 along with images. The structure for this application is as per below image:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/47.PNG" alt="Solution 1" width="300" height="500"&gt;&lt;/p&gt;
&lt;p&gt;Point all URL address to deployed code on IIS, after build and run application, output was null.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/48.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;To resolve this issue I would like to give my special thanks to Carlos&amp;rsquo; blog on MSDN&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2012/02/20/implementing-cors-support-in-asp-net-web-apis.aspx"&gt;Implementing CORS support in ASP.NET Web
 APIs&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;blockquote&gt;
&lt;div&gt;Quote:&lt;/div&gt;
&amp;ldquo;By default, a web page cannot make calls to services (APIs) on a domain other than the one where the page came from. This is a security measure against a group of cross-site forgery attacks in which browsing to a bad site could potentially use the browser
 cookies to get data from a good site which the user had previously logged on (think your bank). There are many situations, however, where getting data from different sites is a perfectly valid scenario, such as mash-up applications which need data from different
 sources.&amp;rdquo;&lt;/blockquote&gt;
&lt;h2&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;That's it !!! Hope you enjoy this article. I am not an expert, and also I have not followed the entire industry standard at the time of writing this article (time factor).&lt;/p&gt;
&lt;p&gt;All&amp;nbsp;&lt;strong&gt;comment/Vote&lt;/strong&gt;&amp;nbsp;are more than welcome&amp;hellip;. :), whenever, I get time, will try to modify this solution. You can also join/contribute to this project on&amp;nbsp;&lt;a href="http://pocwebapi.codeplex.com/"&gt;CodePlex&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Thank's for your time.&lt;/p&gt;
&lt;p&gt;Anand&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;br&gt;
&lt;/strong&gt;&lt;br&gt;
&lt;br&gt;
&lt;/p&gt;
&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>anandranjanpandey</author><pubDate>Thu, 22 Mar 2012 05:48:15 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20120322054815A</guid></item><item><title>Updated Wiki: Home</title><link>http://pocwebapi.codeplex.com/wikipage?version=3</link><description>&lt;div class="wikidoc"&gt;
&lt;h2&gt;&lt;strong&gt;Introduction&amp;nbsp;&lt;/strong&gt;&amp;nbsp;&lt;/h2&gt;
&lt;p&gt;The purpose of this article is to create a&lt;strong&gt;&amp;nbsp;proof of concept&amp;nbsp;&lt;/strong&gt;to demonstrate the feasibility of&amp;nbsp;&lt;a href="http://www.asp.net/web-api"&gt;ASP.NET WebAPI&lt;/a&gt;&amp;nbsp;Beta version.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Prerequisite:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://msftdbprodsamples.codeplex.com/"&gt;AdventureWorksLT2008R2&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://www.asp.net/web-api"&gt;ASP.Net WebAPI&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://code.google.com/p/autofac/downloads/list"&gt;Autofac for Dependency Injection&lt;/a&gt;&amp;nbsp;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://logging.apache.org/log4net/download.html"&gt;Log4Net&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://www.microsoft.com/download/en/details.aspx?displaylang=en&amp;id=8363"&gt;EntityFramework 4.1&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="https://github.com/jquery/jquery-tmpl"&gt;jQuery Templates plugin (jquery-tmpl)&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Goals to achieve:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Any user should be able to view products &lt;/li&gt;&lt;li&gt;Product would be filtered by Categories &lt;/li&gt;&lt;li&gt;User should be able to add products in cart &lt;/li&gt;&lt;li&gt;Only registered user will be able to submit cart &lt;/li&gt;&lt;li&gt;User should be able to register into system &lt;/li&gt;&lt;li&gt;User will get confirmation Invoice after generating order in system. &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Architecture for this POC&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;I am not following any specific Architecture Pattern, although while designing this POC, I&amp;nbsp;&lt;strong&gt;try to follow&lt;/strong&gt;&amp;nbsp;some of the key design principles like:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Separation_of_concerns"&gt;Separation of concerns&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Abstraction_(computer_science)"&gt;Abstraction&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself"&gt;Don't repeat yourself&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/KISS_principle"&gt;KISS principle&lt;/a&gt; &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Again I am repeating my word&amp;nbsp;&lt;strong&gt;try to follow&amp;hellip;.. :)&lt;/strong&gt;. So, all comments/suggestions are more than welcome to discuss and I am always ready to adopt changes, or you can do it yourself by join&amp;nbsp;&lt;a href="http://pocwebapi.codeplex.com/"&gt;@CodePlex&lt;/a&gt;.
 The initial Skeleton for this application is as per below diagram:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/1.PNG" alt="Architecture" width="650" height="500"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Step-by-Step&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/350488/A-simple-POC-using-ASP-NET-Web-API-Entity-Framewor#step1"&gt;Step 1: Create a basic Application Structure Layout&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/350488/A-simple-POC-using-ASP-NET-Web-API-Entity-Framewor#step2"&gt;Step 2: Create the Data Access Layer&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/350488/A-simple-POC-using-ASP-NET-Web-API-Entity-Framewor#step3"&gt;Step 3: Create the Service Layer&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/350488/A-simple-POC-using-ASP-NET-Web-API-Entity-Framewor#step4"&gt;Step 4: Create the API Layer&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/350488/A-simple-POC-using-ASP-NET-Web-API-Entity-Framewor#step5"&gt;Step 5: Integration of Dependency Injection using Autofac&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/350488/A-simple-POC-using-ASP-NET-Web-API-Entity-Framewor#step6"&gt;Step 6: Add Views to solution&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/350488/A-simple-POC-using-ASP-NET-Web-API-Entity-Framewor#step7"&gt;Step 7: Unit test and resolve issues&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/350488/A-simple-POC-using-ASP-NET-Web-API-Entity-Framewor#step8"&gt;Step 8: Deploy application on IIS&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/350488/A-simple-POC-using-ASP-NET-Web-API-Entity-Framewor#step9"&gt;Step 9: Provide Cross Domain Support&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step1"&gt;Step 1: Create a basic Application Structure Layout&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;For more information on ASP.NET WebAPI, watch Videos and Tutorials&amp;nbsp;&lt;a href="http://www.asp.net/web-api"&gt;here&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add a blank Solution named as&amp;nbsp;&lt;strong&gt;Application&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add a new Project (Class Library) named as&amp;nbsp;&lt;strong&gt;Application.DAL&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Repeat above process and create four more Class Library projects named as &amp;ndash;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Application.Model&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Repository&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Common&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Service&lt;/strong&gt; &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Now, application will look like below screen-shot&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/4.PNG" alt="Solution 1" width="250" height="350"&gt;&lt;/p&gt;
&lt;p&gt;Next, add a new Project named as&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;as ASP.Net MVC 4 Web Application. After click on OK, select template as Web API&lt;/p&gt;
&lt;p&gt;This will add a full functional Web API template Application into our main solution.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/7.PNG" alt="Solution 1" width="230" height="350"&gt;&lt;/p&gt;
&lt;p&gt;Right click on Application.API project in Solution Explorer and go to properties, than assign a port to be use by this service application ( In my case its 30000). Hit F5 and we are ready with a dummy data as below screen:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/8.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step2"&gt;Step 2: Prepare Application.DAL, Application.Repository and Application.Model Layers&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Check&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/library/bb399182.aspx"&gt;@MSDN&lt;/a&gt;&amp;nbsp;for more information on Entity Framework&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add Entity Data Model to&amp;nbsp;&lt;strong&gt;Application.DAL&lt;/strong&gt;&amp;nbsp;project. To do this select ADO.NET Entity Data Model from the Data Templates list, and name it as&amp;nbsp;&lt;strong&gt;AdventureWorks.edmx&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Choose&amp;nbsp;&lt;strong&gt;&amp;ldquo;Generate from Database&amp;rdquo;&lt;/strong&gt;&amp;nbsp;and provide the connection string to read the database schema. This will add AdventureWorks.edmx into current project. Right click on the blank space in Entity Model surface and click
 on properties (or alternate press Alt &amp;#43;Enter on keyboard). Now set its Code Generation Strategy as&amp;nbsp;&lt;strong&gt;None&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/10.PNG" alt="Solution 1" width="550" height="300"&gt;&lt;/p&gt;
&lt;p&gt;Now create POCO entities for AdventureWorks Data Model into&amp;nbsp;&lt;strong&gt;Application.Model&lt;/strong&gt;&amp;nbsp;Solution. Check this article to do this job for you on MSDN to use&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/gg558520"&gt;T4 Templates and the Entity
 Framework&lt;/a&gt;&lt;br&gt;
Then, create all required repositories under Application.Repositories.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/11.PNG" alt="Solution 1" width="250" height="500"&gt;&lt;/p&gt;
&lt;p&gt;To build solution, add reference of&amp;nbsp;&lt;strong&gt;Application.Model.dll&lt;/strong&gt;&amp;nbsp;to&amp;nbsp;&lt;strong&gt;Application.DAL.dll&lt;/strong&gt;&amp;nbsp;and&amp;nbsp;&lt;strong&gt;Application.Repository.dll&lt;/strong&gt;projects, and add reference of&amp;nbsp;&lt;strong&gt;Application.DAL.dll&lt;/strong&gt;&amp;nbsp;to&amp;nbsp;&lt;strong&gt;Application.Repository.dll&lt;/strong&gt;&amp;nbsp;project.
 (See below picture for reference)&lt;br&gt;
Before proceeding to next step (designing Application.Service and Application.API Layer), let us see what we have designed yet:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/12.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step3"&gt;Step 3: Add files to Application.Service Layer&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Before adding files to Service layer let us look at the Goals which we want to achieve.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Any user should be able to view products &lt;/li&gt;&lt;li&gt;Product would be filtered by Categories &lt;/li&gt;&lt;li&gt;User should be able to add products in cart &lt;/li&gt;&lt;li&gt;Only registered user will be able to submit cart &lt;/li&gt;&lt;li&gt;User should be able to register into system &lt;/li&gt;&lt;li&gt;User will get confirmation Invoice after generating order in system. &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To achieve the above mention Goals, we need to add three service classes to Application.Service as per below image&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/13.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/14.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;I am not going in deatils, as the implementation for each methods are clear and easy to understand.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step4"&gt;Step 4: Add files to Application.API Layer&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To make this Web API accessed from a broad range of clients like any browsers which use JavaScript or any windows/Mobile platform which supports .dll files, we need to add Controllers with base class as&amp;nbsp;&lt;strong&gt;ApiController&lt;/strong&gt;.&amp;nbsp;&lt;a href="http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api"&gt;More
 details here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;First, we remove the default controllers added by template (HomeController and ValuesController) and then add three new controllers as per below diagram:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/15.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;Again, nothing special in the implementation of these methods, they all jst push the data to service layer.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step5"&gt;Step 5: Integration of Dependency Injection with WebAPI using Autofac&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The implementation is very much straight forward and clear.&amp;nbsp;&lt;a href="http://alexmg.com/post/2012/03/08/Autofac-ASPNET-Web-API-%28Beta%29-Integration.aspx"&gt;Check Alex post here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;Solution Explorer, right-click the References node and click Manage NuGet Packages&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/16.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;It will open the below screen.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/17.PNG" alt="Solution 1" width="700" height="200"&gt;&lt;/p&gt;
&lt;p&gt;Click on install and it will add below three references in solution&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/18.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;Next, go to Global.asax.cs and create a method named as ResolveDependency()&lt;/p&gt;
&lt;pre id="pre0" lang="cs"&gt;             protected void ResolveDependancy()
                {
                    var configuration = GlobalConfiguration.Configuration;
                    var builder = new ContainerBuilder();

                    // Configure the container with the integration implementations.
                    builder.ConfigureWebApi(configuration);

                    // Register API controllers using assembly scanning.
                    builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

                    builder.RegisterType&amp;lt;logservice&amp;gt;().As&amp;lt;ilogservice&amp;gt;().InstancePerLifetimeScope();
                    builder.RegisterType&amp;lt;unitofwork&amp;gt;().As&amp;lt;iunitofwork&amp;gt;().InstancePerDependency();
                    builder.RegisterType&amp;lt;databasefactory&amp;gt;().As&amp;lt;idatabasefactory&amp;gt;().InstancePerLifetimeScope();
                    builder.RegisterAssemblyTypes(typeof(ProductService).Assembly)
                    .Where(t =&amp;gt; t.Name.EndsWith(&amp;quot;Service&amp;quot;))
                    .AsImplementedInterfaces().InstancePerDependency();
                    builder.RegisterAssemblyTypes(typeof(CustomerRepository).Assembly)
                    .Where(t =&amp;gt; t.Name.EndsWith(&amp;quot;Repository&amp;quot;))
                    .AsImplementedInterfaces().InstancePerDependency();      

                    var container = builder.Build();

                    // Set the dependency resolver implementation.
                    var resolver = new AutofacWebApiDependencyResolver(container);
                    configuration.ServiceResolver.SetResolver(resolver);
                }
            &amp;lt;/idatabasefactory&amp;gt;&amp;lt;/databasefactory&amp;gt;&amp;lt;/iunitofwork&amp;gt;&amp;lt;/unitofwork&amp;gt;&amp;lt;/ilogservice&amp;gt;&amp;lt;/logservice&amp;gt;&lt;/pre&gt;
&lt;p&gt;Now we are ready to test our application. Hit F5 and check the browser with following url&amp;rsquo;s:&amp;nbsp;&lt;br&gt;
http://localhost:30000/api/products : will result all Product Categories&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/20.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;http://localhost:30000/api/products/2 : will result all Products with ProductcategoryID as 2&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/21.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;To check other methods, First we will add some Views in current solution.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step6"&gt;Step 6: Add View to solution&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Delete all default files and folders from Views Folder, and add three Html and their supportive Javascript File as. For this POC we will use html files, and some jquery libraries like:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;jquery.tmpl.js :&lt;/strong&gt;&amp;nbsp;to create template based screen, and&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;jquery.validationEngine.js :&lt;/strong&gt;&amp;nbsp;to validate form data&lt;/p&gt;
&lt;p&gt;Now the structure will looks like below picture :&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/22.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;For details code in html and JS file please look into the code. In next step I am going to resolve problems.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step7"&gt;Step 7: Resolve issues&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Before run the application Right Click on Products.htm and click on Set As start Page. Now hit F5&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/23.PNG" alt="Solution 1" width="700" height="300"&gt;&lt;/p&gt;
&lt;p&gt;It means, two WebAPI methods in ProductsController.cs are working perfectly. In JavaScript, on page load we are calling first method inside&amp;nbsp;&lt;strong&gt;product.js&lt;/strong&gt;&amp;nbsp;as:&lt;/p&gt;
&lt;pre id="pre1" lang="js"&gt;                    var productcategoriesAddress = &amp;quot;/api/products/&amp;quot;;
                    $(function () {
                        $('#tblRight').hide();
                        $.getJSON(
                                productcategoriesAddress,
                                function (data) {
                                    var parents = jQuery.grep(data, function (a) { return a.ParentProductCategoryID == null });
                                    var childs = jQuery.grep(data, function (a) { return a.ParentProductCategoryID != null });
                                    $.each(parents,
                                        function (index, value) {
                                            var categorydata = [];
                                            var subCategory = '';
                                            var subChild = jQuery.grep(childs, function (a) { return a.ParentProductCategoryID == value.ProductCategoryID });
                                            $.each(subChild,
                                                function (index, item) {
                                                    var serviceURL = productcategoriesAddress &amp;#43; item.ProductCategoryID;
                                                    subCategory = subCategory &amp;#43; &amp;quot;  &amp;quot; &amp;#43; &amp;quot;&amp;lt;a href=&amp;quot;%20&amp;#43;%20serviceURL%20&amp;#43;%20&amp;quot; class=&amp;quot;menuButton&amp;quot;&amp;gt;&amp;quot; &amp;#43; item.Name &amp;#43; &amp;quot;&amp;lt;/a&amp;gt;&amp;quot;;
                                                });
                                            categorydata.push({
                                                'ProductCategoryID': value.ProductCategoryID,
                                                'ParentCategory': value.Name,
                                                'ChildCategory': subCategory
                                            });
                                            $(&amp;quot;#categoryTemplate&amp;quot;).tmpl(categorydata).appendTo(&amp;quot;#categories&amp;quot;);
                                            $(&amp;quot;#&amp;quot; &amp;#43; value.Name).html(subCategory);
                                        });

                                        GetProducts(1);
                                }
                            );
                &lt;/pre&gt;
&lt;p&gt;This call hits below method in ProductsController, and returns all Product Category to create the Upper Menu Part&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;pre id="pre2" lang="cs"&gt;                    public IQueryable&amp;lt;productcategory&amp;gt; GetProductCategories()
                    {
                        loggerService.Logger().Info(&amp;quot;Calling with null parameter&amp;quot;);
                        return _productservice.GetProductCategories().AsQueryable&amp;lt;productcategory&amp;gt;();
                    }
                &amp;lt;/productcategory&amp;gt;&amp;lt;/productcategory&amp;gt;&lt;/pre&gt;
&lt;p&gt;In ProductService implementation is :&lt;/p&gt;
&lt;pre id="pre3" lang="cs"&gt;                    public IQueryable&amp;lt;productcategory&amp;gt; GetProductCategories()
                    {
                        loggerService.Logger().Info(&amp;quot;Calling with null parameter&amp;quot;);
                        return _productservice.GetProductCategories().AsQueryable&amp;lt;productcategory&amp;gt;();
                    }
                &amp;lt;/productcategory&amp;gt;&amp;lt;/productcategory&amp;gt;&lt;/pre&gt;
&lt;p&gt;The second call is to fetch all products depends on selected category. In javascript&lt;/p&gt;
&lt;pre id="pre4" lang="js"&gt;                      function GetProducts(ProductCategoryID) {
                        var serviceURL = productcategoriesAddress &amp;#43; ProductCategoryID;
                        $('#categories li h1').css('background', '#736F6E');
                        $('#mnu' &amp;#43; ProductCategoryID).css('background', '#357EC7');
                        $(&amp;quot;#loader&amp;quot;).show();
                        $.ajax({
                            type: &amp;quot;GET&amp;quot;,
                            datatype: &amp;quot;json&amp;quot;,
                            url: serviceURL,
                            context: this,
                            success: function (value) {
                                $(&amp;quot;#productData&amp;quot;).html(&amp;quot;&amp;quot;);
                                $(&amp;quot;#productTemplate&amp;quot;).tmpl(value).appendTo(&amp;quot;#productData&amp;quot;);
                                $(&amp;quot;#loader&amp;quot;).hide();
                            }
                        });
                        return false;
                    }
                &lt;/pre&gt;
&lt;p&gt;and in ProductsController it goes to&lt;/p&gt;
&lt;pre id="pre5" lang="cs"&gt;                    public IQueryable&amp;lt;product&amp;gt; GetProductByProductCategoryID(int id)
                    {
                        loggerService.Logger().Info(&amp;quot;Calling with null parameter as : id : &amp;quot; &amp;#43; id);
                        return _productservice.GetProductByProductCategoryID(id).AsQueryable&amp;lt;product&amp;gt;();
                    }

                &amp;lt;/product&amp;gt;&amp;lt;/product&amp;gt;&lt;/pre&gt;
&lt;p&gt;In ProductService implementation is :&lt;/p&gt;
&lt;pre id="pre6" lang="cs"&gt;                    public IQueryable&amp;lt;product&amp;gt; GetProductByProductCategoryID(int id)
                    {
                        loggerService.Logger().Info(&amp;quot;Calling with null parameter as : id : &amp;quot; &amp;#43; id);
                        return _productservice.GetProductByProductCategoryID(id).AsQueryable&amp;lt;product&amp;gt;();
                    }
                &amp;lt;/product&amp;gt;&amp;lt;/product&amp;gt;&lt;/pre&gt;
&lt;p&gt;Next, let us try to add some products to Cart and Checkout cart&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/28.PNG" alt="Solution 1" width="400" height="300"&gt;&lt;/p&gt;
&lt;p&gt;On clicking on checkout It redirect to Checkout.htm page and asking for either Login using existing CustomerID or Register for a new Customer.&lt;br&gt;
Click on&amp;nbsp;&lt;strong&gt;Register&lt;/strong&gt;&amp;nbsp;link to create a new Customer.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/29.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;Submit form after clicking on Register button and see if Posting is working or not. Again its success!!!&lt;/p&gt;
&lt;p&gt;Now we will try to update records for AddressLine2, and Update is also working fine!!!&lt;/p&gt;
&lt;p&gt;In both scenario (Add or Update Customer) we are calling below method of CutomerControllers.cs&lt;/p&gt;
&lt;pre id="pre7" lang="cs"&gt;                     public int PostCustomer(CustomerDTO customer)
                    {
                        loggerService.Logger().Info(&amp;quot;Calling with parameter as : customer: &amp;quot; &amp;#43; customer);
                        return _customerService.SaveOrUpdateCustomer(customer);
                    }
                &lt;/pre&gt;
&lt;p&gt;In CustomerService implementation is :&lt;/p&gt;
&lt;pre id="pre8" lang="cs"&gt;                    public int SaveOrUpdateCustomer(CustomerDTO customer)
                    {
                        string passwordSalt = CreateSalt(5);
                        string pasword = CreatePasswordHash(customer.Password, passwordSalt);
                        Customer objCustomer;

                        if (customer.CustomerID != 0)
                            objCustomer = _customerRepository.GetById(customer.CustomerID);
                        else
                            objCustomer = new Customer();

                        objCustomer.NameStyle = customer.NameStyle;
                        objCustomer.Title = customer.Title;
                        objCustomer.FirstName = customer.FirstName;
                        objCustomer.MiddleName = customer.MiddleName;
                        objCustomer.LastName = customer.LastName;
                        objCustomer.Suffix = customer.Suffix;
                        objCustomer.CompanyName = customer.CompanyName;
                        objCustomer.SalesPerson = customer.SalesPerson;
                        objCustomer.EmailAddress = customer.EmailAddress;
                        objCustomer.Phone = customer.Phone;
                        objCustomer.PasswordHash = pasword;
                        objCustomer.PasswordSalt = passwordSalt;
                        objCustomer.ModifiedDate = DateTime.Now;
                        objCustomer.rowguid = Guid.NewGuid();

                        if (customer.CustomerID != 0)
                            _customerRepository.Update(objCustomer);
                        else
                            _customerRepository.Add(objCustomer);

                        _unitOfWork.Commit();
                        SaveOrUpdateAddress(customer, objCustomer.CustomerID);
                        return objCustomer.CustomerID;
                    }
                &lt;/pre&gt;
&lt;p&gt;Next, click on Submit Order Button, to make previously selected products as an Order and receive Order Invoice.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/33.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;!!!Hurray!!! Order is created in system and invoice is generated with a new Purchase Order. But, wait we got one BUG&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue 1:&lt;/strong&gt;&amp;nbsp;we have an issue with Date Format.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/34.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;According to,&amp;nbsp;&lt;a href="http://www.hanselman.com/blog/OnTheNightmareThatIsJSONDatesPlusJSONNETAndASPNETWebAPI.aspx"&gt;Scott Hanselman&amp;rsquo;s post&lt;/a&gt;&amp;nbsp;this is a bug and will resolve in next release of ASP.Net WebAPI. This issue is resolved using&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/02/18/using-json-net-with-asp-net-web-api.aspx"&gt;solution
 provided in Henrik's Blog&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/35.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue 2:&lt;/strong&gt;&amp;nbsp;Another issue was, when I try to Checkout Cart using the last created Customer. The error was:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/36.PNG" alt="Solution 1" width="700" height="300"&gt;&lt;/p&gt;
&lt;p&gt;After looking this error, first thought comes that we missed the method in CustomersController.cs, but the method was already there. Further investigation make it clear, that, the reason behind this error was name of this method as ValidateCustomer():&lt;/p&gt;
&lt;pre id="pre9" lang="cs"&gt;                     public CustomerDTO ValidateCustomer(int id, string password)
                    {
                        loggerService.Logger().Info(&amp;quot;Calling with parameter as : id and password: &amp;quot; &amp;#43; id &amp;#43; &amp;quot; and &amp;quot; &amp;#43; password);
                        return _customerService.ValidateCustomer(id, password);
                    }
                &lt;/pre&gt;
&lt;p&gt;In CustomerService implementation is :&lt;/p&gt;
&lt;pre id="pre10" lang="cs"&gt;                    public CustomerDTO ValidateCustomer(int id, string password)
                    {
                        Customer objCustomer = _customerRepository.GetById(id);
                        if (objCustomer == null)
                            return null;
                        string strPasswordHash = objCustomer.PasswordHash;
                        string strPasswordSalt = strPasswordHash.Substring(strPasswordHash.Length - 8);
                        string strPasword = CreatePasswordHash(password, strPasswordSalt);

                        if (strPasword.Equals(strPasswordHash))
                            return CreateCustomerDTO(objCustomer);
                        else
                            return null;
                    }
                &lt;/pre&gt;
&lt;p&gt;By default the&amp;nbsp;&lt;strong&gt;route configuration&lt;/strong&gt;&amp;nbsp;of Asp.Net WebAPI follows RESTFUL conventions meaning that it will accept only the&amp;nbsp;&lt;strong&gt;Get, Post, Put and Delete&lt;/strong&gt;&amp;nbsp;action names. So when we send a GET request to http://localhost:30000/api/customers/ValidateCustomer/30135/test
 we are basically calling the Get(int id) action and passing id=30135 which obviously crashes because we don&amp;rsquo;t have any method starting with Get which accept Id as parameter. To resolve this issue I need to add a new route definition in&amp;nbsp;&lt;strong&gt;Global.asax&lt;/strong&gt;&amp;nbsp;file
 as:&lt;/p&gt;
&lt;pre id="pre11" lang="cs"&gt;                     routes.MapHttpRoute(
                           name: &amp;quot;ValidateCustomer&amp;quot;,
                           routeTemplate: &amp;quot;api/{controller}/{action}/{id}/{password}&amp;quot;,
                           defaults: new { action = &amp;quot;get&amp;quot; }
                       );
                &lt;/pre&gt;
&lt;p&gt;Adding this line done the magic and Login functinality start waorking&amp;hellip;. :)&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step8"&gt;Step 8: Deploy on IIS&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;To deploy this API on IIS version 7.5, first, publish only&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;solution to a Folder.&lt;/p&gt;
&lt;p&gt;Next, open IIS Manager and create a new website and set path to Publish folder, and we are done with deployment.&lt;/p&gt;
&lt;p&gt;Now, check whether page is opening or not, in my case, initially I got below error, which is self-explanatory.&lt;br&gt;
The error comes because this application is running on Asp.Net Framework Version 2.0. So, we need to change it to Asp.Net Framework Version 4.0:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/40.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/41.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;To change the Asp.Net Framework from 2.0 to 4.0, follow below steps.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/42.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/43.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;That was not the only reason not to run application, because after made above change in Application pool next error was:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/44.PNG" alt="Solution 1" width="700" height="200"&gt;&lt;/p&gt;
&lt;p&gt;To resolve this error again go to Advance Settings of Application pool and change the identity to Local System from ApplicationPoolIdentity&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/45.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;After modify the Application pool to use Local System, Application starts working on browser... :)&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/46.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;Although IIS errors are depending on servers/Firewall/Network or system to system, so it is very difficult to assume that you will also get the same error as mine. Check these links which help me to resolve some of the IIS issues in
 my work environment.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en/wcf/thread/b990d3ea-3335-40a6-877f-7c295da67a85"&gt;HTTP Error 500.19&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/eu/wcf/thread/39571e42-aca7-469d-8c68-aa59c2da4fcc"&gt;Could Not Load Type &amp;lsquo;System.ServiceModel.Activation.HttpModule&amp;rsquo;&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/k6h9cz8h.aspx"&gt;ASP.NET IIS Registration Tool&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms732012.aspx"&gt;ServiceModel Registration Tool&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step9"&gt;Step 9: Cross Domain Support&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The idea behind the Cross Domain Support comes when I try to remove all HTML pages from&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;solution and created a new Empty Web Application (Adventure.Website) which includes only&amp;nbsp;&lt;strong&gt;.html, .Js and .css&lt;/strong&gt;&amp;nbsp;files
 along with images. The structure for this application is as per below image:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/47.PNG" alt="Solution 1" width="300" height="500"&gt;&lt;/p&gt;
&lt;p&gt;Point all URL address to deployed code on IIS, after build and run application, output was null.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/48.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;To resolve this issue I would like to give my special thanks to Carlos&amp;rsquo; blog on MSDN&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2012/02/20/implementing-cors-support-in-asp-net-web-apis.aspx"&gt;Implementing CORS support in ASP.NET Web
 APIs&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;blockquote&gt;
&lt;div&gt;Quote:&lt;/div&gt;
&amp;ldquo;By default, a web page cannot make calls to services (APIs) on a domain other than the one where the page came from. This is a security measure against a group of cross-site forgery attacks in which browsing to a bad site could potentially use the browser
 cookies to get data from a good site which the user had previously logged on (think your bank). There are many situations, however, where getting data from different sites is a perfectly valid scenario, such as mash-up applications which need data from different
 sources.&amp;rdquo;&lt;/blockquote&gt;
&lt;h2&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;That's it !!! Hope you enjoy this article. I am not an expert, and also I have not followed the entire industry standard at the time of writing this article (time factor).&lt;/p&gt;
&lt;p&gt;All&amp;nbsp;&lt;strong&gt;comment/Vote&lt;/strong&gt;&amp;nbsp;are more than welcome&amp;hellip;. :), whenever, I get time, will try to modify this solution. You can also join/contribute to this project on&amp;nbsp;&lt;a href="http://pocwebapi.codeplex.com/"&gt;CodePlex&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Thank's for your time.&lt;/p&gt;
&lt;p&gt;Anand&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;br&gt;
&lt;/strong&gt;&lt;br&gt;
&lt;br&gt;
&lt;/p&gt;
&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>anandranjanpandey</author><pubDate>Thu, 22 Mar 2012 05:46:03 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20120322054603A</guid></item><item><title>Updated Wiki: Documentation</title><link>http://pocwebapi.codeplex.com/documentation?version=2</link><description>&lt;div class="wikidoc"&gt;
&lt;h2&gt;&lt;strong&gt;Introduction&amp;nbsp;&lt;/strong&gt;&amp;nbsp;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The purpose of this article is to create a&lt;strong&gt;&amp;nbsp;proof of concept&amp;nbsp;&lt;/strong&gt;to demonstrate the feasibility of&amp;nbsp;&lt;a href="http://www.asp.net/web-api"&gt;ASP.NET WebAPI&lt;/a&gt;&amp;nbsp;Beta version.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Prerequisite:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://msftdbprodsamples.codeplex.com/"&gt;AdventureWorksLT2008R2&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://www.asp.net/web-api"&gt;ASP.Net WebAPI&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://code.google.com/p/autofac/downloads/list"&gt;Autofac for Dependency Injection&lt;/a&gt;&amp;nbsp;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://logging.apache.org/log4net/download.html"&gt;Log4Net&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://www.microsoft.com/download/en/details.aspx?displaylang=en&amp;id=8363"&gt;EntityFramework 4.1&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="https://github.com/jquery/jquery-tmpl"&gt;jQuery Templates plugin (jquery-tmpl)&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Goals to achieve:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Any user should be able to view products &lt;/li&gt;&lt;li&gt;Product would be filtered by Categories &lt;/li&gt;&lt;li&gt;User should be able to add products in cart &lt;/li&gt;&lt;li&gt;Only registered user will be able to submit cart &lt;/li&gt;&lt;li&gt;User should be able to register into system &lt;/li&gt;&lt;li&gt;User will get confirmation Invoice after generating order in system. &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Architecture for this POC&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I am not following any specific Architecture Pattern, although while designing this POC, I&amp;nbsp;&lt;strong&gt;try to follow&lt;/strong&gt;&amp;nbsp;some of the key design principles like:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Separation_of_concerns"&gt;Separation of concerns&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Abstraction_(computer_science)"&gt;Abstraction&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself"&gt;Don't repeat yourself&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/KISS_principle"&gt;KISS principle&lt;/a&gt; &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;span&gt;Again I am repeating my word&amp;nbsp;&lt;strong&gt;try to follow&amp;hellip;.. :)&lt;/strong&gt;. So, all comments/suggestions are more than welcome to discuss and I am always ready to adopt changes, or you can do it yourself by join&amp;nbsp;&lt;a href="http://pocwebapi.codeplex.com/"&gt;@CodePlex&lt;/a&gt;.
 The initial Skeleton for this application is as per below diagram:&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/1.PNG" alt="Architecture" width="650" height="500"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Step-by-Step&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/350488/A-simple-POC-using-ASP-NET-Web-API-Entity-Framewor#step1"&gt;Step 1: Create a basic Application Structure Layout&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/350488/A-simple-POC-using-ASP-NET-Web-API-Entity-Framewor#step2"&gt;Step 2: Create the Data Access Layer&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/350488/A-simple-POC-using-ASP-NET-Web-API-Entity-Framewor#step3"&gt;Step 3: Create the Service Layer&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/350488/A-simple-POC-using-ASP-NET-Web-API-Entity-Framewor#step4"&gt;Step 4: Create the API Layer&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/350488/A-simple-POC-using-ASP-NET-Web-API-Entity-Framewor#step5"&gt;Step 5: Integration of Dependency Injection using Autofac&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/350488/A-simple-POC-using-ASP-NET-Web-API-Entity-Framewor#step6"&gt;Step 6: Add Views to solution&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/350488/A-simple-POC-using-ASP-NET-Web-API-Entity-Framewor#step7"&gt;Step 7: Unit test and resolve issues&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/350488/A-simple-POC-using-ASP-NET-Web-API-Entity-Framewor#step8"&gt;Step 8: Deploy application on IIS&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/350488/A-simple-POC-using-ASP-NET-Web-API-Entity-Framewor#step9"&gt;Step 9: Provide Cross Domain Support&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step1"&gt;Step 1: Create a basic Application Structure Layout&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;For more information on ASP.NET WebAPI, watch Videos and Tutorials&amp;nbsp;&lt;a href="http://www.asp.net/web-api"&gt;here&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add a blank Solution named as&amp;nbsp;&lt;strong&gt;Application&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add a new Project (Class Library) named as&amp;nbsp;&lt;strong&gt;Application.DAL&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Repeat above process and create four more Class Library projects named as &amp;ndash;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Application.Model&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Repository&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Common&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Service&lt;/strong&gt; &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;span&gt;Now, application will look like below screen-shot&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/4.PNG" alt="Solution 1" width="250" height="350"&gt;&lt;/p&gt;
&lt;p&gt;Next, add a new Project named as&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;as ASP.Net MVC 4 Web Application. After click on OK, select template as Web API&lt;/p&gt;
&lt;p&gt;&lt;span&gt;This will add a full functional Web API template Application into our main solution.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/7.PNG" alt="Solution 1" width="230" height="350"&gt;&lt;/p&gt;
&lt;p&gt;Right click on Application.API project in Solution Explorer and go to properties, than assign a port to be use by this service application ( In my case its 30000). Hit F5 and we are ready with a dummy data as below screen:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/8.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step2"&gt;Step 2: Prepare Application.DAL, Application.Repository and Application.Model Layers&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Check&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/library/bb399182.aspx"&gt;@MSDN&lt;/a&gt;&amp;nbsp;for more information on Entity Framework&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add Entity Data Model to&amp;nbsp;&lt;strong&gt;Application.DAL&lt;/strong&gt;&amp;nbsp;project. To do this select ADO.NET Entity Data Model from the Data Templates list, and name it as&amp;nbsp;&lt;strong&gt;AdventureWorks.edmx&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Choose&amp;nbsp;&lt;strong&gt;&amp;ldquo;Generate from Database&amp;rdquo;&lt;/strong&gt;&amp;nbsp;and provide the connection string to read the database schema. This will add AdventureWorks.edmx into current project. Right click on the blank space in Entity Model surface and click
 on properties (or alternate press Alt &amp;#43;Enter on keyboard). Now set its Code Generation Strategy as&amp;nbsp;&lt;strong&gt;None&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/10.PNG" alt="Solution 1" width="550" height="300"&gt;&lt;/p&gt;
&lt;p&gt;Now create POCO entities for AdventureWorks Data Model into&amp;nbsp;&lt;strong&gt;Application.Model&lt;/strong&gt;&amp;nbsp;Solution. Check this article to do this job for you on MSDN to use&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/gg558520"&gt;T4 Templates and the Entity
 Framework&lt;/a&gt;&lt;br&gt;
Then, create all required repositories under Application.Repositories.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/11.PNG" alt="Solution 1" width="250" height="500"&gt;&lt;/p&gt;
&lt;p&gt;To build solution, add reference of&amp;nbsp;&lt;strong&gt;Application.Model.dll&lt;/strong&gt;&amp;nbsp;to&amp;nbsp;&lt;strong&gt;Application.DAL.dll&lt;/strong&gt;&amp;nbsp;and&amp;nbsp;&lt;strong&gt;Application.Repository.dll&lt;/strong&gt;projects, and add reference of&amp;nbsp;&lt;strong&gt;Application.DAL.dll&lt;/strong&gt;&amp;nbsp;to&amp;nbsp;&lt;strong&gt;Application.Repository.dll&lt;/strong&gt;&amp;nbsp;project.
 (See below picture for reference)&lt;br&gt;
Before proceeding to next step (designing Application.Service and Application.API Layer), let us see what we have designed yet:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/12.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step3"&gt;Step 3: Add files to Application.Service Layer&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Before adding files to Service layer let us look at the Goals which we want to achieve.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Any user should be able to view products &lt;/li&gt;&lt;li&gt;Product would be filtered by Categories &lt;/li&gt;&lt;li&gt;User should be able to add products in cart &lt;/li&gt;&lt;li&gt;Only registered user will be able to submit cart &lt;/li&gt;&lt;li&gt;User should be able to register into system &lt;/li&gt;&lt;li&gt;User will get confirmation Invoice after generating order in system. &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To achieve the above mention Goals, we need to add three service classes to Application.Service as per below image&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/13.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/14.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;I am not going in deatils, as the implementation for each methods are clear and easy to understand.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step4"&gt;Step 4: Add files to Application.API Layer&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To make this Web API accessed from a broad range of clients like any browsers which use JavaScript or any windows/Mobile platform which supports .dll files, we need to add Controllers with base class as&amp;nbsp;&lt;strong&gt;ApiController&lt;/strong&gt;.&amp;nbsp;&lt;a href="http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api"&gt;More
 details here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;First, we remove the default controllers added by template (HomeController and ValuesController) and then add three new controllers as per below diagram:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/15.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;Again, nothing special in the implementation of these methods, they all jst push the data to service layer.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step5"&gt;Step 5: Integration of Dependency Injection with WebAPI using Autofac&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The implementation is very much straight forward and clear.&amp;nbsp;&lt;a href="http://alexmg.com/post/2012/03/08/Autofac-ASPNET-Web-API-%28Beta%29-Integration.aspx"&gt;Check Alex post here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;Solution Explorer, right-click the References node and click Manage NuGet Packages&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/16.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;It will open the below screen.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/17.PNG" alt="Solution 1" width="700" height="200"&gt;&lt;/p&gt;
&lt;p&gt;Click on install and it will add below three references in solution&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/18.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;Next, go to Global.asax.cs and create a method named as ResolveDependency()&lt;/p&gt;
&lt;div id="premain0"&gt;&lt;/div&gt;
&lt;pre id="pre0" lang="cs"&gt;             &lt;span&gt;protected&lt;/span&gt; &lt;span&gt;void&lt;/span&gt; ResolveDependancy()
                {
                    &lt;span&gt;var&lt;/span&gt; configuration = GlobalConfiguration.Configuration;
                    &lt;span&gt;var&lt;/span&gt; builder = &lt;span&gt;new&lt;/span&gt; ContainerBuilder();

                    &lt;span&gt;//&lt;/span&gt;&lt;span&gt; Configure the container with the integration implementations.
&lt;/span&gt;                    builder.ConfigureWebApi(configuration);

                    &lt;span&gt;//&lt;/span&gt;&lt;span&gt; Register API controllers using assembly scanning.
&lt;/span&gt;                    builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

                    builder.RegisterType&amp;lt;logservice&amp;gt;().As&amp;lt;ilogservice&amp;gt;().InstancePerLifetimeScope();
                    builder.RegisterType&amp;lt;unitofwork&amp;gt;().As&amp;lt;iunitofwork&amp;gt;().InstancePerDependency();
                    builder.RegisterType&amp;lt;databasefactory&amp;gt;().As&amp;lt;idatabasefactory&amp;gt;().InstancePerLifetimeScope();
                    builder.RegisterAssemblyTypes(&lt;span&gt;typeof&lt;/span&gt;(ProductService).Assembly)
                    .Where(t =&amp;gt; t.Name.EndsWith(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Service&amp;quot;&lt;/span&gt;))
                    .AsImplementedInterfaces().InstancePerDependency();
                    builder.RegisterAssemblyTypes(&lt;span&gt;typeof&lt;/span&gt;(CustomerRepository).Assembly)
                    .Where(t =&amp;gt; t.Name.EndsWith(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Repository&amp;quot;&lt;/span&gt;))
                    .AsImplementedInterfaces().InstancePerDependency();      

                    &lt;span&gt;var&lt;/span&gt; container = builder.Build();

                    &lt;span&gt;//&lt;/span&gt;&lt;span&gt; Set the dependency resolver implementation.
&lt;/span&gt;                    &lt;span&gt;var&lt;/span&gt; resolver = &lt;span&gt;new&lt;/span&gt; AutofacWebApiDependencyResolver(container);
                    configuration.ServiceResolver.SetResolver(resolver);
                }
            &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;idatabasefactory&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;databasefactory&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;iunitofwork&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;unitofwork&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;ilogservice&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;logservice&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Now we are ready to test our application. Hit F5 and check the browser with following url&amp;rsquo;s:&amp;nbsp;&lt;br&gt;
http://localhost:30000/api/products : will result all Product Categories&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/20.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;http://localhost:30000/api/products/2 : will result all Products with ProductcategoryID as 2&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/21.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;To check other methods, First we will add some Views in current solution.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step6"&gt;Step 6: Add View to solution&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Delete all default files and folders from Views Folder, and add three Html and their supportive Javascript File as. For this POC we will use html files, and some jquery libraries like:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;jquery.tmpl.js :&lt;/strong&gt;&amp;nbsp;to create template based screen, and&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;jquery.validationEngine.js :&lt;/strong&gt;&amp;nbsp;to validate form data&lt;/p&gt;
&lt;p&gt;Now the structure will looks like below picture :&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/22.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;For details code in html and JS file please look into the code. In next step I am going to resolve problems.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step7"&gt;Step 7: Resolve issues&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Before run the application Right Click on Products.htm and click on Set As start Page. Now hit F5&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/23.PNG" alt="Solution 1" width="700" height="300"&gt;&lt;/p&gt;
&lt;p&gt;It means, two WebAPI methods in ProductsController.cs are working perfectly. In JavaScript, on page load we are calling first method inside&amp;nbsp;&lt;strong&gt;product.js&lt;/strong&gt;&amp;nbsp;as:&lt;/p&gt;
&lt;pre id="pre1" lang="js"&gt;                    var productcategoriesAddress = &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;/api/products/&amp;quot;&lt;/span&gt;;
                    $(function () {
                        $(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;#tblRight'&lt;/span&gt;).hide();
                        $.getJSON(
                                productcategoriesAddress,
                                function (data) {
                                    var parents = jQuery.grep(data, function (a) { &lt;span&gt;return&lt;/span&gt; a.ParentProductCategoryID == null });
                                    var childs = jQuery.grep(data, function (a) { &lt;span&gt;return&lt;/span&gt; a.ParentProductCategoryID != null });
                                    $.&lt;span&gt;each&lt;/span&gt;(parents,
                                        function (index, &lt;span&gt;value&lt;/span&gt;) {
                                            var categorydata = [];
                                            var subCategory = &lt;span&gt;'&lt;/span&gt;&lt;span&gt;'&lt;/span&gt;;
                                            var subChild = jQuery.grep(childs, function (a) { &lt;span&gt;return&lt;/span&gt; a.ParentProductCategoryID == &lt;span&gt;value&lt;/span&gt;.ProductCategoryID });
                                            $.&lt;span&gt;each&lt;/span&gt;(subChild,
                                                function (index, item) {
                                                    var serviceURL = productcategoriesAddress &amp;#43; item.ProductCategoryID;
                                                    subCategory = subCategory &amp;#43; &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;  &amp;quot;&lt;/span&gt; &amp;#43; &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;lt;a href=&amp;quot;&lt;/span&gt;%20&amp;#43;%20serviceURL%20&amp;#43;%20&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt; class=&amp;quot;&lt;/span&gt;menuButton&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;gt;&amp;quot;&lt;/span&gt; &amp;#43; item.Name &amp;#43; &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;lt;/a&amp;gt;&amp;quot;&lt;/span&gt;;
                                                });
                                            categorydata.push({
                                                &lt;span&gt;'&lt;/span&gt;&lt;span&gt;ProductCategoryID'&lt;/span&gt;: &lt;span&gt;value&lt;/span&gt;.ProductCategoryID,
                                                &lt;span&gt;'&lt;/span&gt;&lt;span&gt;ParentCategory'&lt;/span&gt;: &lt;span&gt;value&lt;/span&gt;.Name,
                                                &lt;span&gt;'&lt;/span&gt;&lt;span&gt;ChildCategory'&lt;/span&gt;: subCategory
                                            });
                                            $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#categoryTemplate&amp;quot;&lt;/span&gt;).tmpl(categorydata).appendTo(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#categories&amp;quot;&lt;/span&gt;);
                                            $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#&amp;quot;&lt;/span&gt; &amp;#43; &lt;span&gt;value&lt;/span&gt;.Name).html(subCategory);
                                        });

                                        GetProducts(&lt;span&gt;1&lt;/span&gt;);
                                }
                            );
                &lt;/pre&gt;
&lt;p&gt;This call hits below method in ProductsController, and returns all Product Category to create the Upper Menu Part&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;pre id="pre2" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; IQueryable&amp;lt;productcategory&amp;gt; GetProductCategories()
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with null parameter&amp;quot;&lt;/span&gt;);
                        &lt;span&gt;return&lt;/span&gt; _productservice.GetProductCategories().AsQueryable&amp;lt;productcategory&amp;gt;();
                    }
                &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;productcategory&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;productcategory&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;In ProductService implementation is :&lt;/p&gt;
&lt;pre id="pre3" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; IQueryable&amp;lt;productcategory&amp;gt; GetProductCategories()
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with null parameter&amp;quot;&lt;/span&gt;);
                        &lt;span&gt;return&lt;/span&gt; _productservice.GetProductCategories().AsQueryable&amp;lt;productcategory&amp;gt;();
                    }
                &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;productcategory&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;productcategory&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;The second call is to fetch all products depends on selected category. In javascript&lt;/p&gt;
&lt;pre id="pre4" lang="js"&gt;                      function GetProducts(ProductCategoryID) {
                        var serviceURL = productcategoriesAddress &amp;#43; ProductCategoryID;
                        $(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;#categories li h1'&lt;/span&gt;).css(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;background'&lt;/span&gt;, &lt;span&gt;'&lt;/span&gt;&lt;span&gt;#736F6E'&lt;/span&gt;);
                        $(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;#mnu'&lt;/span&gt; &amp;#43; ProductCategoryID).css(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;background'&lt;/span&gt;, &lt;span&gt;'&lt;/span&gt;&lt;span&gt;#357EC7'&lt;/span&gt;);
                        $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#loader&amp;quot;&lt;/span&gt;).show();
                        $.ajax({
                            type: &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;GET&amp;quot;&lt;/span&gt;,
                            datatype: &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;json&amp;quot;&lt;/span&gt;,
                            url: serviceURL,
                            context: &lt;span&gt;this&lt;/span&gt;,
                            success: function (&lt;span&gt;value&lt;/span&gt;) {
                                $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#productData&amp;quot;&lt;/span&gt;).html(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;quot;&lt;/span&gt;);
                                $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#productTemplate&amp;quot;&lt;/span&gt;).tmpl(&lt;span&gt;value&lt;/span&gt;).appendTo(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#productData&amp;quot;&lt;/span&gt;);
                                $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#loader&amp;quot;&lt;/span&gt;).hide();
                            }
                        });
                        &lt;span&gt;return&lt;/span&gt; &lt;span&gt;false&lt;/span&gt;;
                    }
                &lt;/pre&gt;
&lt;p&gt;and in ProductsController it goes to&lt;/p&gt;
&lt;pre id="pre5" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; IQueryable&amp;lt;product&amp;gt; GetProductByProductCategoryID(&lt;span&gt;int&lt;/span&gt; id)
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with null parameter as : id : &amp;quot;&lt;/span&gt; &amp;#43; id);
                        &lt;span&gt;return&lt;/span&gt; _productservice.GetProductByProductCategoryID(id).AsQueryable&amp;lt;product&amp;gt;();
                    }

                &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;product&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;product&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;In ProductService implementation is :&lt;/p&gt;
&lt;pre id="pre6" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; IQueryable&amp;lt;product&amp;gt; GetProductByProductCategoryID(&lt;span&gt;int&lt;/span&gt; id)
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with null parameter as : id : &amp;quot;&lt;/span&gt; &amp;#43; id);
                        &lt;span&gt;return&lt;/span&gt; _productservice.GetProductByProductCategoryID(id).AsQueryable&amp;lt;product&amp;gt;();
                    }
                &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;product&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;product&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Next, let us try to add some products to Cart and Checkout cart&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/28.PNG" alt="Solution 1" width="400" height="300"&gt;&lt;/p&gt;
&lt;p&gt;On clicking on checkout It redirect to Checkout.htm page and asking for either Login using existing CustomerID or Register for a new Customer.&lt;br&gt;
Click on&amp;nbsp;&lt;strong&gt;Register&lt;/strong&gt;&amp;nbsp;link to create a new Customer.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/29.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;Submit form after clicking on Register button and see if Posting is working or not. Again its success!!!&lt;/p&gt;
&lt;p&gt;Now we will try to update records for AddressLine2, and Update is also working fine!!!&lt;/p&gt;
&lt;p&gt;In both scenario (Add or Update Customer) we are calling below method of CutomerControllers.cs&lt;/p&gt;
&lt;pre id="pre7" lang="cs"&gt;                     &lt;span&gt;public&lt;/span&gt; &lt;span&gt;int&lt;/span&gt; PostCustomer(CustomerDTO customer)
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with parameter as : customer: &amp;quot;&lt;/span&gt; &amp;#43; customer);
                        &lt;span&gt;return&lt;/span&gt; _customerService.SaveOrUpdateCustomer(customer);
                    }
                &lt;/pre&gt;
&lt;p&gt;In CustomerService implementation is :&lt;/p&gt;
&lt;pre id="pre8" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;int&lt;/span&gt; SaveOrUpdateCustomer(CustomerDTO customer)
                    {
                        &lt;span&gt;string&lt;/span&gt; passwordSalt = CreateSalt(&lt;span&gt;5&lt;/span&gt;);
                        &lt;span&gt;string&lt;/span&gt; pasword = CreatePasswordHash(customer.Password, passwordSalt);
                        Customer objCustomer;

                        &lt;span&gt;if&lt;/span&gt; (customer.CustomerID != &lt;span&gt;0&lt;/span&gt;)
                            objCustomer = _customerRepository.GetById(customer.CustomerID);
                        &lt;span&gt;else&lt;/span&gt;
                            objCustomer = &lt;span&gt;new&lt;/span&gt; Customer();

                        objCustomer.NameStyle = customer.NameStyle;
                        objCustomer.Title = customer.Title;
                        objCustomer.FirstName = customer.FirstName;
                        objCustomer.MiddleName = customer.MiddleName;
                        objCustomer.LastName = customer.LastName;
                        objCustomer.Suffix = customer.Suffix;
                        objCustomer.CompanyName = customer.CompanyName;
                        objCustomer.SalesPerson = customer.SalesPerson;
                        objCustomer.EmailAddress = customer.EmailAddress;
                        objCustomer.Phone = customer.Phone;
                        objCustomer.PasswordHash = pasword;
                        objCustomer.PasswordSalt = passwordSalt;
                        objCustomer.ModifiedDate = DateTime.Now;
                        objCustomer.rowguid = Guid.NewGuid();

                        &lt;span&gt;if&lt;/span&gt; (customer.CustomerID != &lt;span&gt;0&lt;/span&gt;)
                            _customerRepository.Update(objCustomer);
                        &lt;span&gt;else&lt;/span&gt;
                            _customerRepository.Add(objCustomer);

                        _unitOfWork.Commit();
                        SaveOrUpdateAddress(customer, objCustomer.CustomerID);
                        &lt;span&gt;return&lt;/span&gt; objCustomer.CustomerID;
                    }
                &lt;/pre&gt;
&lt;p&gt;Next, click on Submit Order Button, to make previously selected products as an Order and receive Order Invoice.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/33.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;!!!Hurray!!! Order is created in system and invoice is generated with a new Purchase Order. But, wait we got one BUG&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue 1:&lt;/strong&gt;&amp;nbsp;we have an issue with Date Format.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/34.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;According to,&amp;nbsp;&lt;a href="http://www.hanselman.com/blog/OnTheNightmareThatIsJSONDatesPlusJSONNETAndASPNETWebAPI.aspx"&gt;Scott Hanselman&amp;rsquo;s post&lt;/a&gt;&amp;nbsp;this is a bug and will resolve in next release of ASP.Net WebAPI. This issue is resolved using&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/02/18/using-json-net-with-asp-net-web-api.aspx"&gt;solution
 provided in Henrik's Blog&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/35.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue 2:&lt;/strong&gt;&amp;nbsp;Another issue was, when I try to Checkout Cart using the last created Customer. The error was:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/36.PNG" alt="Solution 1" width="700" height="300"&gt;&lt;/p&gt;
&lt;p&gt;After looking this error, first thought comes that we missed the method in CustomersController.cs, but the method was already there. Further investigation make it clear, that, the reason behind this error was name of this method as ValidateCustomer():&lt;/p&gt;
&lt;pre id="pre9" lang="cs"&gt;                     &lt;span&gt;public&lt;/span&gt; CustomerDTO ValidateCustomer(&lt;span&gt;int&lt;/span&gt; id, &lt;span&gt;string&lt;/span&gt; password)
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with parameter as : id and password: &amp;quot;&lt;/span&gt; &amp;#43; id &amp;#43; &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt; and &amp;quot;&lt;/span&gt; &amp;#43; password);
                        &lt;span&gt;return&lt;/span&gt; _customerService.ValidateCustomer(id, password);
                    }
                &lt;/pre&gt;
&lt;p&gt;In CustomerService implementation is :&lt;/p&gt;
&lt;pre id="pre10" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; CustomerDTO ValidateCustomer(&lt;span&gt;int&lt;/span&gt; id, &lt;span&gt;string&lt;/span&gt; password)
                    {
                        Customer objCustomer = _customerRepository.GetById(id);
                        &lt;span&gt;if&lt;/span&gt; (objCustomer == &lt;span&gt;null&lt;/span&gt;)
                            &lt;span&gt;return&lt;/span&gt; &lt;span&gt;null&lt;/span&gt;;
                        &lt;span&gt;string&lt;/span&gt; strPasswordHash = objCustomer.PasswordHash;
                        &lt;span&gt;string&lt;/span&gt; strPasswordSalt = strPasswordHash.Substring(strPasswordHash.Length - &lt;span&gt;8&lt;/span&gt;);
                        &lt;span&gt;string&lt;/span&gt; strPasword = CreatePasswordHash(password, strPasswordSalt);

                        &lt;span&gt;if&lt;/span&gt; (strPasword.Equals(strPasswordHash))
                            &lt;span&gt;return&lt;/span&gt; CreateCustomerDTO(objCustomer);
                        &lt;span&gt;else&lt;/span&gt;
                            &lt;span&gt;return&lt;/span&gt; &lt;span&gt;null&lt;/span&gt;;
                    }
                &lt;/pre&gt;
&lt;p&gt;By default the&amp;nbsp;&lt;strong&gt;route configuration&lt;/strong&gt;&amp;nbsp;of Asp.Net WebAPI follows RESTFUL conventions meaning that it will accept only the&amp;nbsp;&lt;strong&gt;Get, Post, Put and Delete&lt;/strong&gt;&amp;nbsp;action names. So when we send a GET request to http://localhost:30000/api/customers/ValidateCustomer/30135/test
 we are basically calling the Get(int id) action and passing id=30135 which obviously crashes because we don&amp;rsquo;t have any method starting with Get which accept Id as parameter. To resolve this issue I need to add a new route definition in&amp;nbsp;&lt;strong&gt;Global.asax&lt;/strong&gt;&amp;nbsp;file
 as:&lt;/p&gt;
&lt;pre id="pre11" lang="cs"&gt;                     routes.MapHttpRoute(
                           name: &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;ValidateCustomer&amp;quot;&lt;/span&gt;,
                           routeTemplate: &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;api/{controller}/{action}/{id}/{password}&amp;quot;&lt;/span&gt;,
                           defaults: &lt;span&gt;new&lt;/span&gt; { action = &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;get&amp;quot;&lt;/span&gt; }
                       );
                &lt;/pre&gt;
&lt;p&gt;Adding this line done the magic and Login functinality start waorking&amp;hellip;. :)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step8"&gt;Step 8: Deploy on IIS&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To deploy this API on IIS version 7.5, first, publish only&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;solution to a Folder.&lt;/p&gt;
&lt;p&gt;Next, open IIS Manager and create a new website and set path to Publish folder, and we are done with deployment.&lt;/p&gt;
&lt;p&gt;Now, check whether page is opening or not, in my case, initially I got below error, which is self-explanatory.&lt;br&gt;
The error comes because this application is running on Asp.Net Framework Version 2.0. So, we need to change it to Asp.Net Framework Version 4.0:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/40.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/41.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;To change the Asp.Net Framework from 2.0 to 4.0, follow below steps.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/42.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/43.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;That was not the only reason not to run application, because after made above change in Application pool next error was:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/44.PNG" alt="Solution 1" width="700" height="200"&gt;&lt;/p&gt;
&lt;p&gt;To resolve this error again go to Advance Settings of Application pool and change the identity to Local System from ApplicationPoolIdentity&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/45.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;After modify the Application pool to use Local System, Application starts working on browser... :)&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/46.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;Although IIS errors are depending on servers/Firewall/Network or system to system, so it is very difficult to assume that you will also get the same error as mine. Check these links which help me to resolve some of the IIS issues in
 my work environment.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en/wcf/thread/b990d3ea-3335-40a6-877f-7c295da67a85"&gt;HTTP Error 500.19&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/eu/wcf/thread/39571e42-aca7-469d-8c68-aa59c2da4fcc"&gt;Could Not Load Type &amp;lsquo;System.ServiceModel.Activation.HttpModule&amp;rsquo;&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/k6h9cz8h.aspx"&gt;ASP.NET IIS Registration Tool&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms732012.aspx"&gt;ServiceModel Registration Tool&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step9"&gt;Step 9: Cross Domain Support&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The idea behind the Cross Domain Support comes when I try to remove all HTML pages from&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;solution and created a new Empty Web Application (Adventure.Website) which includes only&amp;nbsp;&lt;strong&gt;.html, .Js and .css&lt;/strong&gt;&amp;nbsp;files
 along with images. The structure for this application is as per below image:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/47.PNG" alt="Solution 1" width="300" height="500"&gt;&lt;/p&gt;
&lt;p&gt;Point all URL address to deployed code on IIS, after build and run application, output was null.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/48.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;To resolve this issue I would like to give my special thanks to Carlos&amp;rsquo; blog on MSDN&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2012/02/20/implementing-cors-support-in-asp-net-web-apis.aspx"&gt;Implementing CORS support in ASP.NET Web
 APIs&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;blockquote&gt;
&lt;div&gt;Quote:&lt;/div&gt;
&amp;ldquo;By default, a web page cannot make calls to services (APIs) on a domain other than the one where the page came from. This is a security measure against a group of cross-site forgery attacks in which browsing to a bad site could potentially use the browser
 cookies to get data from a good site which the user had previously logged on (think your bank). There are many situations, however, where getting data from different sites is a perfectly valid scenario, such as mash-up applications which need data from different
 sources.&amp;rdquo;&lt;/blockquote&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;That's it !!! Hope you enjoy this article. I am not an expert, and also I have not followed the entire industry standard at the time of writing this article (time factor).&lt;/p&gt;
&lt;p&gt;All&amp;nbsp;&lt;strong&gt;comment/Vote&lt;/strong&gt;&amp;nbsp;are more than welcome&amp;hellip;. :), whenever, I get time, will try to modify this solution. You can also join/contribute to this project on&amp;nbsp;&lt;a href="http://pocwebapi.codeplex.com/"&gt;CodePlex&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Thank's for your time.&lt;/p&gt;
&lt;p&gt;Anand&lt;/p&gt;
&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>anandranjanpandey</author><pubDate>Thu, 22 Mar 2012 05:43:31 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Documentation 20120322054331A</guid></item><item><title>Updated Wiki: Documentation</title><link>http://pocwebapi.codeplex.com/documentation?version=1</link><description>&lt;div class="wikidoc"&gt;
&lt;h2&gt;&lt;strong&gt;Introduction&amp;nbsp;&lt;/strong&gt;&amp;nbsp;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The purpose of this article is to create a&lt;strong&gt;&amp;nbsp;proof of concept&amp;nbsp;&lt;/strong&gt;to demonstrate the feasibility of&amp;nbsp;&lt;a href="http://www.asp.net/web-api"&gt;ASP.NET WebAPI&lt;/a&gt;&amp;nbsp;Beta version.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Prerequisite:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://msftdbprodsamples.codeplex.com/"&gt;AdventureWorksLT2008R2&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://www.asp.net/web-api"&gt;ASP.Net WebAPI&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://code.google.com/p/autofac/downloads/list"&gt;Autofac for Dependency Injection&lt;/a&gt;&amp;nbsp;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://logging.apache.org/log4net/download.html"&gt;Log4Net&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://www.microsoft.com/download/en/details.aspx?displaylang=en&amp;id=8363"&gt;EntityFramework 4.1&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="https://github.com/jquery/jquery-tmpl"&gt;jQuery Templates plugin (jquery-tmpl)&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Goals to achieve:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Any user should be able to view products &lt;/li&gt;&lt;li&gt;Product would be filtered by Categories &lt;/li&gt;&lt;li&gt;User should be able to add products in cart &lt;/li&gt;&lt;li&gt;Only registered user will be able to submit cart &lt;/li&gt;&lt;li&gt;User should be able to register into system &lt;/li&gt;&lt;li&gt;User will get confirmation Invoice after generating order in system. &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Architecture for this POC&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I am not following any specific Architecture Pattern, although while designing this POC, I&amp;nbsp;&lt;strong&gt;try to follow&lt;/strong&gt;&amp;nbsp;some of the key design principles like:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Separation_of_concerns"&gt;Separation of concerns&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Abstraction_(computer_science)"&gt;Abstraction&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself"&gt;Don't repeat yourself&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/KISS_principle"&gt;KISS principle&lt;/a&gt; &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;span&gt;Again I am repeating my word&amp;nbsp;&lt;strong&gt;try to follow&amp;hellip;.. :)&lt;/strong&gt;. So, all comments/suggestions are more than welcome to discuss and I am always ready to adopt changes, or you can do it yourself by join&amp;nbsp;&lt;a href="http://pocwebapi.codeplex.com/"&gt;@CodePlex&lt;/a&gt;.
 The initial Skeleton for this application is as per below diagram:&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/1.PNG" alt="Architecture" width="650" height="500"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Step-by-Step&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/350488/A-simple-POC-using-ASP-NET-Web-API-Entity-Framewor#step1"&gt;Step 1: Create a basic Application Structure Layout&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/350488/A-simple-POC-using-ASP-NET-Web-API-Entity-Framewor#step2"&gt;Step 2: Create the Data Access Layer&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/350488/A-simple-POC-using-ASP-NET-Web-API-Entity-Framewor#step3"&gt;Step 3: Create the Service Layer&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/350488/A-simple-POC-using-ASP-NET-Web-API-Entity-Framewor#step4"&gt;Step 4: Create the API Layer&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/350488/A-simple-POC-using-ASP-NET-Web-API-Entity-Framewor#step5"&gt;Step 5: Integration of Dependency Injection using Autofac&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/350488/A-simple-POC-using-ASP-NET-Web-API-Entity-Framewor#step6"&gt;Step 6: Add Views to solution&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/350488/A-simple-POC-using-ASP-NET-Web-API-Entity-Framewor#step7"&gt;Step 7: Unit test and resolve issues&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/350488/A-simple-POC-using-ASP-NET-Web-API-Entity-Framewor#step8"&gt;Step 8: Deploy application on IIS&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/350488/A-simple-POC-using-ASP-NET-Web-API-Entity-Framewor#step9"&gt;Step 9: Provide Cross Domain Support&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step1"&gt;Step 1: Create a basic Application Structure Layout&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;For more information on ASP.NET WebAPI, watch Videos and Tutorials&amp;nbsp;&lt;a href="http://www.asp.net/web-api"&gt;here&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add a blank Solution named as&amp;nbsp;&lt;strong&gt;Application&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add a new Project (Class Library) named as&amp;nbsp;&lt;strong&gt;Application.DAL&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Repeat above process and create four more Class Library projects named as &amp;ndash;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Application.Model&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Repository&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Common&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Application.Service&lt;/strong&gt; &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;span&gt;Now, application will look like below screen-shot&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/4.PNG" alt="Solution 1" width="250" height="350"&gt;&lt;/p&gt;
&lt;p&gt;Next, add a new Project named as&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;as ASP.Net MVC 4 Web Application. After click on OK, select template as Web API&lt;/p&gt;
&lt;p&gt;&lt;span&gt;This will add a full functional Web API template Application into our main solution.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/7.PNG" alt="Solution 1" width="230" height="350"&gt;&lt;/p&gt;
&lt;p&gt;Right click on Application.API project in Solution Explorer and go to properties, than assign a port to be use by this service application ( In my case its 30000). Hit F5 and we are ready with a dummy data as below screen:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/8.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step2"&gt;Step 2: Prepare Application.DAL, Application.Repository and Application.Model Layers&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Check&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/library/bb399182.aspx"&gt;@MSDN&lt;/a&gt;&amp;nbsp;for more information on Entity Framework&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add Entity Data Model to&amp;nbsp;&lt;strong&gt;Application.DAL&lt;/strong&gt;&amp;nbsp;project. To do this select ADO.NET Entity Data Model from the Data Templates list, and name it as&amp;nbsp;&lt;strong&gt;AdventureWorks.edmx&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Choose&amp;nbsp;&lt;strong&gt;&amp;ldquo;Generate from Database&amp;rdquo;&lt;/strong&gt;&amp;nbsp;and provide the connection string to read the database schema. This will add AdventureWorks.edmx into current project. Right click on the blank space in Entity Model surface and click
 on properties (or alternate press Alt &amp;#43;Enter on keyboard). Now set its Code Generation Strategy as&amp;nbsp;&lt;strong&gt;None&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/10.PNG" alt="Solution 1" width="550" height="300"&gt;&lt;/p&gt;
&lt;p&gt;Now create POCO entities for AdventureWorks Data Model into&amp;nbsp;&lt;strong&gt;Application.Model&lt;/strong&gt;&amp;nbsp;Solution. Check this article to do this job for you on MSDN to use&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/gg558520"&gt;T4 Templates and the Entity
 Framework&lt;/a&gt;&lt;br&gt;
Then, create all required repositories under Application.Repositories.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/11.PNG" alt="Solution 1" width="250" height="500"&gt;&lt;/p&gt;
&lt;p&gt;To build solution, add reference of&amp;nbsp;&lt;strong&gt;Application.Model.dll&lt;/strong&gt;&amp;nbsp;to&amp;nbsp;&lt;strong&gt;Application.DAL.dll&lt;/strong&gt;&amp;nbsp;and&amp;nbsp;&lt;strong&gt;Application.Repository.dll&lt;/strong&gt;projects, and add reference of&amp;nbsp;&lt;strong&gt;Application.DAL.dll&lt;/strong&gt;&amp;nbsp;to&amp;nbsp;&lt;strong&gt;Application.Repository.dll&lt;/strong&gt;&amp;nbsp;project.
 (See below picture for reference)&lt;br&gt;
Before proceeding to next step (designing Application.Service and Application.API Layer), let us see what we have designed yet:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/12.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step3"&gt;Step 3: Add files to Application.Service Layer&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Before adding files to Service layer let us look at the Goals which we want to achieve.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Any user should be able to view products &lt;/li&gt;&lt;li&gt;Product would be filtered by Categories &lt;/li&gt;&lt;li&gt;User should be able to add products in cart &lt;/li&gt;&lt;li&gt;Only registered user will be able to submit cart &lt;/li&gt;&lt;li&gt;User should be able to register into system &lt;/li&gt;&lt;li&gt;User will get confirmation Invoice after generating order in system. &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To achieve the above mention Goals, we need to add three service classes to Application.Service as per below image&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/13.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/14.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;I am not going in deatils, as the implementation for each methods are clear and easy to understand.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step4"&gt;Step 4: Add files to Application.API Layer&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To make this Web API accessed from a broad range of clients like any browsers which use JavaScript or any windows/Mobile platform which supports .dll files, we need to add Controllers with base class as&amp;nbsp;&lt;strong&gt;ApiController&lt;/strong&gt;.&amp;nbsp;&lt;a href="http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api"&gt;More
 details here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;First, we remove the default controllers added by template (HomeController and ValuesController) and then add three new controllers as per below diagram:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/15.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;Again, nothing special in the implementation of these methods, they all jst push the data to service layer.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step5"&gt;Step 5: Integration of Dependency Injection with WebAPI using Autofac&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The implementation is very much straight forward and clear.&amp;nbsp;&lt;a href="http://alexmg.com/post/2012/03/08/Autofac-ASPNET-Web-API-%28Beta%29-Integration.aspx"&gt;Check Alex post here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;Solution Explorer, right-click the References node and click Manage NuGet Packages&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/16.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;It will open the below screen.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/17.PNG" alt="Solution 1" width="700" height="200"&gt;&lt;/p&gt;
&lt;p&gt;Click on install and it will add below three references in solution&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/18.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;Next, go to Global.asax.cs and create a method named as ResolveDependency()&lt;/p&gt;
&lt;div id="premain0"&gt;&lt;img id="preimg0" src="http://www.codeproject.com/images/minus.gif" alt="" width="9" height="9"&gt;&lt;span id="precollapse0"&gt;&amp;nbsp;Collapse&lt;/span&gt;&amp;nbsp;|&amp;nbsp;&lt;a href="http://www.codeproject.com/Articles/350488/A-simple-POC-using-ASP-NET-Web-API-Entity-Framewor#"&gt;Copy
 Code&lt;/a&gt;&lt;/div&gt;
&lt;pre id="pre0" lang="cs"&gt;             &lt;span&gt;protected&lt;/span&gt; &lt;span&gt;void&lt;/span&gt; ResolveDependancy()
                {
                    &lt;span&gt;var&lt;/span&gt; configuration = GlobalConfiguration.Configuration;
                    &lt;span&gt;var&lt;/span&gt; builder = &lt;span&gt;new&lt;/span&gt; ContainerBuilder();

                    &lt;span&gt;//&lt;/span&gt;&lt;span&gt; Configure the container with the integration implementations.
&lt;/span&gt;                    builder.ConfigureWebApi(configuration);

                    &lt;span&gt;//&lt;/span&gt;&lt;span&gt; Register API controllers using assembly scanning.
&lt;/span&gt;                    builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

                    builder.RegisterType&amp;lt;logservice&amp;gt;().As&amp;lt;ilogservice&amp;gt;().InstancePerLifetimeScope();
                    builder.RegisterType&amp;lt;unitofwork&amp;gt;().As&amp;lt;iunitofwork&amp;gt;().InstancePerDependency();
                    builder.RegisterType&amp;lt;databasefactory&amp;gt;().As&amp;lt;idatabasefactory&amp;gt;().InstancePerLifetimeScope();
                    builder.RegisterAssemblyTypes(&lt;span&gt;typeof&lt;/span&gt;(ProductService).Assembly)
                    .Where(t =&amp;gt; t.Name.EndsWith(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Service&amp;quot;&lt;/span&gt;))
                    .AsImplementedInterfaces().InstancePerDependency();
                    builder.RegisterAssemblyTypes(&lt;span&gt;typeof&lt;/span&gt;(CustomerRepository).Assembly)
                    .Where(t =&amp;gt; t.Name.EndsWith(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Repository&amp;quot;&lt;/span&gt;))
                    .AsImplementedInterfaces().InstancePerDependency();      

                    &lt;span&gt;var&lt;/span&gt; container = builder.Build();

                    &lt;span&gt;//&lt;/span&gt;&lt;span&gt; Set the dependency resolver implementation.
&lt;/span&gt;                    &lt;span&gt;var&lt;/span&gt; resolver = &lt;span&gt;new&lt;/span&gt; AutofacWebApiDependencyResolver(container);
                    configuration.ServiceResolver.SetResolver(resolver);
                }
            &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;idatabasefactory&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;databasefactory&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;iunitofwork&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;unitofwork&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;ilogservice&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;logservice&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Now we are ready to test our application. Hit F5 and check the browser with following url&amp;rsquo;s:&amp;nbsp;&lt;br&gt;
http://localhost:30000/api/products : will result all Product Categories&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/20.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;http://localhost:30000/api/products/2 : will result all Products with ProductcategoryID as 2&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/21.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;To check other methods, First we will add some Views in current solution.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step6"&gt;Step 6: Add View to solution&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Delete all default files and folders from Views Folder, and add three Html and their supportive Javascript File as. For this POC we will use html files, and some jquery libraries like:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;jquery.tmpl.js :&lt;/strong&gt;&amp;nbsp;to create template based screen, and&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;jquery.validationEngine.js :&lt;/strong&gt;&amp;nbsp;to validate form data&lt;/p&gt;
&lt;p&gt;Now the structure will looks like below picture :&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/22.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;For details code in html and JS file please look into the code. In next step I am going to resolve problems.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step7"&gt;Step 7: Resolve issues&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Before run the application Right Click on Products.htm and click on Set As start Page. Now hit F5&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/23.PNG" alt="Solution 1" width="700" height="300"&gt;&lt;/p&gt;
&lt;p&gt;It means, two WebAPI methods in ProductsController.cs are working perfectly. In JavaScript, on page load we are calling first method inside&amp;nbsp;&lt;strong&gt;product.js&lt;/strong&gt;&amp;nbsp;as:&lt;/p&gt;
&lt;div id="premain1"&gt;&lt;/div&gt;
&lt;pre id="pre1" lang="js"&gt;                    var productcategoriesAddress = &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;/api/products/&amp;quot;&lt;/span&gt;;
                    $(function () {
                        $(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;#tblRight'&lt;/span&gt;).hide();
                        $.getJSON(
                                productcategoriesAddress,
                                function (data) {
                                    var parents = jQuery.grep(data, function (a) { &lt;span&gt;return&lt;/span&gt; a.ParentProductCategoryID == null });
                                    var childs = jQuery.grep(data, function (a) { &lt;span&gt;return&lt;/span&gt; a.ParentProductCategoryID != null });
                                    $.&lt;span&gt;each&lt;/span&gt;(parents,
                                        function (index, &lt;span&gt;value&lt;/span&gt;) {
                                            var categorydata = [];
                                            var subCategory = &lt;span&gt;'&lt;/span&gt;&lt;span&gt;'&lt;/span&gt;;
                                            var subChild = jQuery.grep(childs, function (a) { &lt;span&gt;return&lt;/span&gt; a.ParentProductCategoryID == &lt;span&gt;value&lt;/span&gt;.ProductCategoryID });
                                            $.&lt;span&gt;each&lt;/span&gt;(subChild,
                                                function (index, item) {
                                                    var serviceURL = productcategoriesAddress &amp;#43; item.ProductCategoryID;
                                                    subCategory = subCategory &amp;#43; &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;  &amp;quot;&lt;/span&gt; &amp;#43; &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;lt;a href=&amp;quot;&lt;/span&gt;%20&amp;#43;%20serviceURL%20&amp;#43;%20&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt; class=&amp;quot;&lt;/span&gt;menuButton&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;gt;&amp;quot;&lt;/span&gt; &amp;#43; item.Name &amp;#43; &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;lt;/a&amp;gt;&amp;quot;&lt;/span&gt;;
                                                });
                                            categorydata.push({
                                                &lt;span&gt;'&lt;/span&gt;&lt;span&gt;ProductCategoryID'&lt;/span&gt;: &lt;span&gt;value&lt;/span&gt;.ProductCategoryID,
                                                &lt;span&gt;'&lt;/span&gt;&lt;span&gt;ParentCategory'&lt;/span&gt;: &lt;span&gt;value&lt;/span&gt;.Name,
                                                &lt;span&gt;'&lt;/span&gt;&lt;span&gt;ChildCategory'&lt;/span&gt;: subCategory
                                            });
                                            $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#categoryTemplate&amp;quot;&lt;/span&gt;).tmpl(categorydata).appendTo(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#categories&amp;quot;&lt;/span&gt;);
                                            $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#&amp;quot;&lt;/span&gt; &amp;#43; &lt;span&gt;value&lt;/span&gt;.Name).html(subCategory);
                                        });

                                        GetProducts(&lt;span&gt;1&lt;/span&gt;);
                                }
                            );
                &lt;/pre&gt;
&lt;p&gt;This call hits below method in ProductsController, and returns all Product Category to create the Upper Menu Part&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;pre id="pre2" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; IQueryable&amp;lt;productcategory&amp;gt; GetProductCategories()
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with null parameter&amp;quot;&lt;/span&gt;);
                        &lt;span&gt;return&lt;/span&gt; _productservice.GetProductCategories().AsQueryable&amp;lt;productcategory&amp;gt;();
                    }
                &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;productcategory&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;productcategory&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;In ProductService implementation is :&lt;/p&gt;
&lt;div id="premain3"&gt;&lt;/div&gt;
&lt;pre id="pre3" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; IQueryable&amp;lt;productcategory&amp;gt; GetProductCategories()
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with null parameter&amp;quot;&lt;/span&gt;);
                        &lt;span&gt;return&lt;/span&gt; _productservice.GetProductCategories().AsQueryable&amp;lt;productcategory&amp;gt;();
                    }
                &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;productcategory&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;productcategory&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;The second call is to fetch all products depends on selected category. In javascript&lt;/p&gt;
&lt;div id="premain4"&gt;&lt;/div&gt;
&lt;pre id="pre4" lang="js"&gt;                      function GetProducts(ProductCategoryID) {
                        var serviceURL = productcategoriesAddress &amp;#43; ProductCategoryID;
                        $(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;#categories li h1'&lt;/span&gt;).css(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;background'&lt;/span&gt;, &lt;span&gt;'&lt;/span&gt;&lt;span&gt;#736F6E'&lt;/span&gt;);
                        $(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;#mnu'&lt;/span&gt; &amp;#43; ProductCategoryID).css(&lt;span&gt;'&lt;/span&gt;&lt;span&gt;background'&lt;/span&gt;, &lt;span&gt;'&lt;/span&gt;&lt;span&gt;#357EC7'&lt;/span&gt;);
                        $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#loader&amp;quot;&lt;/span&gt;).show();
                        $.ajax({
                            type: &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;GET&amp;quot;&lt;/span&gt;,
                            datatype: &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;json&amp;quot;&lt;/span&gt;,
                            url: serviceURL,
                            context: &lt;span&gt;this&lt;/span&gt;,
                            success: function (&lt;span&gt;value&lt;/span&gt;) {
                                $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#productData&amp;quot;&lt;/span&gt;).html(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;quot;&lt;/span&gt;);
                                $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#productTemplate&amp;quot;&lt;/span&gt;).tmpl(&lt;span&gt;value&lt;/span&gt;).appendTo(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#productData&amp;quot;&lt;/span&gt;);
                                $(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;#loader&amp;quot;&lt;/span&gt;).hide();
                            }
                        });
                        &lt;span&gt;return&lt;/span&gt; &lt;span&gt;false&lt;/span&gt;;
                    }
                &lt;/pre&gt;
&lt;p&gt;and in ProductsController it goes to&lt;/p&gt;
&lt;div id="premain5"&gt;&lt;/div&gt;
&lt;pre id="pre5" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; IQueryable&amp;lt;product&amp;gt; GetProductByProductCategoryID(&lt;span&gt;int&lt;/span&gt; id)
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with null parameter as : id : &amp;quot;&lt;/span&gt; &amp;#43; id);
                        &lt;span&gt;return&lt;/span&gt; _productservice.GetProductByProductCategoryID(id).AsQueryable&amp;lt;product&amp;gt;();
                    }

                &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;product&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;product&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;In ProductService implementation is :&lt;/p&gt;
&lt;div id="premain6"&gt;&lt;/div&gt;
&lt;pre id="pre6" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; IQueryable&amp;lt;product&amp;gt; GetProductByProductCategoryID(&lt;span&gt;int&lt;/span&gt; id)
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with null parameter as : id : &amp;quot;&lt;/span&gt; &amp;#43; id);
                        &lt;span&gt;return&lt;/span&gt; _productservice.GetProductByProductCategoryID(id).AsQueryable&amp;lt;product&amp;gt;();
                    }
                &lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;product&amp;gt;&amp;lt;&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;product&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Next, let us try to add some products to Cart and Checkout cart&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/28.PNG" alt="Solution 1" width="400" height="300"&gt;&lt;/p&gt;
&lt;p&gt;On clicking on checkout It redirect to Checkout.htm page and asking for either Login using existing CustomerID or Register for a new Customer.&lt;br&gt;
Click on&amp;nbsp;&lt;strong&gt;Register&lt;/strong&gt;&amp;nbsp;link to create a new Customer.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/29.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;Submit form after clicking on Register button and see if Posting is working or not. Again its success!!!&lt;/p&gt;
&lt;p&gt;Now we will try to update records for AddressLine2, and Update is also working fine!!!&lt;/p&gt;
&lt;p&gt;In both scenario (Add or Update Customer) we are calling below method of CutomerControllers.cs&lt;/p&gt;
&lt;div id="premain7"&gt;&lt;/div&gt;
&lt;pre id="pre7" lang="cs"&gt;                     &lt;span&gt;public&lt;/span&gt; &lt;span&gt;int&lt;/span&gt; PostCustomer(CustomerDTO customer)
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with parameter as : customer: &amp;quot;&lt;/span&gt; &amp;#43; customer);
                        &lt;span&gt;return&lt;/span&gt; _customerService.SaveOrUpdateCustomer(customer);
                    }
                &lt;/pre&gt;
&lt;p&gt;In CustomerService implementation is :&lt;/p&gt;
&lt;div id="premain8"&gt;&lt;/div&gt;
&lt;pre id="pre8" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;int&lt;/span&gt; SaveOrUpdateCustomer(CustomerDTO customer)
                    {
                        &lt;span&gt;string&lt;/span&gt; passwordSalt = CreateSalt(&lt;span&gt;5&lt;/span&gt;);
                        &lt;span&gt;string&lt;/span&gt; pasword = CreatePasswordHash(customer.Password, passwordSalt);
                        Customer objCustomer;

                        &lt;span&gt;if&lt;/span&gt; (customer.CustomerID != &lt;span&gt;0&lt;/span&gt;)
                            objCustomer = _customerRepository.GetById(customer.CustomerID);
                        &lt;span&gt;else&lt;/span&gt;
                            objCustomer = &lt;span&gt;new&lt;/span&gt; Customer();

                        objCustomer.NameStyle = customer.NameStyle;
                        objCustomer.Title = customer.Title;
                        objCustomer.FirstName = customer.FirstName;
                        objCustomer.MiddleName = customer.MiddleName;
                        objCustomer.LastName = customer.LastName;
                        objCustomer.Suffix = customer.Suffix;
                        objCustomer.CompanyName = customer.CompanyName;
                        objCustomer.SalesPerson = customer.SalesPerson;
                        objCustomer.EmailAddress = customer.EmailAddress;
                        objCustomer.Phone = customer.Phone;
                        objCustomer.PasswordHash = pasword;
                        objCustomer.PasswordSalt = passwordSalt;
                        objCustomer.ModifiedDate = DateTime.Now;
                        objCustomer.rowguid = Guid.NewGuid();

                        &lt;span&gt;if&lt;/span&gt; (customer.CustomerID != &lt;span&gt;0&lt;/span&gt;)
                            _customerRepository.Update(objCustomer);
                        &lt;span&gt;else&lt;/span&gt;
                            _customerRepository.Add(objCustomer);

                        _unitOfWork.Commit();
                        SaveOrUpdateAddress(customer, objCustomer.CustomerID);
                        &lt;span&gt;return&lt;/span&gt; objCustomer.CustomerID;
                    }
                &lt;/pre&gt;
&lt;p&gt;Next, click on Submit Order Button, to make previously selected products as an Order and receive Order Invoice.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/33.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;!!!Hurray!!! Order is created in system and invoice is generated with a new Purchase Order. But, wait we got one BUG&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue 1:&lt;/strong&gt;&amp;nbsp;we have an issue with Date Format.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/34.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;According to,&amp;nbsp;&lt;a href="http://www.hanselman.com/blog/OnTheNightmareThatIsJSONDatesPlusJSONNETAndASPNETWebAPI.aspx"&gt;Scott Hanselman&amp;rsquo;s post&lt;/a&gt;&amp;nbsp;this is a bug and will resolve in next release of ASP.Net WebAPI. This issue is resolved using&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/02/18/using-json-net-with-asp-net-web-api.aspx"&gt;solution
 provided in Henrik's Blog&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/35.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue 2:&lt;/strong&gt;&amp;nbsp;Another issue was, when I try to Checkout Cart using the last created Customer. The error was:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/36.PNG" alt="Solution 1" width="700" height="300"&gt;&lt;/p&gt;
&lt;p&gt;After looking this error, first thought comes that we missed the method in CustomersController.cs, but the method was already there. Further investigation make it clear, that, the reason behind this error was name of this method as ValidateCustomer():&lt;/p&gt;
&lt;div id="premain9"&gt;&lt;/div&gt;
&lt;pre id="pre9" lang="cs"&gt;                     &lt;span&gt;public&lt;/span&gt; CustomerDTO ValidateCustomer(&lt;span&gt;int&lt;/span&gt; id, &lt;span&gt;string&lt;/span&gt; password)
                    {
                        loggerService.Logger().Info(&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Calling with parameter as : id and password: &amp;quot;&lt;/span&gt; &amp;#43; id &amp;#43; &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt; and &amp;quot;&lt;/span&gt; &amp;#43; password);
                        &lt;span&gt;return&lt;/span&gt; _customerService.ValidateCustomer(id, password);
                    }
                &lt;/pre&gt;
&lt;p&gt;In CustomerService implementation is :&lt;/p&gt;
&lt;div id="premain10"&gt;&lt;/div&gt;
&lt;pre id="pre10" lang="cs"&gt;                    &lt;span&gt;public&lt;/span&gt; CustomerDTO ValidateCustomer(&lt;span&gt;int&lt;/span&gt; id, &lt;span&gt;string&lt;/span&gt; password)
                    {
                        Customer objCustomer = _customerRepository.GetById(id);
                        &lt;span&gt;if&lt;/span&gt; (objCustomer == &lt;span&gt;null&lt;/span&gt;)
                            &lt;span&gt;return&lt;/span&gt; &lt;span&gt;null&lt;/span&gt;;
                        &lt;span&gt;string&lt;/span&gt; strPasswordHash = objCustomer.PasswordHash;
                        &lt;span&gt;string&lt;/span&gt; strPasswordSalt = strPasswordHash.Substring(strPasswordHash.Length - &lt;span&gt;8&lt;/span&gt;);
                        &lt;span&gt;string&lt;/span&gt; strPasword = CreatePasswordHash(password, strPasswordSalt);

                        &lt;span&gt;if&lt;/span&gt; (strPasword.Equals(strPasswordHash))
                            &lt;span&gt;return&lt;/span&gt; CreateCustomerDTO(objCustomer);
                        &lt;span&gt;else&lt;/span&gt;
                            &lt;span&gt;return&lt;/span&gt; &lt;span&gt;null&lt;/span&gt;;
                    }
                &lt;/pre&gt;
&lt;p&gt;By default the&amp;nbsp;&lt;strong&gt;route configuration&lt;/strong&gt;&amp;nbsp;of Asp.Net WebAPI follows RESTFUL conventions meaning that it will accept only the&amp;nbsp;&lt;strong&gt;Get, Post, Put and Delete&lt;/strong&gt;&amp;nbsp;action names. So when we send a GET request to http://localhost:30000/api/customers/ValidateCustomer/30135/test
 we are basically calling the Get(int id) action and passing id=30135 which obviously crashes because we don&amp;rsquo;t have any method starting with Get which accept Id as parameter. To resolve this issue I need to add a new route definition in&amp;nbsp;&lt;strong&gt;Global.asax&lt;/strong&gt;&amp;nbsp;file
 as:&lt;/p&gt;
&lt;div id="premain11"&gt;&lt;/div&gt;
&lt;pre id="pre11" lang="cs"&gt;                     routes.MapHttpRoute(
                           name: &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;ValidateCustomer&amp;quot;&lt;/span&gt;,
                           routeTemplate: &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;api/{controller}/{action}/{id}/{password}&amp;quot;&lt;/span&gt;,
                           defaults: &lt;span&gt;new&lt;/span&gt; { action = &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;get&amp;quot;&lt;/span&gt; }
                       );
                &lt;/pre&gt;
&lt;p&gt;Adding this line done the magic and Login functinality start waorking&amp;hellip;. :)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step8"&gt;Step 8: Deploy on IIS&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To deploy this API on IIS version 7.5, first, publish only&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;solution to a Folder.&lt;/p&gt;
&lt;p&gt;Next, open IIS Manager and create a new website and set path to Publish folder, and we are done with deployment.&lt;/p&gt;
&lt;p&gt;Now, check whether page is opening or not, in my case, initially I got below error, which is self-explanatory.&lt;br&gt;
The error comes because this application is running on Asp.Net Framework Version 2.0. So, we need to change it to Asp.Net Framework Version 4.0:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/40.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/41.PNG" alt="Solution 1" width="650"&gt;&lt;/p&gt;
&lt;p&gt;To change the Asp.Net Framework from 2.0 to 4.0, follow below steps.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/42.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/43.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;That was not the only reason not to run application, because after made above change in Application pool next error was:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/44.PNG" alt="Solution 1" width="700" height="200"&gt;&lt;/p&gt;
&lt;p&gt;To resolve this error again go to Advance Settings of Application pool and change the identity to Local System from ApplicationPoolIdentity&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/45.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;After modify the Application pool to use Local System, Application starts working on browser... :)&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/46.PNG" alt="Solution 1" width="700" height="500"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;Although IIS errors are depending on servers/Firewall/Network or system to system, so it is very difficult to assume that you will also get the same error as mine. Check these links which help me to resolve some of the IIS issues in
 my work environment.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en/wcf/thread/b990d3ea-3335-40a6-877f-7c295da67a85"&gt;HTTP Error 500.19&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/eu/wcf/thread/39571e42-aca7-469d-8c68-aa59c2da4fcc"&gt;Could Not Load Type &amp;lsquo;System.ServiceModel.Activation.HttpModule&amp;rsquo;&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/k6h9cz8h.aspx"&gt;ASP.NET IIS Registration Tool&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms732012.aspx"&gt;ServiceModel Registration Tool&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;&lt;a id="step9"&gt;Step 9: Cross Domain Support&lt;/a&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The idea behind the Cross Domain Support comes when I try to remove all HTML pages from&amp;nbsp;&lt;strong&gt;Application.API&lt;/strong&gt;&amp;nbsp;solution and created a new Empty Web Application (Adventure.Website) which includes only&amp;nbsp;&lt;strong&gt;.html, .Js and .css&lt;/strong&gt;&amp;nbsp;files
 along with images. The structure for this application is as per below image:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/47.PNG" alt="Solution 1" width="300" height="500"&gt;&lt;/p&gt;
&lt;p&gt;Point all URL address to deployed code on IIS, after build and run application, output was null.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.codeproject.com/KB/WCF/350488/48.PNG" alt="Solution 1"&gt;&lt;/p&gt;
&lt;p&gt;To resolve this issue I would like to give my special thanks to Carlos&amp;rsquo; blog on MSDN&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2012/02/20/implementing-cors-support-in-asp-net-web-apis.aspx"&gt;Implementing CORS support in ASP.NET Web
 APIs&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;blockquote&gt;
&lt;div&gt;Quote:&lt;/div&gt;
&amp;ldquo;By default, a web page cannot make calls to services (APIs) on a domain other than the one where the page came from. This is a security measure against a group of cross-site forgery attacks in which browsing to a bad site could potentially use the browser
 cookies to get data from a good site which the user had previously logged on (think your bank). There are many situations, however, where getting data from different sites is a perfectly valid scenario, such as mash-up applications which need data from different
 sources.&amp;rdquo;&lt;/blockquote&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;That's it !!! Hope you enjoy this article. I am not an expert, and also I have not followed the entire industry standard at the time of writing this article (time factor).&lt;/p&gt;
&lt;p&gt;All&amp;nbsp;&lt;strong&gt;comment/Vote&lt;/strong&gt;&amp;nbsp;are more than welcome&amp;hellip;. :), whenever, I get time, will try to modify this solution. You can also join/contribute to this project on&amp;nbsp;&lt;a href="http://pocwebapi.codeplex.com/"&gt;CodePlex&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Thank's for your time.&lt;/p&gt;
&lt;p&gt;Anand&lt;/p&gt;
&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>anandranjanpandey</author><pubDate>Thu, 22 Mar 2012 05:42:00 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Documentation 20120322054200A</guid></item></channel></rss>