Download presentation
Presentation is loading. Please wait.
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 form:Created using HTML tags –Example: Fullname.htm first Name: Last Name: Full Name:.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; fName=document.formControl.T1.value; lName=document.formControl.T2.value; document.formControl.T3.value=fName + " " + lName; } --> first Name: Last Name: Full Name:
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 = "Provider=Microsoft.Jet.OLEDB.4.0;Data 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 = "Provider=Microsoft.Jet.OLEDB.4.0;Data 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: – programmed as a function with return value: – Public Function GetCname(ByVal CID As String) As String
19
A Web Service Example Public Class MyWebService Inherits System.Web.Services.WebService Public Function GetCname(ByVal CID As String) As String Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data 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 service’s name, methods, and parameter types. Help page: After entering web service’s 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(TextBox1.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
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.