Title: Introduction to Web Application Development with 'Net and Web Service
1Introduction to Web Application Development with
.Net and Web Service
2Web 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
3HTML 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
4Client-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.
5JavaScript 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
6Benefits of Server-Side Technology
- Browser compatibility Every browser reads HTML.
- Protection of source code.
- Controls are server-side objects with properties,
methods and events.
7Web 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.
8Create a web page to add two numbers
- Add controls
- Format/Set position/Absolute
9Monthly 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
10Data Grid
- Creating bound DataGrid by dragging a table from
the Server Explorer
11Working with Multiple Pages
- Redirect or transfer to another page
- Server.Transfer(page name)
- Response.Redirect(page name)
12Working 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()
13Select 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()
14Postback
- 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.
15Working 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.
16Working with an Assembly
- Website/Add refernce/Browse for the assembly
17Web 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.
18To 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
19A 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
20Web 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.
21Consuming 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
22Example
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
23Web 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
24Using 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
25Reference 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. -
26Example
Dim WS As New Mortgage.Mortgage Dim WSResult As
MortgageResults WSResult WS.GetMortgagePayment(
10, 0.05, 2000, 0, 0) TextBox2.Text
WSResult.TotalPayment.ToString