SlideShare ist ein Scribd-Unternehmen logo
1 von 6
Downloaden Sie, um offline zu lesen
ASP.NET MVC 3 Rapid Application Development

                           Mădălin     tefîrcă and Victor Chircu



       Abstract. This paper’s aim is to point out the RAD ( Rapid application devel-
       opment) elements present in the Microsoft’s MVC 3 and WCF 4.0 using Micro-
       soft Visual Studio 2010. It will describe why creating a new web application us-
       ing MVC 3 and WCF 4.0 is a easy and fast and also present simple ways to de-
       velop such applications.



1      Introduction

The paper will describe to you the simplicity of developing a web application using
Microsoft’s ASP.NET MVC 3 and WCF 4.0. Starting with the creation of a new
project, adding new items, and quickly adding functionality including modeling, data-
bases CRUD operations, UI elements, exposing and consuming REST services etc.
There will be a brief presentation of the Html Helpers provided by Visual Studio, and
the use of Dynamic Templates and how they can help you and a comparison between
MVC 3 and Web Forms, the main web oriented frameworks provided by Microsoft.



2      Creating a new project

Creating a new project is easier than ever. You can create an emtpy project allowing
you to structure it the way you think is best fit, or you can choose to create a new
Internet Application that will create for you a fully functioning project and fully ex-
tensible. It is recommended to choose the second option, because this way you will
not have to worry about the project structure and start developing since the very first
minute. If you watch Fig.1 you can notice that Visual Studio has buit for you separate
folders for Controllers, Views, Models, Scripts, Content.
If you check the packages.config file you can also see that Visula Studio also added
some useful packages for you like jQuery, jQuery-UI, jQuery.Validation meaning
javascript libraries that will greatly improve your development and are very common
to an experienced developer. The Entity Framework nuGet package is installed also
by default and it comes in handy when working with complex databases since most of
the work is done by this ORM (Object Relational Mapping tool ).
In the ViewsShared folder you will find two .cshtml files, _Layout, used as a master
page in the application, and Error, used as an global error page displayed to the user
when the server crashes. These two are also added by default when creating a new
MVC3 project.
If you run the application you will notice that you have a fully functional project in-
cluding a minimal authentication system that allows you to register users and authen-
ticate them later on.




                                        Fig. 1.


3      Adding new items

3.1    Models
   Visual Studio also has provided for you an easy way for adding new items to your
projects. You can add a new class in the Models folder that will be our new model.
Right click the Models folder and select Add/Class. Name the class Employee and
click Add. Inside the class you type “prop” and click the Tab key. This will instantly
create for you a default property. Pressing the Tab key will switch you through the
property type and property name in order to change them. Make for a start two prop-
erties of type string and name them Name and CompanyName and an Id. Still inside
the class, if you type in “ctor” and press Tab key it will automatically generate a con-
structor for you. Inside the constructor assign the CompanyName property a string.
Now you have your first model. Your code should look like this:

public class Employee
    {
        public Employee()
        {
            this.CompanyName = "Fictional Company";
        }

           public int Id { get; set; }

            public string Name { get; set; }

            public string CompanyName { get; set; }
      }

3.2    Context
Now we will have to add a context for Entity Framework database. Int he Models
folder add a new class. This should inherit the DBContext object from Sys-
tem.Data.Entity. Add a property to the class that should look like this:

public class EmployeeContext : DbContext
    {
        public DbSet<Employee> Employees { get; set; }
    }
And now you have your context.


3.3    Controllers
To add a new controller, you simply right click the Controllers folder and select
Add/Controller. You type in the controller name, and then you get to choose between
several scaffolding options like and empty controller, controller with empty actions or
controller with read/write actions and views. The latter is the easiest way to develop.
Choosing this option will require you to set the model class and the data context. Our
model is Employee and context is EmployeeeContext. After selecting those previously
mentioned click Add. This will generate you the whole mechanism required for
CRUD (Create, Read, Update, Delete) operations over the Employee entity, including
database operations, and UI. If you take a look in the Views/Employees folder you
will see that Visual Studio has already generated all the html you need for the actions.
If you run the application in your browser and go to host/Employees you will have the
full functionality done.
4      Html helpers


Html Helpers are provided by visual studio as support for rendering HTML controls
in a view. It has a wide variety of choices like generating a link, forms, or even inputs
or validations for inputs based on a predefined model. Also these helpers are highly
extensible, customizing them being a great benefit for development.


@Html.EditorFor(m => m.Property)

@Html.DropDownListFor(m => m.Property, customSelectList)



5      Dynamic templates

Templates are used to display a predetermined portion of the page layout which also
contains fill-in-the-blanks that can be filled at run time. Template saves a lot of time
because it can be reused in many places. Razor view engine includes a feature called
Inline Template, which allows you to define a portion of dynamic HTML that can be
reused. Also using Razor template you can pass template as a parameter to a method.
You can make this for display or edit mode. All you must do is to set the @model of
the template to the desired type. This can be a struct, a class, or even a collection.
You can call this templates either by setting the name of the templates exactly the
same as the type of the property of the model, or by setting an attribute to the property
[UIHint(“templateName”)].



6      WCF and REST

Consuming and exposing REST services has become easier with the release of Win-
dows Communication Foundation (WCF) 4.0, because of the inclusion of the Web
HTTP programming model.
For exposing RESTful services, all you need is the WCF Rest Service Template 40,
which you can get through the Extension Manager (you can find it in the Tools
menu). In a project created with the template mentioned earlier, you can add a new
class for your service and decorate it with the [ServiceContract] attribute. Now you
can add methods to your service class and decorate them with either the [WebGet]
attribute (for GET requests) or with the [WebInvoke] attribute (for other HTTP me-
thods). Both attributes take a UriTemplate as a parameter, in which you can specify
the URI template to your resource. As a note, every token (string between “{}”) in the
UriTemplate has to be a parameter to the method, as shown in the following example:
[WebGet(UriTemplate = "Result?q={keyword}&lat={latitude}&
lng={longitude}&rad={radius}&output={outputType}")]
public string Get(string keyword, double latitude, double
 longitude, int radius, string outputType)

After you have defined your RESTfull method, the only think that remains is to regis-
ter it in the Global.asax file, in the RegisterRoutes method:

RouteTable.Routes.Add(new ServiceRoute("WhereToGoService"
, new WebServiceHostFactory(), typeof(WhereToGoService)))

Now by accesing :
<serv-
er>:<port>/WhereToGoService/Result?q=Tuxy&lat=24.4&lng=24.4&rad=10&outp
ut=json, the corresponding Get method from WhereToGoService will be called.

Consuming RESTful services is easy if you use the right tools and .NET classes:
   • UriTemplate to specify the template for the URI, and using the UriTem-
       plate.BindByPosition or UriTemplate.BindByName methods to replace the
       tokens in the template with the actual values.
   • WebClient to get the data from the specified URI (for example you can use
       the WebClient.DownloadString method which returns the String received by
       accessing the URI specified as the method’s parameter).
   • LINQ to XML for converting the string into and XML, and manipulating the
       XML through LINQ sintax.
   • Newtonsoft’s Json.net library for manipulating strings in Json format (for ex-
       ample if the service that you are consuming returns information in Json for-
       mat), and for converting XML to Json and vice-versa.

These are simple use cases used as proof of concept, but you can develop far more
complex REST services using WCF 4.0, together with other frameworks and libraries
provided by the .NET community.


7     Alternatives

The main advantages of the ASP.NET MVC 3 are that it enables full control over the
rendered HTML, it provides clean separation of concerns, easy integration with java-
script, RESTful urls that enables SEO, no ViewState and PostBacks events. The web
forms provide a wide variety of RAD elements, like drag & drop, automatic event
generation, and it is easier for developers coming from the winform development to
adapt. Another big plus for the web forms framework is the maturity - it has been
around since 2002 and there is a big amount of information regarding solving prob-
lems. Both of them are good choices, neither of the web frameworks are to be re-
placed by the other, nor there are plans to have them merged.
There are other vendors that offer 3rd party components and controls, like Telerik or
DevExpress. These controls get rid of most of the boilerplate code that you would be
writing, so they are feasible for small applications. But when it comes to building
complex enterprise applications, you would notice that these 3rd party components do
not cover all of the uses cases that you need, so ASP.MVC would be a safer bet.


8      Conclusion

All mentioned above prove that MVC 3 is very reliable and can easily be used to
develop complex web applications in a very short time, with great elegance. It is easy
to start with at a beginner level, allowing you to build basic functionality without too
much experience, and allowing more advanced developers to build solid, complex
applications in a short time. When working on a project you have to take into consid-
eration its purpose, scale, scalability and maintainability, and choose a framework
accordingly. Even if lately Microsoft has integrated more and more RAD components
into ASP.MVC, this framework is still designed for complex web application.

Weitere ähnliche Inhalte

Was ist angesagt?

Murach': HOW TO DEVELOP A DATA DRIVEN MVC WEB
Murach': HOW TO DEVELOP A DATA DRIVEN MVC WEB Murach': HOW TO DEVELOP A DATA DRIVEN MVC WEB
Murach': HOW TO DEVELOP A DATA DRIVEN MVC WEB MahmoudOHassouna
 
LearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLLearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLAkhil Mittal
 
Murach : HOW to work with controllers and routing
Murach : HOW to work with controllers and routingMurach : HOW to work with controllers and routing
Murach : HOW to work with controllers and routingMahmoudOHassouna
 
Repository Pattern in MVC3 Application with Entity Framework
Repository Pattern in MVC3 Application with Entity FrameworkRepository Pattern in MVC3 Application with Entity Framework
Repository Pattern in MVC3 Application with Entity FrameworkAkhil Mittal
 
Overview of CSharp MVC3 and EF4
Overview of CSharp MVC3 and EF4Overview of CSharp MVC3 and EF4
Overview of CSharp MVC3 and EF4Rich Helton
 
Cis407 a ilab 3 web application development devry university
Cis407 a ilab 3 web application development devry universityCis407 a ilab 3 web application development devry university
Cis407 a ilab 3 web application development devry universitylhkslkdh89009
 
Murach: How to validate data in asp.net core mvc
Murach: How to validate data in asp.net core mvcMurach: How to validate data in asp.net core mvc
Murach: How to validate data in asp.net core mvcMahmoudOHassouna
 
Murach: ASP.NET Core MVC, How To Work With Razor Views
Murach: ASP.NET Core MVC, How To Work With Razor ViewsMurach: ASP.NET Core MVC, How To Work With Razor Views
Murach: ASP.NET Core MVC, How To Work With Razor ViewsMahmoudOHassouna
 
C# Tutorial MSM_Murach chapter-20-slides
C# Tutorial MSM_Murach chapter-20-slidesC# Tutorial MSM_Murach chapter-20-slides
C# Tutorial MSM_Murach chapter-20-slidesSami Mut
 
ASPNET_MVC_Tutorial_06_CS
ASPNET_MVC_Tutorial_06_CSASPNET_MVC_Tutorial_06_CS
ASPNET_MVC_Tutorial_06_CStutorialsruby
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studioAravindharamanan S
 
Crystal report generation in visual studio 2010
Crystal report generation in visual studio 2010Crystal report generation in visual studio 2010
Crystal report generation in visual studio 2010Slideshare
 
Access tips access and sql part 4 building select queries on-the-fly
Access tips  access and sql part 4  building select queries on-the-flyAccess tips  access and sql part 4  building select queries on-the-fly
Access tips access and sql part 4 building select queries on-the-flyquest2900
 
C# Tutorial MSM_Murach chapter-01-slides
C# Tutorial MSM_Murach chapter-01-slidesC# Tutorial MSM_Murach chapter-01-slides
C# Tutorial MSM_Murach chapter-01-slidesSami Mut
 
Report programming model for microsoft dynamics ax 2012
Report programming model for microsoft dynamics ax 2012Report programming model for microsoft dynamics ax 2012
Report programming model for microsoft dynamics ax 2012KiranVathaluru
 
Resolve dependency of dependencies using Inversion of Control and dependency ...
Resolve dependency of dependencies using Inversion of Control and dependency ...Resolve dependency of dependencies using Inversion of Control and dependency ...
Resolve dependency of dependencies using Inversion of Control and dependency ...Akhil Mittal
 
Struts Introduction Course
Struts Introduction CourseStruts Introduction Course
Struts Introduction Courseguest764934
 

Was ist angesagt? (19)

Murach': HOW TO DEVELOP A DATA DRIVEN MVC WEB
Murach': HOW TO DEVELOP A DATA DRIVEN MVC WEB Murach': HOW TO DEVELOP A DATA DRIVEN MVC WEB
Murach': HOW TO DEVELOP A DATA DRIVEN MVC WEB
 
Building richwebapplicationsusingasp
Building richwebapplicationsusingaspBuilding richwebapplicationsusingasp
Building richwebapplicationsusingasp
 
LearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLLearningMVCWithLINQToSQL
LearningMVCWithLINQToSQL
 
Murach : HOW to work with controllers and routing
Murach : HOW to work with controllers and routingMurach : HOW to work with controllers and routing
Murach : HOW to work with controllers and routing
 
Repository Pattern in MVC3 Application with Entity Framework
Repository Pattern in MVC3 Application with Entity FrameworkRepository Pattern in MVC3 Application with Entity Framework
Repository Pattern in MVC3 Application with Entity Framework
 
Overview of CSharp MVC3 and EF4
Overview of CSharp MVC3 and EF4Overview of CSharp MVC3 and EF4
Overview of CSharp MVC3 and EF4
 
Cis407 a ilab 3 web application development devry university
Cis407 a ilab 3 web application development devry universityCis407 a ilab 3 web application development devry university
Cis407 a ilab 3 web application development devry university
 
Murach: How to validate data in asp.net core mvc
Murach: How to validate data in asp.net core mvcMurach: How to validate data in asp.net core mvc
Murach: How to validate data in asp.net core mvc
 
Murach: ASP.NET Core MVC, How To Work With Razor Views
Murach: ASP.NET Core MVC, How To Work With Razor ViewsMurach: ASP.NET Core MVC, How To Work With Razor Views
Murach: ASP.NET Core MVC, How To Work With Razor Views
 
C# Tutorial MSM_Murach chapter-20-slides
C# Tutorial MSM_Murach chapter-20-slidesC# Tutorial MSM_Murach chapter-20-slides
C# Tutorial MSM_Murach chapter-20-slides
 
ASPNET_MVC_Tutorial_06_CS
ASPNET_MVC_Tutorial_06_CSASPNET_MVC_Tutorial_06_CS
ASPNET_MVC_Tutorial_06_CS
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
 
Knockout in action
Knockout in actionKnockout in action
Knockout in action
 
Crystal report generation in visual studio 2010
Crystal report generation in visual studio 2010Crystal report generation in visual studio 2010
Crystal report generation in visual studio 2010
 
Access tips access and sql part 4 building select queries on-the-fly
Access tips  access and sql part 4  building select queries on-the-flyAccess tips  access and sql part 4  building select queries on-the-fly
Access tips access and sql part 4 building select queries on-the-fly
 
C# Tutorial MSM_Murach chapter-01-slides
C# Tutorial MSM_Murach chapter-01-slidesC# Tutorial MSM_Murach chapter-01-slides
C# Tutorial MSM_Murach chapter-01-slides
 
Report programming model for microsoft dynamics ax 2012
Report programming model for microsoft dynamics ax 2012Report programming model for microsoft dynamics ax 2012
Report programming model for microsoft dynamics ax 2012
 
Resolve dependency of dependencies using Inversion of Control and dependency ...
Resolve dependency of dependencies using Inversion of Control and dependency ...Resolve dependency of dependencies using Inversion of Control and dependency ...
Resolve dependency of dependencies using Inversion of Control and dependency ...
 
Struts Introduction Course
Struts Introduction CourseStruts Introduction Course
Struts Introduction Course
 

Ähnlich wie ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010

Generic Repository Pattern in MVC3 Application with Entity Framework
Generic Repository Pattern in MVC3 Application with Entity FrameworkGeneric Repository Pattern in MVC3 Application with Entity Framework
Generic Repository Pattern in MVC3 Application with Entity FrameworkAkhil Mittal
 
Enterprise Level Application Architecture with Web APIs using Entity Framewor...
Enterprise Level Application Architecture with Web APIs using Entity Framewor...Enterprise Level Application Architecture with Web APIs using Entity Framewor...
Enterprise Level Application Architecture with Web APIs using Entity Framewor...Akhil Mittal
 
Why use .net by naveen kumar veligeti
Why use .net by naveen kumar veligetiWhy use .net by naveen kumar veligeti
Why use .net by naveen kumar veligetiNaveen Kumar Veligeti
 
Learn about dot net attributes
Learn about dot net attributesLearn about dot net attributes
Learn about dot net attributessonia merchant
 
ASP.NET MVC Introduction
ASP.NET MVC IntroductionASP.NET MVC Introduction
ASP.NET MVC IntroductionSumit Chhabra
 
Tutorial mvc (pelajari ini jika ingin tahu mvc) keren
Tutorial mvc (pelajari ini jika ingin tahu mvc) kerenTutorial mvc (pelajari ini jika ingin tahu mvc) keren
Tutorial mvc (pelajari ini jika ingin tahu mvc) kerenSony Suci
 
Adding a view
Adding a viewAdding a view
Adding a viewNhan Do
 
AspMVC4 start101
AspMVC4 start101AspMVC4 start101
AspMVC4 start101Rich Helton
 
Learning .NET Attributes
Learning .NET AttributesLearning .NET Attributes
Learning .NET AttributesPooja Gaikwad
 
Learn dot net attributes
Learn dot net attributesLearn dot net attributes
Learn dot net attributessonia merchant
 
IRJET- Lightweight MVC Framework in PHP
IRJET- Lightweight MVC Framework in PHPIRJET- Lightweight MVC Framework in PHP
IRJET- Lightweight MVC Framework in PHPIRJET Journal
 
Adopting AnswerModules ModuleSuite
Adopting AnswerModules ModuleSuiteAdopting AnswerModules ModuleSuite
Adopting AnswerModules ModuleSuiteAnswerModules
 
Server side programming bt0083
Server side programming bt0083Server side programming bt0083
Server side programming bt0083Divyam Pateriya
 
ASP.NET MVC 5 Building Your First Web Application (A Beginner S Guide
ASP.NET MVC 5  Building Your First Web Application (A Beginner S GuideASP.NET MVC 5  Building Your First Web Application (A Beginner S Guide
ASP.NET MVC 5 Building Your First Web Application (A Beginner S GuideAlicia Buske
 
Introduction To Umbraco
Introduction To UmbracoIntroduction To Umbraco
Introduction To UmbracoKen Cenerelli
 
A report on mvc using the information
A report on mvc using the informationA report on mvc using the information
A report on mvc using the informationToushik Paul
 
Angular - Chapter 3 - Components
Angular - Chapter 3 - ComponentsAngular - Chapter 3 - Components
Angular - Chapter 3 - ComponentsWebStackAcademy
 

Ähnlich wie ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010 (20)

Generic Repository Pattern in MVC3 Application with Entity Framework
Generic Repository Pattern in MVC3 Application with Entity FrameworkGeneric Repository Pattern in MVC3 Application with Entity Framework
Generic Repository Pattern in MVC3 Application with Entity Framework
 
ASP.NET Identity
ASP.NET IdentityASP.NET Identity
ASP.NET Identity
 
Enterprise Level Application Architecture with Web APIs using Entity Framewor...
Enterprise Level Application Architecture with Web APIs using Entity Framewor...Enterprise Level Application Architecture with Web APIs using Entity Framewor...
Enterprise Level Application Architecture with Web APIs using Entity Framewor...
 
Why use .net by naveen kumar veligeti
Why use .net by naveen kumar veligetiWhy use .net by naveen kumar veligeti
Why use .net by naveen kumar veligeti
 
Learn about dot net attributes
Learn about dot net attributesLearn about dot net attributes
Learn about dot net attributes
 
ASP.NET MVC Introduction
ASP.NET MVC IntroductionASP.NET MVC Introduction
ASP.NET MVC Introduction
 
Tutorial mvc (pelajari ini jika ingin tahu mvc) keren
Tutorial mvc (pelajari ini jika ingin tahu mvc) kerenTutorial mvc (pelajari ini jika ingin tahu mvc) keren
Tutorial mvc (pelajari ini jika ingin tahu mvc) keren
 
Adding a view
Adding a viewAdding a view
Adding a view
 
AspMVC4 start101
AspMVC4 start101AspMVC4 start101
AspMVC4 start101
 
Learning .NET Attributes
Learning .NET AttributesLearning .NET Attributes
Learning .NET Attributes
 
Learn dot net attributes
Learn dot net attributesLearn dot net attributes
Learn dot net attributes
 
IRJET- Lightweight MVC Framework in PHP
IRJET- Lightweight MVC Framework in PHPIRJET- Lightweight MVC Framework in PHP
IRJET- Lightweight MVC Framework in PHP
 
MVC Training Part 2
MVC Training Part 2MVC Training Part 2
MVC Training Part 2
 
Adopting AnswerModules ModuleSuite
Adopting AnswerModules ModuleSuiteAdopting AnswerModules ModuleSuite
Adopting AnswerModules ModuleSuite
 
Server side programming bt0083
Server side programming bt0083Server side programming bt0083
Server side programming bt0083
 
Mvc acchitecture
Mvc acchitectureMvc acchitecture
Mvc acchitecture
 
ASP.NET MVC 5 Building Your First Web Application (A Beginner S Guide
ASP.NET MVC 5  Building Your First Web Application (A Beginner S GuideASP.NET MVC 5  Building Your First Web Application (A Beginner S Guide
ASP.NET MVC 5 Building Your First Web Application (A Beginner S Guide
 
Introduction To Umbraco
Introduction To UmbracoIntroduction To Umbraco
Introduction To Umbraco
 
A report on mvc using the information
A report on mvc using the informationA report on mvc using the information
A report on mvc using the information
 
Angular - Chapter 3 - Components
Angular - Chapter 3 - ComponentsAngular - Chapter 3 - Components
Angular - Chapter 3 - Components
 

Kürzlich hochgeladen

Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 

Kürzlich hochgeladen (20)

Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 

ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010

  • 1. ASP.NET MVC 3 Rapid Application Development Mădălin tefîrcă and Victor Chircu Abstract. This paper’s aim is to point out the RAD ( Rapid application devel- opment) elements present in the Microsoft’s MVC 3 and WCF 4.0 using Micro- soft Visual Studio 2010. It will describe why creating a new web application us- ing MVC 3 and WCF 4.0 is a easy and fast and also present simple ways to de- velop such applications. 1 Introduction The paper will describe to you the simplicity of developing a web application using Microsoft’s ASP.NET MVC 3 and WCF 4.0. Starting with the creation of a new project, adding new items, and quickly adding functionality including modeling, data- bases CRUD operations, UI elements, exposing and consuming REST services etc. There will be a brief presentation of the Html Helpers provided by Visual Studio, and the use of Dynamic Templates and how they can help you and a comparison between MVC 3 and Web Forms, the main web oriented frameworks provided by Microsoft. 2 Creating a new project Creating a new project is easier than ever. You can create an emtpy project allowing you to structure it the way you think is best fit, or you can choose to create a new Internet Application that will create for you a fully functioning project and fully ex- tensible. It is recommended to choose the second option, because this way you will not have to worry about the project structure and start developing since the very first minute. If you watch Fig.1 you can notice that Visual Studio has buit for you separate folders for Controllers, Views, Models, Scripts, Content. If you check the packages.config file you can also see that Visula Studio also added some useful packages for you like jQuery, jQuery-UI, jQuery.Validation meaning javascript libraries that will greatly improve your development and are very common to an experienced developer. The Entity Framework nuGet package is installed also by default and it comes in handy when working with complex databases since most of the work is done by this ORM (Object Relational Mapping tool ). In the ViewsShared folder you will find two .cshtml files, _Layout, used as a master page in the application, and Error, used as an global error page displayed to the user when the server crashes. These two are also added by default when creating a new MVC3 project.
  • 2. If you run the application you will notice that you have a fully functional project in- cluding a minimal authentication system that allows you to register users and authen- ticate them later on. Fig. 1. 3 Adding new items 3.1 Models Visual Studio also has provided for you an easy way for adding new items to your projects. You can add a new class in the Models folder that will be our new model. Right click the Models folder and select Add/Class. Name the class Employee and click Add. Inside the class you type “prop” and click the Tab key. This will instantly create for you a default property. Pressing the Tab key will switch you through the property type and property name in order to change them. Make for a start two prop-
  • 3. erties of type string and name them Name and CompanyName and an Id. Still inside the class, if you type in “ctor” and press Tab key it will automatically generate a con- structor for you. Inside the constructor assign the CompanyName property a string. Now you have your first model. Your code should look like this: public class Employee { public Employee() { this.CompanyName = "Fictional Company"; } public int Id { get; set; } public string Name { get; set; } public string CompanyName { get; set; } } 3.2 Context Now we will have to add a context for Entity Framework database. Int he Models folder add a new class. This should inherit the DBContext object from Sys- tem.Data.Entity. Add a property to the class that should look like this: public class EmployeeContext : DbContext { public DbSet<Employee> Employees { get; set; } } And now you have your context. 3.3 Controllers To add a new controller, you simply right click the Controllers folder and select Add/Controller. You type in the controller name, and then you get to choose between several scaffolding options like and empty controller, controller with empty actions or controller with read/write actions and views. The latter is the easiest way to develop. Choosing this option will require you to set the model class and the data context. Our model is Employee and context is EmployeeeContext. After selecting those previously mentioned click Add. This will generate you the whole mechanism required for CRUD (Create, Read, Update, Delete) operations over the Employee entity, including database operations, and UI. If you take a look in the Views/Employees folder you will see that Visual Studio has already generated all the html you need for the actions. If you run the application in your browser and go to host/Employees you will have the full functionality done.
  • 4. 4 Html helpers Html Helpers are provided by visual studio as support for rendering HTML controls in a view. It has a wide variety of choices like generating a link, forms, or even inputs or validations for inputs based on a predefined model. Also these helpers are highly extensible, customizing them being a great benefit for development. @Html.EditorFor(m => m.Property) @Html.DropDownListFor(m => m.Property, customSelectList) 5 Dynamic templates Templates are used to display a predetermined portion of the page layout which also contains fill-in-the-blanks that can be filled at run time. Template saves a lot of time because it can be reused in many places. Razor view engine includes a feature called Inline Template, which allows you to define a portion of dynamic HTML that can be reused. Also using Razor template you can pass template as a parameter to a method. You can make this for display or edit mode. All you must do is to set the @model of the template to the desired type. This can be a struct, a class, or even a collection. You can call this templates either by setting the name of the templates exactly the same as the type of the property of the model, or by setting an attribute to the property [UIHint(“templateName”)]. 6 WCF and REST Consuming and exposing REST services has become easier with the release of Win- dows Communication Foundation (WCF) 4.0, because of the inclusion of the Web HTTP programming model. For exposing RESTful services, all you need is the WCF Rest Service Template 40, which you can get through the Extension Manager (you can find it in the Tools menu). In a project created with the template mentioned earlier, you can add a new class for your service and decorate it with the [ServiceContract] attribute. Now you can add methods to your service class and decorate them with either the [WebGet] attribute (for GET requests) or with the [WebInvoke] attribute (for other HTTP me- thods). Both attributes take a UriTemplate as a parameter, in which you can specify the URI template to your resource. As a note, every token (string between “{}”) in the UriTemplate has to be a parameter to the method, as shown in the following example:
  • 5. [WebGet(UriTemplate = "Result?q={keyword}&lat={latitude}& lng={longitude}&rad={radius}&output={outputType}")] public string Get(string keyword, double latitude, double longitude, int radius, string outputType) After you have defined your RESTfull method, the only think that remains is to regis- ter it in the Global.asax file, in the RegisterRoutes method: RouteTable.Routes.Add(new ServiceRoute("WhereToGoService" , new WebServiceHostFactory(), typeof(WhereToGoService))) Now by accesing : <serv- er>:<port>/WhereToGoService/Result?q=Tuxy&lat=24.4&lng=24.4&rad=10&outp ut=json, the corresponding Get method from WhereToGoService will be called. Consuming RESTful services is easy if you use the right tools and .NET classes: • UriTemplate to specify the template for the URI, and using the UriTem- plate.BindByPosition or UriTemplate.BindByName methods to replace the tokens in the template with the actual values. • WebClient to get the data from the specified URI (for example you can use the WebClient.DownloadString method which returns the String received by accessing the URI specified as the method’s parameter). • LINQ to XML for converting the string into and XML, and manipulating the XML through LINQ sintax. • Newtonsoft’s Json.net library for manipulating strings in Json format (for ex- ample if the service that you are consuming returns information in Json for- mat), and for converting XML to Json and vice-versa. These are simple use cases used as proof of concept, but you can develop far more complex REST services using WCF 4.0, together with other frameworks and libraries provided by the .NET community. 7 Alternatives The main advantages of the ASP.NET MVC 3 are that it enables full control over the rendered HTML, it provides clean separation of concerns, easy integration with java- script, RESTful urls that enables SEO, no ViewState and PostBacks events. The web forms provide a wide variety of RAD elements, like drag & drop, automatic event generation, and it is easier for developers coming from the winform development to adapt. Another big plus for the web forms framework is the maturity - it has been around since 2002 and there is a big amount of information regarding solving prob- lems. Both of them are good choices, neither of the web frameworks are to be re- placed by the other, nor there are plans to have them merged.
  • 6. There are other vendors that offer 3rd party components and controls, like Telerik or DevExpress. These controls get rid of most of the boilerplate code that you would be writing, so they are feasible for small applications. But when it comes to building complex enterprise applications, you would notice that these 3rd party components do not cover all of the uses cases that you need, so ASP.MVC would be a safer bet. 8 Conclusion All mentioned above prove that MVC 3 is very reliable and can easily be used to develop complex web applications in a very short time, with great elegance. It is easy to start with at a beginner level, allowing you to build basic functionality without too much experience, and allowing more advanced developers to build solid, complex applications in a short time. When working on a project you have to take into consid- eration its purpose, scale, scalability and maintainability, and choose a framework accordingly. Even if lately Microsoft has integrated more and more RAD components into ASP.MVC, this framework is still designed for complex web application.