Introduction to Web Application Development with 'Net and Web Service - PowerPoint PPT Presentation

1 / 26
About This Presentation
Title:

Introduction to Web Application Development with 'Net and Web Service

Description:

function calcJS(){ var fName, lName; fName=document.formControl.T1.value; ... This web service return an object of MortgageResults type with more than one properties. ... – PowerPoint PPT presentation

Number of Views:175
Avg rating:3.0/5.0
Slides: 27
Provided by: Cob86
Learn more at: http://userwww.sfsu.edu
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Web Application Development with 'Net and Web Service


1
Introduction to Web Application Development with
.Net and Web Service
  • ISYS 350

2
Web Server
  • Web Server
  • Built-in Web Server
  • VS 08 uses the built-in web server for debugging.
  • Localhost website for testing
  • Default home page
  • Default.aspx, default.asp, default.htm

3
HTML Form vs .Net Web Form
  • HTML formCreated using HTML tags
  • Example Fullname.htm
  • ltform name "formControl" method"POST"gt
  • ltpgtfirst Nameltinput type"text" name"T1"
    size"20"gtlt/pgt ltpgtLast Nameltinput type"text"
    name"T2" size"20"gtlt/pgt ltpgtFull Name ltinput
    type"text" name"T3" size"20"gtlt/pgt ltpgtltinput
    type"button" value"Calculate" name"B1"
    onClick"calcJS()"gtlt/pgt
  • ltpgtltinput type"reset" value"Reset"
    name"B2"gtlt/pgt lt/formgt
  • .Net web form Created using ASP.Net controls

4
Client-Side vs Server-Side Script
  • Client-side Script is executing on client-side
  • JavaScript
  • Server-side Script is executing on server-side
    and produce HTML code as output.
  • ASP.Net
  • Java Servlets and JSP
  • PHP
  • Etc.

5
JavaScript Example
function calcJS() var fName, lName fNamedocumen
t.formControl.T1.value lNamedocument.formControl
.T2.value document.formControl.T3.valuefName
" " lName --gt lt/scriptgt lt/headgt ltbodygt ltform
name "formControl" method"POST"gt ltpgtfirst
Nameltinput type"text" name"T1" size"20"gtlt/pgt
ltpgtLast Nameltinput type"text" name"T2"
size"20"gtlt/pgt ltpgtFull Name ltinput
type"text" name"T3" size"20"gtlt/pgt
ltpgtltinput type"button" value"Calculate"
name"B1" onClick"calcJS()"gtlt/pgt ltpgtltinput
type"reset" value"Reset" name"B2"gtlt/pgt lt/formgt
6
Benefits of Server-Side Technology
  • Browser compatibility Every browser reads HTML.
  • Protection of source code.
  • Controls are server-side objects with properties,
    methods and events.

7
Web Project
  • File/New Website/ ASP.Net Website
  • Website folder
  • Web form
  • default.aspx
  • Design view and source view
  • Add a new page
  • Website/Add New Item/Web form
  • To set start up page
  • Point to the web page in the Solution Explorer
    and right click to choose Set As Start Page.

8
Create a web page to add two numbers
  • Add controls
  • Format/Set position/Absolute

9
Monthly Payment of a Loan
Protected Sub Button1_Click(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
Button1.Click Dim term, intRate, payment
As Double intRate ListBox1.SelectedValue
term RadioButtonList1.SelectedValue
payment Pmt(intRate / 12, term 12,
-CDbl(TextBox1.Text)) TextBox2.Text
payment End Sub
10
Data Grid
  • Creating bound DataGrid by dragging a table from
    the Server Explorer

11
Working with Multiple Pages
  • Redirect or transfer to another page
  • Server.Transfer(page name)
  • Response.Redirect(page name)

12
Working with ADO.Net(DataReader can be used as
a data source)
Dim strConn As String "ProviderMicrosoft.Jet.OL
EDB.4.0Data Source c\salesDB.mdb" Dim
objConn As New OleDbConnection(strConn)
Dim strSQL As String "select from customer"
Dim objComm As New OleDbCommand(strSQL,
objConn) objConn.Open() Dim
objDataReader As OleDbDataReader
objDataReader objComm.ExecuteReader()
GridView1.DataSource objDataReader
GridView1.DataBind()
13
Select a Rating from RadiobuttonList and Display
Customers with that Rating
Dim strConn As String "ProviderMicrosoft.Jet.OL
EDB.4.0Data Source c\salesDB.mdb" Dim
objConn As New OleDbConnection(strConn)
Dim strSQL As String "select from customer
where rating '" RadioButtonList1.SelectedValue
"'" Dim objComm As New
OleDbCommand(strSQL, objConn)
objConn.Open() Dim objDataReader As
OleDbDataReader objDataReader
objComm.ExecuteReader()
GridView1.DataSource objDataReader
GridView1.DataBind()
14
Postback
  • Postback is the process by which the browser
    posts information back to the server telling the
    server to handle the event, the server does so
    and sends the resulting HTML back to the browser.
  • Button control triggers the postback when
    clicked other controls need to set the
    AutoPostBack property to true.

15
Working with Database Class
  • Add a class
  • Website/Add New Item/Class
  • Classes with be placed in a App_Code folder
  • Adding an existing item
  • Example Adding the Customer class created
    earlier.

16
Working with an Assembly
  • Website/Add refernce/Browse for the assembly

17
Web Service
  • XML Web Service
  • Web services are classes that are stored on the
    web which can instantiate and use in both Windows
    and Web applications.

18
To Add a New Web Service
  • Website/Add New Item/Web Service
  • Web Service has an extension ASMX
  • The CodeBehind File is stored in the App_Code
    folder.
  • Web Services are defined as Web Method
  • ltWebMethod()gt programmed as a function with
    return value
  • ltWebMethod()gt Public Function GetCname(ByVal CID
    As String) As String

19
A Web Service Example
Public Class MyWebService Inherits
System.Web.Services.WebService ltWebMethod()gt
Public Function GetCname(ByVal CID As String) As
String Dim strConn As String
"ProviderMicrosoft.Jet.OLEDB.4.0Data Source
c\salesDB.mdb" Dim objConn As New
OleDbConnection(strConn) Dim strSQL As
String "select from customer where CID '"
CID "'" Dim objComm As New
OleDbCommand(strSQL, objConn)
objConn.Open() Dim objDataReader As
OleDbDataReader objDataReader
objComm.ExecuteReader() If
objDataReader.Read() Then Return
objDataReader("Cname") Else
Return ("Not exist") End If End
Function End Class
20
Web Service Description Language (WSDL)
  • A WSDL file is an XML document containing a
    complete description of the web service. It
    shows a web services name, methods, and
    parameter types.
  • Help page After entering web services URL, a
    help page is displayed. You can click the
    Service Description link to see the WSDL file.

21
Consuming Web Services from a Web Application
  • Add a web reference to the web service
  • Website/Add Web Reference
  • Within this soulution
  • Local computer
  • Internet
  • Imports the web service
  • Declare a web service class variable.
  • Dim UseWs As New DBWebService

22
Example
Imports localhost.Service1 Partial Class
Default3 Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
Button1.Click Dim WS As New
localhost.Service1 TextBox2.Text
WS.GetCname(TextBox1.Text) End Sub End Class
23
Web Service that Returns an Object(Customer
Object)
Public Function GetCustomer(ByVal CID As String)
As Customer Dim myCust As New Customer
myCust.getData(CID) If
myCust.RecExist Then Return myCust
Else myCust.cid CID
myCust.CName "NA" myCust.City
"NA" myCust.Rating "NA"
Return myCust End If End Function
24
Using the Service
Dim WS As New WebService2 Dim myCust As
New Customer myCust WS.GetCustomer(TextB
ox1.Text) TextBox2.Text myCust.CName
TextBox3.Text myCust.City
TextBox4.Text myCust.Rating
25
Reference a Web Service on Internet
  • Mortgage calculator
  • http//www.webservicex.net/mortgage.asmx
  • This web service return an object of
    MortgageResults type with more than one
    properties.

26
Example
Dim WS As New Mortgage.Mortgage Dim WSResult As
MortgageResults WSResult WS.GetMortgagePayment(
10, 0.05, 2000, 0, 0) TextBox2.Text
WSResult.TotalPayment.ToString
Write a Comment
User Comments (0)
About PowerShow.com