Click here to Skip to main content
15,886,110 members
Articles / Web Development / ASP.NET

A N-Tier Architecture Sample with ASP.NET MVC3, WCF, and Entity Framework

Rate me:
Please Sign up or sign in to vote.
4.85/5 (91 votes)
11 Sep 2012CPOL48 min read 555.2K   31.7K   425  
This article tries to introduce a decoupled, unit-testable, deployment-flexible, implementation-efficient and validation-flexible N-Tier architecture in .NET
<?xml version="1.0"?>
<configuration>
  
  <system.web>
    <compilation debug="true"/>
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>

    <extensions>
      <behaviorExtensions>
        <add name="FaultErrorHandling" type="ErrorHandlerBehavior, GH.Northwind.Business, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
      </behaviorExtensions>
    </extensions>

    <services>
      <service name="GH.Northwind.Business.NorthwindSvr" behaviorConfiguration="BusinessServiceBehavior">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8732/Design_Time_Addresses/GH.Northwind.Business/NorthwindSvr/"/>
          </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <endpoint address="" binding="BasicHttpBinding" contract="GH.Northwind.Business.INorthwindSvr">
          <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <!-- Metadata Endpoints -->
        <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. --> 
        <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="BusinessServiceBehavior">
          <!-- To avoid disclosing metadata information, 
          set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="True"/>
          <!-- To receive exception details in faults for debugging purposes, 
          set the value below to true.  Set to false before deployment 
          to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="False"/>
          <FaultErrorHandling />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

	<appSettings>
		<add key="UseWcfDataService" value="false"></add>
		<add key="WcfDataServiceUrl" value="http://localhost:55555/NorthwindDataService.svc/"></add>
	</appSettings>
	<connectionStrings>
		<add name="NorthwindEntities" connectionString="metadata=res://*/GHNorthwindModels.csdl|res://*/GHNorthwindModels.ssdl|res://*/GHNorthwindModels.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=GH-PC\SQLEXPRESS;initial catalog=Northwind;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
	</connectionStrings>
</configuration>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions