SlideShare a Scribd company logo
1 of 71
Download to read offline
3-tier Architecture
Hans-Petter Halvorsen, M.Sc.
Step by step Exercises
Client-
Server
Software Architecture
Web
Services
APIs
3-Tier
Architecture
API: Application Programming
Interface. Different devices or software
modules can share the same code.
Code once, use it many times
Web Services: A standard
way to get data over a
network/Internet using
standard Web protocols
(HTTP, etc.)
3-Tier: A way to structure your code
into logical parts. Different devices or
software modules canshare the same
code.
Good Software!
2-Tier
n-Tier
3
The database-centric style. Typically,
the clients communicate directly with
the database.
A three-tier style, in which clients
do not connect directly to the
database.
Web Services, etc.
3-tier/layer
Architecture
4
Presentation
Tier
Business
Logic
Tier
Data
Access
Tier
Data
Source
PL
BL
DAL
Note! The different layers can be on the
same computer (Logic Layers) or on different
Computers in a network (Physical Layers)
Data
Tier
-
DL
Logic
Tier
Why 3-Tier (N-Tier Architecture?)
• Flexible applications
• Reusable code
– Code once, use many times
• Modularized
– You need only to change part of the code
– You can deploy only one part
– You can Test only one part
– Multiple Developers
• Different parts (Tiers) can be stored on different
computers
• Different Platforms and Languages can be used
• etc.
5
6
http://en.wikipedia.org/wiki/Multitier_architecture
3-tier/layer Architecture
Presentation Tier
• This is the topmost level of the application.
• The presentation tier displays information related to such services as browsing
merchandise,purchasingand shoppingcart contents.
• It communicates with other tiers by which it puts out the results to the
browser/client tier and all other tiers in the network.
• In simple terms it is a layer which users can access directly such as a web page,
or an operatingsystems GUI
Application tier (business logic, logic tier, data access tier, or middle tier)
• The logical tier is pulled out from the presentation tier and,as its own layer.
• It controls an application’s functionalitybyperformingdetailedprocessing.
Data tier
• This tier consists of database servers.Here informationis stored and retrieved.
• This tier keeps data neutral and independentfrom application servers or
business logic.
• Givingdata its own tier also improves scalabilityand performance.
7
http://en.wikipedia.org/wiki/Multitier_architecture
3-tier Architecture
Presentation Tier
Business Logic Tier
Data Access Tier
Database
Presentation Tier Presentation Tier
Stored Procedures
Data Tier
Logic Tier
3-tier Architecture
Presentation Tier
Business Logic Tier
Data Access Tier
Database
Presentation Tier Presentation Tier
Stored Procedures
Different Devices can share
the same Business and Data
Access Code
The different Tiers can be
physical or logical Data Tier
Logic Tier
Web
Server
3-tier + WebService Architecture - Example
Presentation
Tier
Business/Data
Logic Tier
Data
Source
Web
Services
Server(s)
Data
Tier
Stored
Procedures
Server-side Client-side
Web
Server
3-tier + WebService Architecture - Example
Presentation
Tier
Business/Dat
a Logic Tier
Data
Source
Web
Services
Team
Foundation
Server
TFS Cient
Installed on one or more
Windows Servers in your LAN
or in the Cloud
Data
Tier
Stored
Procedures
Team FoundationServer
3-tier Architecture Scenarios
Presentation Layer
Business Logic
Data Access Logic
Database
Presentation Layer Presentation Layer
Stored
Procedures
Client
Client
Client
Web
Server
Web Service
Presentation Layer
Client
Presentation Layer
Internet
Local Network (LAN)
Client
Firewall
Presentation Layer
Server
Server
Exercises
1. Create Data Tier (Database)
2. Create Logic Tier (Database Communication Logic)
Create Presentation Tier (User Interface Logic):
3. WebApp: Using ASP.NET Web Forms (WS normallynot needed)
4. Desktop App: Using WinForms
A. Without Web Services (We assume the App will be used
only in the LAN and that we have direct access to the
Database)
B. With Web Services (We assume the App should be used
on Internet outside the Firewall without direct DB access)
Database
Presentation Tier
e.g., ADO, ADO.NET
Logic Tier
Web Service
Business Tier
Data Access Tier
Data Tier
Stored Procedures
Views
Tables
Web Server
Database
Server
Presentation Tier
Client
ASP.NET Web Forms
Web App
Presentation Tier
Client
Client
Client
WinForms
3-tier
Architecture
Scenarios
Firewall
Clients
Desktop App
Mobile
App
Internet
Local
Network
Note! The different Tiers
can be on the same
Computer (Logic Layers) or
on different Computers in a
network (Physical Layers)
Android, iOS, Windows
8/Windows Phone,
etc.
Presentation Tiers
Devices can share the same
Business/Logic Tier and
APIs
Seperate Presentation Tier
for each Device App
API
API
API
API
15
Visual Studio Projects
Solution with all Projects
(Logic Tier, Web Service,
Desktop App, Web App,
Mobile App)
Solution with Projects
used by Web App
(Logic Tier, Web App)
Data Tier
We are going to create the Database / Data Layer/Tier,
including:
1. Tables
2. Views
3. Stored Procedures
4. Triggers
5. Script for some “Dummy” Data
Download Zip Files with Tables, Views, Stored Procedures
and Triggerse in order to create the Data Tier in SQL Server
(The ZIP File is located on the same place as this File)
16
Note! Install them
in this order
Data Tier
17
Tables
Views
Stored Procedures
SQL Server
Triggers
Data Tier
18
Database Tables
19
Execute the different
Scripts inside SQL Server
Management Studio
20
You are finished with the Exercise
Create Logic Tier
21
Database
Presentation Tier
Logic Tier
ASP.NET Web Forms
Data Tier
Presentation Tier Presentation Tier
WinForms Windows Store App
Purpose:
• All the Apps should/could
share the same Logic Tier
• To make your Apps easier
to maintain and extend
• etc.
22
Create an Empty (Blank) Solution in Visual Studio
23
Add Project for Logic Tier (Data Access)
Select a “Class Library” Project
“LogicTier”
24
Add a New Class to the
Project (“StudentData.cs”)
“StudentData.cs”
25
Create the Code, e.g., like this (“StudentData.cs”):
Create your own Namespace
Improvements: Use Try... Catch...
A View that collects data
from several tables
26
You should test the SQL Query in the SQL Server
Management Studio first
27
Code (“StudentData.cs”):
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Data;
namespace Tuc.School.LogicTier
{
public class StudentData
{
public DataSet GetStudentDB(string connectionString)
{
string selectSQL = "select StudentName, StudentNumber, SchoolName, ClassName,
Grade from StudentData order by StudentName";
// Define the ADO.NET objects.
SqlConnection con = new SqlConnection(connectionString);
SqlDataAdapter da = new SqlDataAdapter(selectSQL, con);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
}
}
28
Create a proper name for the Assembly (.dll File)
This will be the Assembly for your
Logic Tier, that can be imported
and used in other projects.
Create once – use it many times!!
Then Build your
Project (hopefully
with no errors)
Right-click on the Project in the Solution Explorer and select Properties
29
You are finished with the Exercise
30
Presentation Layer
Web App: ASP.NET WebForms
We will create a WebForm like this where the data comes from our Logic Tier
31
Add Project for PresentationTier
(ASP.NET WebForm)
32
Add a New Class (“Student.cs”)
33
Add Code (“Student.cs”)
Add a Reference to the Assembly in the Logic Tier
Note! This is our Logic Tier
34
Code for “Student.cs”
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using Tuc.School.LogicTier;
namespace Tuc.School.WebApp
{
public class Student
{
public DataSet GetStudent(string connectionString)
{
StudentData studentData = new StudentData();
return studentData.GetStudentDB(connectionString);
}
}
}
Get Dat from our
Logic Tier
Since we are using the DataSet Class
Our Logic Tier
35
Add a New WebForm (StudentInformation.aspx)
36
Create WebForm Page (“StudentInformation.aspx”)
GridView (Drag & Drop from Toolbox or create
code in .aspx file)
37
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="StudentInformation.aspx.cs" Inherits="WebApp.StudentInformation" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Student Information</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>Student Information</h1>
</div>
<asp:GridView ID="gridStudentData" runat="server">
</asp:GridView>
</form>
</body>
</html>
HTML /ASPX Code (“StudentInformation.aspx”)
38
Code behind for the Web Form (“StudentInformation.aspx.cs”)
using System.Web.Configuration;
using Tuc.School.WebApp;
namespace WebApp
{
public partial class StudentInformation : System.Web.UI.Page
{
private string connectionString =
WebConfigurationManager.ConnectionStrings["SCHOOLConnectionString"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
FillStudentGrid();
}
}
private void FillStudentGrid()
{
DataSet ds = new DataSet();
Student studentList = new Student();
ds = studentList.GetStudent(connectionString);
gridStudentData.DataSource = ds;
gridStudentData.DataBind();
}
}
}
Note!
Web.Config
39
Store the “ConnectionString”for your Database in “Web.Config”
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<add name="SCHOOLConnectionString" connectionString="Data Source=macwin8;Initial
Catalog=SCHOOL;Persist Security Info=True;User ID=sa;Password=xxxxxx"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
</configuration>
Then you can easly switch Databsse without changingthe Code!!
40
Test your Web App
Note! We have used a “View” in order to get data from several tables
41
Additional
Exercise:
Update GridView with New
Data from Database
Goto New WebForm
in order to Add another
Student
42
You are finished with the Exercise
43
Presentation Layer
Desktop App: WinForms
Part A: Without Web Services (we assume the App will be used only in the local LAN (or
local on the same computer where the database is located) and that we have direct access
to the Database)
Label
DataGridView
44
Add a WinForm Project
45
Add a New Class (“StudentWinForm.cs”)
46
Add Code in Class
Add a Reference to the
Assembly in the Logic Tier
47
Code for Class “StudentWinForm.cs”
using System.Data;
using Tuc.School.LogicTier;
namespace Tuc.School.WinFormApp
{
class StudentWinForm
{
public DataSet GetStudent(string connectionString)
{
StudentData studentData = new StudentData();
return studentData.GetStudentDB(connectionString);
}
}
}
Reference to our Logic Tier
Since we are using the DataSet Class
Our Database Method in our Logic Tier
48
Create Form
Label
DataGridView
49
Create Form Code
50
using System.Configuration;
using Tuc.School.WinFormApp;
namespace WinFormApp
{
public partial class Form1 : Form
{
private string connectionString =
ConfigurationManager.ConnectionStrings["SCHOOLConnectionString"].ConnectionString;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
FillStudentGrid();
}
private void FillStudentGrid()
{
DataSet ds = new DataSet();
StudentWinForm studentList = new StudentWinForm();
ds = studentList.GetStudent(connectionString);
dataGridViewStudentInformation.DataSource = ds.Tables[0];
}
}
}
WinForm Code
Note!
ConnectionString is
stored in App.config
51
Note! Add System.Configuration Reference
52
Create DB ConnectionString in App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<connectionStrings>
<add name="SCHOOLConnectionString" connectionString="Data Source=macwin8;Initial Catalog=SCHOOL;Persist Security
Info=True;User ID=sa;Password=xxxxxx"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
53
Test it
It works!!!
54
You are finished with the Exercise
55
Presentation Layer
Desktop App: WinForms
Part B: Using Web Services (we assume the The App should be used on Internet outside
the Firewall)
Label
DataGridView
56
Step 1: Create Web Service
Add Web Service:
Create an ASP.NET Project:
“SchoolWS”
“SchoolWS.asmx”
57
Web Service Code
Database ConnectionString
is located in Web.config
Web Service Method
58
Database ConnectionString is located in Web.config
59
Test Web Service
It Works!!
Click to Test the Web Service
Method we created
60
Deploy/Publish Web Service to IIS
CopyWeb Service Files (Project) to default IIS Directory: C:inetpubwwwroot
61
62
Test if WS working:
http://localhost/SchoolWS
63
Step 2: Use Web Service in WinForm
Create New WinForm Project:
“WinFormAppWSClient”
64
Add Web Service Reference
Our Web Service Methods
Create GUI
Label
DataGridView
66
Create Code
67
using System.Windows.Forms;
namespace WinFormAppWSClient
{
public partial class FormWSClient : Form
{
public FormWSClient()
{
InitializeComponent();
}
private void FormWSClient_Load(object sender, EventArgs e)
{
FillStudentGrid();
}
private void FillStudentGrid()
{
DataSet ds = new DataSet();
SchoolWSReference.SchoolWSSoapClient schoolWs = new
SchoolWSReference.SchoolWSSoapClient();
ds = schoolWs.GetStudent();
dataGridViewStudentInformation.DataSource = ds.Tables[0];
}
}
WinForm Code
Call the Web Service method
Fill GridView
68
Test it:
It works!!!
69
You are finished with the Exercise
Hans-Petter Halvorsen, M.Sc.
University College of Southeast Norway
www.usn.no
E-mail: hans.p.halvorsen@hit.no
Blog: http://home.hit.no/~hansha/

More Related Content

Similar to 3-Tier Architecture Step By Step Exercises

Dot Net Fundamentals
Dot Net FundamentalsDot Net Fundamentals
Dot Net FundamentalsLiquidHub
 
Data Access
Data AccessData Access
Data Accesseclumson
 
3 tier architecture in asp.net
3 tier architecture in asp.net3 tier architecture in asp.net
3 tier architecture in asp.netRavi Bansal
 
Entity Framework Code First Migrations
Entity Framework Code First MigrationsEntity Framework Code First Migrations
Entity Framework Code First MigrationsDiluka99999
 
Overview of VS2010 and .NET 4.0
Overview of VS2010 and .NET 4.0Overview of VS2010 and .NET 4.0
Overview of VS2010 and .NET 4.0Bruce Johnson
 
Topic1 Understanding Distributed Information Systems
Topic1 Understanding Distributed Information SystemsTopic1 Understanding Distributed Information Systems
Topic1 Understanding Distributed Information Systemssanjoysanyal
 
Asp.net new
Asp.net newAsp.net new
Asp.net newGanesh Jaya
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfoliomwillmer
 
Yemo_Capstone_MS_Fairfield University
Yemo_Capstone_MS_Fairfield UniversityYemo_Capstone_MS_Fairfield University
Yemo_Capstone_MS_Fairfield UniversityGuillermo Julca
 
My Saminar On Php
My Saminar On PhpMy Saminar On Php
My Saminar On PhpArjun Kumawat
 
Sky High With Azure
Sky High With AzureSky High With Azure
Sky High With AzureClint Edmonson
 
The Magic Of Application Lifecycle Management In Vs Public
The Magic Of Application Lifecycle Management In Vs PublicThe Magic Of Application Lifecycle Management In Vs Public
The Magic Of Application Lifecycle Management In Vs PublicDavid Solivan
 
3 Tier Architecture
3 Tier Architecture3 Tier Architecture
3 Tier Architectureguestd0cc01
 
Project seminar
Project seminarProject seminar
Project seminarKuldeep Jain
 
Introduction to asp
Introduction to aspIntroduction to asp
Introduction to aspMadhuri Kavade
 
3 Tier Architecture
3  Tier Architecture3  Tier Architecture
3 Tier ArchitectureWebx
 
Clean architecture with asp.net core
Clean architecture with asp.net coreClean architecture with asp.net core
Clean architecture with asp.net coreSam Nasr, MCSA, MVP
 

Similar to 3-Tier Architecture Step By Step Exercises (20)

Dot Net Fundamentals
Dot Net FundamentalsDot Net Fundamentals
Dot Net Fundamentals
 
Data Access
Data AccessData Access
Data Access
 
unit 3.docx
unit 3.docxunit 3.docx
unit 3.docx
 
3 tier architecture in asp.net
3 tier architecture in asp.net3 tier architecture in asp.net
3 tier architecture in asp.net
 
Entity Framework Code First Migrations
Entity Framework Code First MigrationsEntity Framework Code First Migrations
Entity Framework Code First Migrations
 
Overview of VS2010 and .NET 4.0
Overview of VS2010 and .NET 4.0Overview of VS2010 and .NET 4.0
Overview of VS2010 and .NET 4.0
 
Topic1 Understanding Distributed Information Systems
Topic1 Understanding Distributed Information SystemsTopic1 Understanding Distributed Information Systems
Topic1 Understanding Distributed Information Systems
 
Asp.net new
Asp.net newAsp.net new
Asp.net new
 
Dbms fast track 2/3
Dbms fast track 2/3Dbms fast track 2/3
Dbms fast track 2/3
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfolio
 
Yemo_Capstone_MS_Fairfield University
Yemo_Capstone_MS_Fairfield UniversityYemo_Capstone_MS_Fairfield University
Yemo_Capstone_MS_Fairfield University
 
My Saminar On Php
My Saminar On PhpMy Saminar On Php
My Saminar On Php
 
.NET presentation
.NET presentation.NET presentation
.NET presentation
 
Sky High With Azure
Sky High With AzureSky High With Azure
Sky High With Azure
 
The Magic Of Application Lifecycle Management In Vs Public
The Magic Of Application Lifecycle Management In Vs PublicThe Magic Of Application Lifecycle Management In Vs Public
The Magic Of Application Lifecycle Management In Vs Public
 
3 Tier Architecture
3 Tier Architecture3 Tier Architecture
3 Tier Architecture
 
Project seminar
Project seminarProject seminar
Project seminar
 
Introduction to asp
Introduction to aspIntroduction to asp
Introduction to asp
 
3 Tier Architecture
3  Tier Architecture3  Tier Architecture
3 Tier Architecture
 
Clean architecture with asp.net core
Clean architecture with asp.net coreClean architecture with asp.net core
Clean architecture with asp.net core
 

More from Miranda Anderson

UED102 STUDY SKILLS PORTF. Online assignment writing service.
UED102 STUDY SKILLS PORTF. Online assignment writing service.UED102 STUDY SKILLS PORTF. Online assignment writing service.
UED102 STUDY SKILLS PORTF. Online assignment writing service.Miranda Anderson
 
Master Essay Writers UK Reviews - 4 Reviews Of Masteressaywriters.Co.Uk
Master Essay Writers UK Reviews - 4 Reviews Of Masteressaywriters.Co.UkMaster Essay Writers UK Reviews - 4 Reviews Of Masteressaywriters.Co.Uk
Master Essay Writers UK Reviews - 4 Reviews Of Masteressaywriters.Co.UkMiranda Anderson
 
Write My Paper For Cheap, Cheap Online. Online assignment writing service.
Write My Paper For Cheap, Cheap Online. Online assignment writing service.Write My Paper For Cheap, Cheap Online. Online assignment writing service.
Write My Paper For Cheap, Cheap Online. Online assignment writing service.Miranda Anderson
 
Academic Essay Writing. Online assignment writing service.
Academic Essay Writing. Online assignment writing service.Academic Essay Writing. Online assignment writing service.
Academic Essay Writing. Online assignment writing service.Miranda Anderson
 
Amazing Cause And Effect Essay Examples Thatsn
Amazing Cause And Effect Essay Examples ThatsnAmazing Cause And Effect Essay Examples Thatsn
Amazing Cause And Effect Essay Examples ThatsnMiranda Anderson
 
New Year Printables Kindergarten Writing, New
New Year Printables Kindergarten Writing, NewNew Year Printables Kindergarten Writing, New
New Year Printables Kindergarten Writing, NewMiranda Anderson
 
Essay Importance Group Discussion Help Research Paper
Essay Importance Group Discussion Help Research PaperEssay Importance Group Discussion Help Research Paper
Essay Importance Group Discussion Help Research PaperMiranda Anderson
 
Where Do I See Myself In 10 Years Essay. Where Do
Where Do I See Myself In 10 Years Essay. Where DoWhere Do I See Myself In 10 Years Essay. Where Do
Where Do I See Myself In 10 Years Essay. Where DoMiranda Anderson
 
Things To Focus On While Writing A Literary Analysis
Things To Focus On While Writing A Literary AnalysisThings To Focus On While Writing A Literary Analysis
Things To Focus On While Writing A Literary AnalysisMiranda Anderson
 
A Notepad With The Words Cause Signal Words And Ph
A Notepad With The Words Cause Signal Words And PhA Notepad With The Words Cause Signal Words And Ph
A Notepad With The Words Cause Signal Words And PhMiranda Anderson
 
Obesity Essay Final - Discuss How Obesity Affects The Bra
Obesity Essay Final - Discuss How Obesity Affects The BraObesity Essay Final - Discuss How Obesity Affects The Bra
Obesity Essay Final - Discuss How Obesity Affects The BraMiranda Anderson
 
Term Paper Writing Services Reviews - The First Writing Service.
Term Paper Writing Services Reviews - The First Writing Service.Term Paper Writing Services Reviews - The First Writing Service.
Term Paper Writing Services Reviews - The First Writing Service.Miranda Anderson
 
College Admission Essay Writing Service - Get Ac
College Admission Essay Writing Service - Get AcCollege Admission Essay Writing Service - Get Ac
College Admission Essay Writing Service - Get AcMiranda Anderson
 
MLASamplePaper. Online assignment writing service.
MLASamplePaper. Online assignment writing service.MLASamplePaper. Online assignment writing service.
MLASamplePaper. Online assignment writing service.Miranda Anderson
 
Unsolicited Proposal Template. Online assignment writing service.
Unsolicited Proposal Template. Online assignment writing service.Unsolicited Proposal Template. Online assignment writing service.
Unsolicited Proposal Template. Online assignment writing service.Miranda Anderson
 
Ucas Personal Statement Examples - Pin On Teachin
Ucas Personal Statement Examples - Pin On TeachinUcas Personal Statement Examples - Pin On Teachin
Ucas Personal Statement Examples - Pin On TeachinMiranda Anderson
 
IELTS BAND SCORES - Mr. Einstein Pare. Online assignment writing service.
IELTS BAND SCORES - Mr. Einstein Pare. Online assignment writing service.IELTS BAND SCORES - Mr. Einstein Pare. Online assignment writing service.
IELTS BAND SCORES - Mr. Einstein Pare. Online assignment writing service.Miranda Anderson
 
Grad School Personal Statement Template Busi
Grad School Personal Statement  Template BusiGrad School Personal Statement  Template Busi
Grad School Personal Statement Template BusiMiranda Anderson
 
Mohawk Via Linen Writing Paper Natural Shade Wa
Mohawk Via Linen Writing Paper Natural Shade WaMohawk Via Linen Writing Paper Natural Shade Wa
Mohawk Via Linen Writing Paper Natural Shade WaMiranda Anderson
 
How To Write A Research Introduction 10 Steps (With Pictures) Essay ...
How To Write A Research Introduction 10 Steps (With Pictures)  Essay ...How To Write A Research Introduction 10 Steps (With Pictures)  Essay ...
How To Write A Research Introduction 10 Steps (With Pictures) Essay ...Miranda Anderson
 

More from Miranda Anderson (20)

UED102 STUDY SKILLS PORTF. Online assignment writing service.
UED102 STUDY SKILLS PORTF. Online assignment writing service.UED102 STUDY SKILLS PORTF. Online assignment writing service.
UED102 STUDY SKILLS PORTF. Online assignment writing service.
 
Master Essay Writers UK Reviews - 4 Reviews Of Masteressaywriters.Co.Uk
Master Essay Writers UK Reviews - 4 Reviews Of Masteressaywriters.Co.UkMaster Essay Writers UK Reviews - 4 Reviews Of Masteressaywriters.Co.Uk
Master Essay Writers UK Reviews - 4 Reviews Of Masteressaywriters.Co.Uk
 
Write My Paper For Cheap, Cheap Online. Online assignment writing service.
Write My Paper For Cheap, Cheap Online. Online assignment writing service.Write My Paper For Cheap, Cheap Online. Online assignment writing service.
Write My Paper For Cheap, Cheap Online. Online assignment writing service.
 
Academic Essay Writing. Online assignment writing service.
Academic Essay Writing. Online assignment writing service.Academic Essay Writing. Online assignment writing service.
Academic Essay Writing. Online assignment writing service.
 
Amazing Cause And Effect Essay Examples Thatsn
Amazing Cause And Effect Essay Examples ThatsnAmazing Cause And Effect Essay Examples Thatsn
Amazing Cause And Effect Essay Examples Thatsn
 
New Year Printables Kindergarten Writing, New
New Year Printables Kindergarten Writing, NewNew Year Printables Kindergarten Writing, New
New Year Printables Kindergarten Writing, New
 
Essay Importance Group Discussion Help Research Paper
Essay Importance Group Discussion Help Research PaperEssay Importance Group Discussion Help Research Paper
Essay Importance Group Discussion Help Research Paper
 
Where Do I See Myself In 10 Years Essay. Where Do
Where Do I See Myself In 10 Years Essay. Where DoWhere Do I See Myself In 10 Years Essay. Where Do
Where Do I See Myself In 10 Years Essay. Where Do
 
Things To Focus On While Writing A Literary Analysis
Things To Focus On While Writing A Literary AnalysisThings To Focus On While Writing A Literary Analysis
Things To Focus On While Writing A Literary Analysis
 
A Notepad With The Words Cause Signal Words And Ph
A Notepad With The Words Cause Signal Words And PhA Notepad With The Words Cause Signal Words And Ph
A Notepad With The Words Cause Signal Words And Ph
 
Obesity Essay Final - Discuss How Obesity Affects The Bra
Obesity Essay Final - Discuss How Obesity Affects The BraObesity Essay Final - Discuss How Obesity Affects The Bra
Obesity Essay Final - Discuss How Obesity Affects The Bra
 
Term Paper Writing Services Reviews - The First Writing Service.
Term Paper Writing Services Reviews - The First Writing Service.Term Paper Writing Services Reviews - The First Writing Service.
Term Paper Writing Services Reviews - The First Writing Service.
 
College Admission Essay Writing Service - Get Ac
College Admission Essay Writing Service - Get AcCollege Admission Essay Writing Service - Get Ac
College Admission Essay Writing Service - Get Ac
 
MLASamplePaper. Online assignment writing service.
MLASamplePaper. Online assignment writing service.MLASamplePaper. Online assignment writing service.
MLASamplePaper. Online assignment writing service.
 
Unsolicited Proposal Template. Online assignment writing service.
Unsolicited Proposal Template. Online assignment writing service.Unsolicited Proposal Template. Online assignment writing service.
Unsolicited Proposal Template. Online assignment writing service.
 
Ucas Personal Statement Examples - Pin On Teachin
Ucas Personal Statement Examples - Pin On TeachinUcas Personal Statement Examples - Pin On Teachin
Ucas Personal Statement Examples - Pin On Teachin
 
IELTS BAND SCORES - Mr. Einstein Pare. Online assignment writing service.
IELTS BAND SCORES - Mr. Einstein Pare. Online assignment writing service.IELTS BAND SCORES - Mr. Einstein Pare. Online assignment writing service.
IELTS BAND SCORES - Mr. Einstein Pare. Online assignment writing service.
 
Grad School Personal Statement Template Busi
Grad School Personal Statement  Template BusiGrad School Personal Statement  Template Busi
Grad School Personal Statement Template Busi
 
Mohawk Via Linen Writing Paper Natural Shade Wa
Mohawk Via Linen Writing Paper Natural Shade WaMohawk Via Linen Writing Paper Natural Shade Wa
Mohawk Via Linen Writing Paper Natural Shade Wa
 
How To Write A Research Introduction 10 Steps (With Pictures) Essay ...
How To Write A Research Introduction 10 Steps (With Pictures)  Essay ...How To Write A Research Introduction 10 Steps (With Pictures)  Essay ...
How To Write A Research Introduction 10 Steps (With Pictures) Essay ...
 

Recently uploaded

Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 

Recently uploaded (20)

Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 

3-Tier Architecture Step By Step Exercises

  • 1. 3-tier Architecture Hans-Petter Halvorsen, M.Sc. Step by step Exercises
  • 2. Client- Server Software Architecture Web Services APIs 3-Tier Architecture API: Application Programming Interface. Different devices or software modules can share the same code. Code once, use it many times Web Services: A standard way to get data over a network/Internet using standard Web protocols (HTTP, etc.) 3-Tier: A way to structure your code into logical parts. Different devices or software modules canshare the same code. Good Software! 2-Tier n-Tier
  • 3. 3 The database-centric style. Typically, the clients communicate directly with the database. A three-tier style, in which clients do not connect directly to the database. Web Services, etc.
  • 4. 3-tier/layer Architecture 4 Presentation Tier Business Logic Tier Data Access Tier Data Source PL BL DAL Note! The different layers can be on the same computer (Logic Layers) or on different Computers in a network (Physical Layers) Data Tier - DL Logic Tier
  • 5. Why 3-Tier (N-Tier Architecture?) • Flexible applications • Reusable code – Code once, use many times • Modularized – You need only to change part of the code – You can deploy only one part – You can Test only one part – Multiple Developers • Different parts (Tiers) can be stored on different computers • Different Platforms and Languages can be used • etc. 5
  • 7. 3-tier/layer Architecture Presentation Tier • This is the topmost level of the application. • The presentation tier displays information related to such services as browsing merchandise,purchasingand shoppingcart contents. • It communicates with other tiers by which it puts out the results to the browser/client tier and all other tiers in the network. • In simple terms it is a layer which users can access directly such as a web page, or an operatingsystems GUI Application tier (business logic, logic tier, data access tier, or middle tier) • The logical tier is pulled out from the presentation tier and,as its own layer. • It controls an application’s functionalitybyperformingdetailedprocessing. Data tier • This tier consists of database servers.Here informationis stored and retrieved. • This tier keeps data neutral and independentfrom application servers or business logic. • Givingdata its own tier also improves scalabilityand performance. 7 http://en.wikipedia.org/wiki/Multitier_architecture
  • 8. 3-tier Architecture Presentation Tier Business Logic Tier Data Access Tier Database Presentation Tier Presentation Tier Stored Procedures Data Tier Logic Tier
  • 9. 3-tier Architecture Presentation Tier Business Logic Tier Data Access Tier Database Presentation Tier Presentation Tier Stored Procedures Different Devices can share the same Business and Data Access Code The different Tiers can be physical or logical Data Tier Logic Tier
  • 10. Web Server 3-tier + WebService Architecture - Example Presentation Tier Business/Data Logic Tier Data Source Web Services Server(s) Data Tier Stored Procedures Server-side Client-side
  • 11. Web Server 3-tier + WebService Architecture - Example Presentation Tier Business/Dat a Logic Tier Data Source Web Services Team Foundation Server TFS Cient Installed on one or more Windows Servers in your LAN or in the Cloud Data Tier Stored Procedures Team FoundationServer
  • 12. 3-tier Architecture Scenarios Presentation Layer Business Logic Data Access Logic Database Presentation Layer Presentation Layer Stored Procedures Client Client Client Web Server Web Service Presentation Layer Client Presentation Layer Internet Local Network (LAN) Client Firewall Presentation Layer Server Server
  • 13. Exercises 1. Create Data Tier (Database) 2. Create Logic Tier (Database Communication Logic) Create Presentation Tier (User Interface Logic): 3. WebApp: Using ASP.NET Web Forms (WS normallynot needed) 4. Desktop App: Using WinForms A. Without Web Services (We assume the App will be used only in the LAN and that we have direct access to the Database) B. With Web Services (We assume the App should be used on Internet outside the Firewall without direct DB access)
  • 14. Database Presentation Tier e.g., ADO, ADO.NET Logic Tier Web Service Business Tier Data Access Tier Data Tier Stored Procedures Views Tables Web Server Database Server Presentation Tier Client ASP.NET Web Forms Web App Presentation Tier Client Client Client WinForms 3-tier Architecture Scenarios Firewall Clients Desktop App Mobile App Internet Local Network Note! The different Tiers can be on the same Computer (Logic Layers) or on different Computers in a network (Physical Layers) Android, iOS, Windows 8/Windows Phone, etc. Presentation Tiers Devices can share the same Business/Logic Tier and APIs Seperate Presentation Tier for each Device App API API API API
  • 15. 15 Visual Studio Projects Solution with all Projects (Logic Tier, Web Service, Desktop App, Web App, Mobile App) Solution with Projects used by Web App (Logic Tier, Web App)
  • 16. Data Tier We are going to create the Database / Data Layer/Tier, including: 1. Tables 2. Views 3. Stored Procedures 4. Triggers 5. Script for some “Dummy” Data Download Zip Files with Tables, Views, Stored Procedures and Triggerse in order to create the Data Tier in SQL Server (The ZIP File is located on the same place as this File) 16 Note! Install them in this order
  • 19. 19 Execute the different Scripts inside SQL Server Management Studio
  • 20. 20 You are finished with the Exercise
  • 21. Create Logic Tier 21 Database Presentation Tier Logic Tier ASP.NET Web Forms Data Tier Presentation Tier Presentation Tier WinForms Windows Store App Purpose: • All the Apps should/could share the same Logic Tier • To make your Apps easier to maintain and extend • etc.
  • 22. 22 Create an Empty (Blank) Solution in Visual Studio
  • 23. 23 Add Project for Logic Tier (Data Access) Select a “Class Library” Project “LogicTier”
  • 24. 24 Add a New Class to the Project (“StudentData.cs”) “StudentData.cs”
  • 25. 25 Create the Code, e.g., like this (“StudentData.cs”): Create your own Namespace Improvements: Use Try... Catch... A View that collects data from several tables
  • 26. 26 You should test the SQL Query in the SQL Server Management Studio first
  • 27. 27 Code (“StudentData.cs”): using System.Data.SqlClient; using System.Data.SqlTypes; using System.Data; namespace Tuc.School.LogicTier { public class StudentData { public DataSet GetStudentDB(string connectionString) { string selectSQL = "select StudentName, StudentNumber, SchoolName, ClassName, Grade from StudentData order by StudentName"; // Define the ADO.NET objects. SqlConnection con = new SqlConnection(connectionString); SqlDataAdapter da = new SqlDataAdapter(selectSQL, con); DataSet ds = new DataSet(); da.Fill(ds); return ds; } } }
  • 28. 28 Create a proper name for the Assembly (.dll File) This will be the Assembly for your Logic Tier, that can be imported and used in other projects. Create once – use it many times!! Then Build your Project (hopefully with no errors) Right-click on the Project in the Solution Explorer and select Properties
  • 29. 29 You are finished with the Exercise
  • 30. 30 Presentation Layer Web App: ASP.NET WebForms We will create a WebForm like this where the data comes from our Logic Tier
  • 31. 31 Add Project for PresentationTier (ASP.NET WebForm)
  • 32. 32 Add a New Class (“Student.cs”)
  • 33. 33 Add Code (“Student.cs”) Add a Reference to the Assembly in the Logic Tier Note! This is our Logic Tier
  • 34. 34 Code for “Student.cs” using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data; using Tuc.School.LogicTier; namespace Tuc.School.WebApp { public class Student { public DataSet GetStudent(string connectionString) { StudentData studentData = new StudentData(); return studentData.GetStudentDB(connectionString); } } } Get Dat from our Logic Tier Since we are using the DataSet Class Our Logic Tier
  • 35. 35 Add a New WebForm (StudentInformation.aspx)
  • 36. 36 Create WebForm Page (“StudentInformation.aspx”) GridView (Drag & Drop from Toolbox or create code in .aspx file)
  • 37. 37 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="StudentInformation.aspx.cs" Inherits="WebApp.StudentInformation" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Student Information</title> </head> <body> <form id="form1" runat="server"> <div> <h1>Student Information</h1> </div> <asp:GridView ID="gridStudentData" runat="server"> </asp:GridView> </form> </body> </html> HTML /ASPX Code (“StudentInformation.aspx”)
  • 38. 38 Code behind for the Web Form (“StudentInformation.aspx.cs”) using System.Web.Configuration; using Tuc.School.WebApp; namespace WebApp { public partial class StudentInformation : System.Web.UI.Page { private string connectionString = WebConfigurationManager.ConnectionStrings["SCHOOLConnectionString"].ConnectionString; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { FillStudentGrid(); } } private void FillStudentGrid() { DataSet ds = new DataSet(); Student studentList = new Student(); ds = studentList.GetStudent(connectionString); gridStudentData.DataSource = ds; gridStudentData.DataBind(); } } } Note! Web.Config
  • 39. 39 Store the “ConnectionString”for your Database in “Web.Config” <?xml version="1.0" encoding="utf-8"?> <!-- For more information on how to configure your ASP.NET application, please visit http://go.microsoft.com/fwlink/?LinkId=169433 --> <configuration> <connectionStrings> <add name="SCHOOLConnectionString" connectionString="Data Source=macwin8;Initial Catalog=SCHOOL;Persist Security Info=True;User ID=sa;Password=xxxxxx" providerName="System.Data.SqlClient" /> </connectionStrings> <system.web> <compilation debug="true" targetFramework="4.5" /> <httpRuntime targetFramework="4.5" /> </system.web> </configuration> Then you can easly switch Databsse without changingthe Code!!
  • 40. 40 Test your Web App Note! We have used a “View” in order to get data from several tables
  • 41. 41 Additional Exercise: Update GridView with New Data from Database Goto New WebForm in order to Add another Student
  • 42. 42 You are finished with the Exercise
  • 43. 43 Presentation Layer Desktop App: WinForms Part A: Without Web Services (we assume the App will be used only in the local LAN (or local on the same computer where the database is located) and that we have direct access to the Database) Label DataGridView
  • 44. 44 Add a WinForm Project
  • 45. 45 Add a New Class (“StudentWinForm.cs”)
  • 46. 46 Add Code in Class Add a Reference to the Assembly in the Logic Tier
  • 47. 47 Code for Class “StudentWinForm.cs” using System.Data; using Tuc.School.LogicTier; namespace Tuc.School.WinFormApp { class StudentWinForm { public DataSet GetStudent(string connectionString) { StudentData studentData = new StudentData(); return studentData.GetStudentDB(connectionString); } } } Reference to our Logic Tier Since we are using the DataSet Class Our Database Method in our Logic Tier
  • 50. 50 using System.Configuration; using Tuc.School.WinFormApp; namespace WinFormApp { public partial class Form1 : Form { private string connectionString = ConfigurationManager.ConnectionStrings["SCHOOLConnectionString"].ConnectionString; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { FillStudentGrid(); } private void FillStudentGrid() { DataSet ds = new DataSet(); StudentWinForm studentList = new StudentWinForm(); ds = studentList.GetStudent(connectionString); dataGridViewStudentInformation.DataSource = ds.Tables[0]; } } } WinForm Code Note! ConnectionString is stored in App.config
  • 52. 52 Create DB ConnectionString in App.config <?xml version="1.0" encoding="utf-8" ?> <configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> </startup> <connectionStrings> <add name="SCHOOLConnectionString" connectionString="Data Source=macwin8;Initial Catalog=SCHOOL;Persist Security Info=True;User ID=sa;Password=xxxxxx" providerName="System.Data.SqlClient" /> </connectionStrings> </configuration>
  • 54. 54 You are finished with the Exercise
  • 55. 55 Presentation Layer Desktop App: WinForms Part B: Using Web Services (we assume the The App should be used on Internet outside the Firewall) Label DataGridView
  • 56. 56 Step 1: Create Web Service Add Web Service: Create an ASP.NET Project: “SchoolWS” “SchoolWS.asmx”
  • 57. 57 Web Service Code Database ConnectionString is located in Web.config Web Service Method
  • 58. 58 Database ConnectionString is located in Web.config
  • 59. 59 Test Web Service It Works!! Click to Test the Web Service Method we created
  • 60. 60 Deploy/Publish Web Service to IIS CopyWeb Service Files (Project) to default IIS Directory: C:inetpubwwwroot
  • 61. 61
  • 62. 62 Test if WS working: http://localhost/SchoolWS
  • 63. 63 Step 2: Use Web Service in WinForm Create New WinForm Project: “WinFormAppWSClient”
  • 64. 64 Add Web Service Reference Our Web Service Methods
  • 67. 67 using System.Windows.Forms; namespace WinFormAppWSClient { public partial class FormWSClient : Form { public FormWSClient() { InitializeComponent(); } private void FormWSClient_Load(object sender, EventArgs e) { FillStudentGrid(); } private void FillStudentGrid() { DataSet ds = new DataSet(); SchoolWSReference.SchoolWSSoapClient schoolWs = new SchoolWSReference.SchoolWSSoapClient(); ds = schoolWs.GetStudent(); dataGridViewStudentInformation.DataSource = ds.Tables[0]; } } WinForm Code Call the Web Service method Fill GridView
  • 69. 69 You are finished with the Exercise
  • 70.
  • 71. Hans-Petter Halvorsen, M.Sc. University College of Southeast Norway www.usn.no E-mail: hans.p.halvorsen@hit.no Blog: http://home.hit.no/~hansha/