Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Web Service ISYS 512. Web Service XML Web Service Web services are classes that are stored on the web which can instantiate and use in.

Similar presentations


Presentation on theme: "Introduction to Web Service ISYS 512. Web Service XML Web Service Web services are classes that are stored on the web which can instantiate and use in."— Presentation transcript:

1 Introduction to Web Service ISYS 512

2 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. Example: http://www.webservicex.net/stockquote.asmx

3 To Add a New Web Service: Project/Add New Item/Web Service –Web Service has an extension: ASMX Web Services are defined as Web Method: – _

4 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.ACE.OLEDB.12.0;Data Source=C:\SalesDB2007.accdb“ 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

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

6 Returning a Complex Data Type Examples: –ArrayList –DataSet –User-defined object Customer Class

7 Returning an ArrayList Public Function GetCnameRating(ByVal CID As String) As ArrayList Dim strConn As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\SalesDB2007.accdb“ 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() Dim temp As New ArrayList If objDataReader.Read() Then temp.Add(objDataReader("Cname")) temp.Add(objDataReader("Rating")) Else temp.Add("Not exist") End If Return temp End Function

8 Returning a DataSet Public Function GetCustomerDataSet() As DataSet Dim strConn As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\SalesDB2007.accdb“ Dim objConn As New OleDbConnection(strConn) Dim strSQLSelect As String = "select * from customer;" Dim objDataSet As New DataSet() Dim objAdapter As New OleDbDataAdapter(strSQLSelect, objConn) objAdapter.Fill(objDataSet, "Customer") Return objDataSet End Function

9 Consuming a Local Web Services from a Web Application Add a web reference to the web service: –Project/Add Service Reference Click Discover to show local web services Declare a web service class variable. –Dim MyWebService As New ServiceReference2.WebService2SoapClient

10

11 Example Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim MyWebService As New ServiceReference2.WebService2SoapClient TextBox2.Text = MyWebService.GetCname("c01") End Sub

12 Consuming a Services Found On Internet Find and display the web service Add a web reference to the web service: –Project/Add Service Reference Paste the web service’s URL to the address box Declare a web service class variable. –Dim MyService As New net.webservicex.www.StockQuote

13 Example Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim MyService As New net.webservicex.www.StockQuote TextBox2.Text = MyService.GetQuote("csco") End Sub

14 Using a DataSet Returning by Web Service (Web Project) Imports DBWS Imports System.Data Partial Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim UseWs As New DBWebService Dim MyDs As New dataset MyDs = UseWs.GetCustomerDataSet() GridView1.DataSource = MyDs.Tables("customer") GridView1.DataBind() End Sub End Class

15 Reference a Web Service on Internet that Return an object with many properties Mortgage calculator http://www.webservicex.net/mortgage.asmx

16 Example Dim ws As New ServiceReference3.MortgageSoapClient TextBox2.Text = ws.GetMortgagePayment(10, 0.05, 2000, 0, 0).TotalPayment

17 Using an Assembly with a Web Project Project/Add Reference/Browse

18 Loosely Coupled Software Refers to software routines (modules, programs) that can be called by an application and executed as needed. For example, Web services are loosely coupled software modules that are invoked on demand when required. An approach to designing interfaces across modules to reduce the interdependencies across modules or components – in particular, reducing the risk that changes within one module will create unanticipated changes within other modules.

19 Benefits of Loosely Coupled Software This approach specifically seeks to increase flexibility in adding modules, replacing modules and changing operations within individual modules. It assumes a modular approach to design. It values flexibility. It seeks to increase flexibility by focusing on design of interfaces.

20 Service Oriented Architecture SOA expresses a perspective of software architecture that defines the use of loosely coupled software services to support the requirements of the business processes and software users. In an SOA environment, resources on a network are made available as independent services that can be accessed without knowledge of their underlying platform implementation. A service-oriented architecture is not tied to a specific technology. It may be implemented using a wide range of technologies.


Download ppt "Introduction to Web Service ISYS 512. Web Service XML Web Service Web services are classes that are stored on the web which can instantiate and use in."

Similar presentations


Ads by Google