Top Banner
3-tier Architecture Hans-Petter Halvorsen, M.Sc. Step by step Exercises
71

Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

Apr 06, 2018

Download

Documents

dangnhi
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

3-tierArchitecture

Hans-PetterHalvorsen,M.Sc.

StepbystepExercises

Page 2: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

Client-Server

SoftwareArchitecture

WebServices

APIs

3-TierArchitecture

API:ApplicationProgrammingInterface.Differentdevicesorsoftwaremodulescansharethesamecode.Codeonce,useitmanytimes

WebServices:Astandardwaytogetdataoveranetwork/InternetusingstandardWebprotocols(HTTP,etc.)

3-Tier:Awaytostructureyourcodeintologicalparts.Differentdevicesorsoftwaremodules cansharethesamecode.

GoodSoftware!

2-Tier

n-Tier

Page 3: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

3

Thedatabase-centricstyle.Typically,theclientscommunicatedirectlywiththedatabase.

Athree-tierstyle,inwhichclientsdonotconnectdirectlytothedatabase.

WebServices,etc.

Page 4: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

3-tier/layerArchitecture

4

PresentationTier

BusinessLogicTier

DataAccessTier

DataSource

PL

BL

DAL

Note!T

hedifferen

tlayerscanbeon

the

samecompu

ter(LogicL

ayers)oro

ndiffe

rent

Compu

tersinanetwork(Ph

ysicalLa

yers)

DataTier- DL

LogicTier

Page 5: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

Why3-Tier(N-TierArchitecture?)• Flexibleapplications• Reusablecode– Codeonce,usemanytimes

• Modularized– Youneedonlytochangepartofthecode– Youcandeployonlyonepart– YoucanTestonlyonepart– MultipleDevelopers

• Differentparts(Tiers)canbestoredondifferentcomputers

• DifferentPlatformsandLanguagescanbeused• etc.

5

Page 6: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

6http://en.wikipedia.org/wiki/Multitier_architecture

Page 7: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

3-tier/layerArchitecturePresentationTier• Thisisthetopmostleveloftheapplication.• Thepresentationtierdisplaysinformationrelatedtosuchservicesasbrowsing

merchandise,purchasingandshoppingcartcontents.• Itcommunicateswithothertiersbywhichitputsouttheresultstothe

browser/clienttierandallothertiersinthenetwork.• Insimpletermsitisalayerwhichuserscanaccessdirectlysuchasawebpage,

oranoperatingsystemsGUIApplicationtier(businesslogic,logictier,dataaccesstier,ormiddletier)• Thelogicaltierispulledoutfromthepresentationtierand,asitsownlayer.• Itcontrolsanapplication’sfunctionalitybyperformingdetailedprocessing.Datatier• Thistierconsistsofdatabaseservers.Hereinformationisstoredandretrieved.• Thistierkeepsdataneutralandindependentfromapplicationserversor

businesslogic.• Givingdataitsowntieralsoimprovesscalabilityandperformance.

7http://en.wikipedia.org/wiki/Multitier_architecture

Page 8: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

3-tierArchitecture

PresentationTier

BusinessLogicTier

DataAccessTier

Database

PresentationTier PresentationTier

StoredProcedures

DataTier

LogicTier

Page 9: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

3-tierArchitecture

PresentationTier

BusinessLogicTier

DataAccessTier

Database

PresentationTier PresentationTier

StoredProcedures

DifferentDevicescansharethesameBusinessandDataAccessCode

ThedifferentTierscanbephysicalorlogical DataTier

LogicTier

Page 10: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

WebServer

3-tier+WebService Architecture- Example

PresentationTier

Business/DataLogicTier

DataSource

WebServices

Server(s)

DataTier

StoredProcedures

Server-side Client-side

Page 11: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

WebServer

3-tier+WebServiceArchitecture- Example

PresentationTier

Business/DataLogicTier

DataSource

WebServices

Team

Fou

ndationServer

TFSCient

InstalledononeormoreWindowsServersinyourLANorintheCloud

DataTier

StoredProcedures

TeamFoundationServer

Page 12: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

3-tierArchitectureScenarios

PresentationLayer

BusinessLogic

DataAccessLogicDatabase

PresentationLayer PresentationLayer

StoredProcedures

Client

ClientClient

WebServer

WebService

PresentationLayer

Client

PresentationLayer

Internet

LocalNetwork(LAN)

Client

Firewall

PresentationLayer

ServerServer

Page 13: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

Exercises1. CreateDataTier (Database)2. CreateLogicTier(DatabaseCommunicationLogic)

CreatePresentationTier(UserInterfaceLogic):3. WebApp:UsingASP.NETWebForms(WSnormallynotneeded)

4. DesktopApp:UsingWinFormsA. WithoutWebServices(WeassumetheAppwillbeused

onlyintheLANandthatwehavedirectaccesstotheDatabase)

B. WithWebServices(WeassumetheAppshouldbeusedonInternetoutsidetheFirewallwithoutdirectDBaccess)

Page 14: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

Database

PresentationTier

e.g.,ADO,ADO.NET

LogicTier

WebService

BusinessTier

DataAccessTier

DataTier

StoredProceduresViewsTables

WebServer

DatabaseServer

PresentationTier

Client

ASP.NETWebForms

WebAppPresentationTier

Client

Client

ClientWinForms

3-tierArchitectureScenarios

Firewall

Clients

DesktopAppMobileApp

Internet

LocalNetwork

Note!ThedifferentTierscanbeonthesameComputer(LogicLayers)orondifferentComputers inanetwork(PhysicalLayers)

Android, iOS,Windows8/WindowsPhone,

etc.

PresentationTiers

DevicescansharethesameBusiness/LogicTierandAPIs

SeperatePresentationTierforeachDeviceApp

API

API

API

API

Page 15: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

15

VisualStudioProjectsSolution withallProjects(LogicTier,WebService,DesktopApp,WebApp,MobileApp)

Solution withProjectsusedbyWebApp(LogicTier,WebApp)

Page 16: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

DataTierWearegoingtocreatetheDatabase/DataLayer/Tier,including:1. Tables2. Views3. StoredProcedures4. Triggers5. Scriptforsome“Dummy”Data

DownloadZipFileswithTables,Views,StoredProceduresandTriggerseinordertocreatetheDataTierinSQLServer(TheZIPFileislocatedonthesameplaceasthisFile)

16

Note!Installtheminthisorder

Page 17: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

DataTier

17

Tables

Views

StoredProcedures

SQLServer

Triggers

DataTier

Page 18: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

18

DatabaseTables

Page 19: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

19

ExecutethedifferentScriptsinsideSQLServerManagementStudio

Page 20: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

20YouarefinishedwiththeExercise

Page 21: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

CreateLogicTier

21

Database

PresentationTier

LogicTier

ASP.NETWebForms

DataTier

PresentationTier PresentationTier

WinForms WindowsStoreApp

Purpose:• AlltheAppsshould/could

sharethesameLogicTier• TomakeyourAppseasier

tomaintainandextend• etc.

Page 22: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

22

CreateanEmpty(Blank)Solution inVisualStudio

Page 23: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

23

AddProject forLogicTier(DataAccess)

Selecta“ClassLibrary”Project

“LogicTier”

Page 24: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

24

AddaNewClass totheProject(“StudentData.cs”)

“StudentData.cs”

Page 25: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

25

CreatetheCode,e.g.,likethis(“StudentData.cs”):

CreateyourownNamespace

Improvements:UseTry...Catch...

AViewthatcollectsdatafromseveraltables

Page 26: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

26

YoushouldtesttheSQLQueryintheSQLServerManagementStudiofirst

Page 27: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

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;

}}

}

Page 28: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

28

CreateapropernamefortheAssembly (.dllFile)

ThiswillbetheAssembly foryourLogicTier,thatcanbeimportedandusedinotherprojects.Createonce– useitmanytimes!!

ThenBuildyourProject(hopefullywithnoerrors)

Right-clickon theProjectintheSolution ExplorerandselectProperties

Page 29: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

29YouarefinishedwiththeExercise

Page 30: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

30

PresentationLayerWebApp:ASP.NETWebForms

WewillcreateaWebFormlikethiswherethedatacomesfromourLogicTier

Page 31: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

31

AddProjectforPresentationTier(ASP.NETWebForm)

Page 32: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

32

AddaNewClass(“Student.cs”)

Page 33: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

33

AddCode(“Student.cs”)

AddaReferencetotheAssembly intheLogicTier

Note!ThisisourLogicTier

Page 34: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

34

Codefor“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);

}}

}

GetDatfromourLogicTier

Sinceweareusing theDataSetClass

OurLogicTier

Page 35: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

35

AddaNewWebForm (StudentInformation.aspx)

Page 36: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

36

CreateWebFormPage(“StudentInformation.aspx”)

GridView (Drag&DropfromToolboxorcreatecodein.aspxfile)

Page 37: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

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/ASPXCode(“StudentInformation.aspx”)

Page 38: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

38

CodebehindfortheWebForm(“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

Page 39: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

39

Storethe“ConnectionString”foryourDatabasein“Web.Config”

<?xml version="1.0" encoding="utf-8"?><!--For more information on how to configure your ASP.NET application, please visithttp://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>

ThenyoucaneaslyswitchDatabssewithoutchangingtheCode!!

Page 40: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

40

TestyourWebApp

Note!Wehaveuseda“View”inordertogetdatafromseveraltables

Page 41: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

41

AdditionalExercise:

UpdateGridViewwithNewDatafromDatabase

GotoNewWebForminordertoAddanotherStudent

Page 42: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

42YouarefinishedwiththeExercise

Page 43: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

43

PresentationLayerDesktopApp:WinForms

PartA:WithoutWebServices(weassumetheAppwillbeusedonlyinthelocalLAN(orlocalonthesamecomputerwherethedatabaseislocated)andthatwehavedirectaccesstotheDatabase)

Label

DataGridView

Page 44: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

44

AddaWinFormProject

Page 45: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

45

AddaNewClass (“StudentWinForm.cs”)

Page 46: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

46

AddCode inClass

AddaReferencetotheAssemblyintheLogicTier

Page 47: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

47

CodeforClass“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);}

}}

ReferencetoourLogicTier

Sinceweareusing theDataSetClass

OurDatabaseMethod inourLogicTier

Page 48: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

48

CreateForm

Label

DataGridView

Page 49: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

49

CreateFormCode

Page 50: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

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];

}}

}

WinFormCodeNote!

ConnectionString isstoredinApp.config

Page 51: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

51

Note!AddSystem.ConfigurationReference

Page 52: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

52

CreateDBConnectionStringinApp.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>

Page 53: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

53

Testit

Itworks!!!

Page 54: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

54YouarefinishedwiththeExercise

Page 55: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

55

PresentationLayerDesktopApp:WinForms

PartB:UsingWebServices(weassumetheTheAppshould beusedonInternetoutsidetheFirewall)

Label

DataGridView

Page 56: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

56

Step1:CreateWebService

AddWebService:

CreateanASP.NETProject:“SchoolWS”

“SchoolWS.asmx”

Page 57: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

57

WebServiceCode

DatabaseConnectionStringislocatedinWeb.config

WebServiceMethod

Page 58: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

58

DatabaseConnectionStringislocatedinWeb.config

Page 59: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

59

TestWebService

ItWorks!!

ClicktoTesttheWebServiceMethodwecreated

Page 60: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

60

Deploy/PublishWebServicetoIIS

CopyWebServiceFiles(Project)todefaultIISDirectory:C:\inetpub\wwwroot

Page 61: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

61

Page 62: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

62

TestifWSworking:

http://localhost/SchoolWS

Page 63: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

63

Step2:UseWebServiceinWinFormCreateNewWinFormProject:

“WinFormAppWSClient”

Page 64: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

64

AddWebServiceReference

OurWebServiceMethods

Page 65: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

CreateGUI

Label

DataGridView

Page 66: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

66

CreateCode

Page 67: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

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 = newSchoolWSReference.SchoolWSSoapClient();

ds = schoolWs.GetStudent();

dataGridViewStudentInformation.DataSource = ds.Tables[0];

}}

WinFormCode

CalltheWebServicemethod

FillGridView

Page 68: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

68

Testit:

Itworks!!!

Page 69: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

69YouarefinishedwiththeExercise

Page 70: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not
Page 71: Step by step Exercises - Telemark University Collegehome.hit.no/~hansha/documents/software/software... · Exercises 1. Create Data Tier ... Using ASP.NET Web Forms (WS normally not

Hans-PetterHalvorsen,M.Sc.

UniversityCollegeofSoutheastNorwaywww.usn.no

E-mail:[email protected]:http://home.hit.no/~hansha/