Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 CS 3870/CS 5870: Note 20 Web Service. 2 What is Web Service? Providing functionality online to other applications, Web and Windows applications. The.

Similar presentations


Presentation on theme: "1 CS 3870/CS 5870: Note 20 Web Service. 2 What is Web Service? Providing functionality online to other applications, Web and Windows applications. The."— Presentation transcript:

1 1 CS 3870/CS 5870: Note 20 Web Service

2 2 What is Web Service? Providing functionality online to other applications, Web and Windows applications. The original Goal of MS ASP.NET To enable developers to build and consume Web services with easy

3 Communication Between Disparate Systems Systems within an organization –Unix –Windows –Mac –Others Various systems need to talk with one another –Not an easy job 3

4 XML XML: eXtensible Makeup Language –Simpler version of SGML (Standard Generalized Makeup Language) –Best choice for disparate systems for now SOAP Simple Object Access Protocol 4

5 Previous Attempts DCOM Distributed Component Object Model RMI Remote Method Invocation CORBA:... IIOP:... Driven by a single vendor or Very vendor specific 5

6 6 Creating Web Service Add New Items Web Service –Specify Name File WebService.asmx File WebService.vb –under App_Code

7 7 WebService Page Directive File WebService.asmx <%@ WebService Language="VB" CodeBehind="~/App_Code/WebService.vb" Class="WebService" %>

8 8 Web Service Class (VB File) Imports System.Web Imports System.Web.Services Imports System.Web.Services.Protocols ‘ To allow this Web Service to be called from script, ‘ using ASP.NET AJAX, uncomment the following line. ‘ _ _ Public Class WebService Inherits System.Web.Services.WebService... End Class

9 9 Web Service Class Web Service Namespace –Default : http://tempuri.org/ http://tempuri.org/ –Change to: https://xray.ion.uwplatt.edu/YourUserName/ https://xray.ion.uwplatt.edu/YourUserName/ ScriptService: AJAX Service.Protocols –SOAP can be used in VB.NET

10 10 Web Service Class Public Class WebService Inherits System.Web.Services.WebService _ Public Function HelloWorld() As String Return "Hello" End Function _ Public Function WS_GetAllProducts() As Data.DataTable... ‘ Return a datatable End Function End Class

11 11 Looking at Web Service Go to the Web Service URL: https://xray.ion.uwplatt.edu/yangq/UWPCSSEWebService.asmx https://xray.ion.uwplatt.edu/CS3870/UWPCSSEWebService.asmx

12 SOAP SOAP Envelop SOAP Body 12

13 13 Web Service Class _ Public Class WebService Inherits System.Web.Services.WebService ‘ Create new web methods _ Public Sub WS_UpdateProduct(...)... End Sub End Class

14 14 Web Service Class _ Public Class WebService Inherits System.Web.Services.WebService ‘ Insert a new record into the table Public Sub WS_InsertProduct(...)... End Sub End Class

15 15 Web Service Class _ Public Class WebService Inherits System.Web.Services.WebService ‘ Insert a new record into the table _ Public Sub WS_InsertProduct(...)... End Sub End Class Must have _

16 16 Consuming Web Service Adding Web Reference Invoking Web Service from client application

17 17 Adding Web Reference Right click the root of the Web Site Add Service Reference Enter the URL of the wanted web service followed by “?WSDL” https://xray.ion.uwplatt.edu/CS3870/UWPCSSEWebservi ce.asmx?WSDL Namespace (the grader assumes this!) UserName (Web Site Name, e.g. CS3870)

18 18 Adding Web Reference Add Service Reference to the Web Service created on your Web site Namespace YourUserName (Web Site Name, e.g. YangQ)

19 19 Web Config The Web Config file will be updated automatically with the following. <endpoint address="https://xray.ion.uwplatt.edu/cs3870/UWPCSSEWebservice.asmx" binding="basicHttpBinding" bindingConfiguration="UWPCSSEWebServiceSoap" contract="CS3870.UWPCSSEWebServiceSoap" name="UWPCSSEWebServiceSoap" />

20 Page Product.aspx Protected Sub Page_Load(... ) Handles Me.Load Dim obj As CS387.UWPCSSEWebServiceSoapClient Dim myTable As Data.DataTable = obj.WS_GetAllProducts() GridView1.DataSource = myTable GridView1.DataBind() End Sub 20

21 21 Selecting Web Services Dim ws As String Dim obj As Object If ws = "CS3870" Then ‘obj = New CS3870.UWPCSSEWebService obj = New CS3870.UWPCSSEWebServiceSoapClient ElseIf ws = "yangq" Then obj = New yangq.UWPCSSEWebServiceSoapClient End If Session("WS") = obj

22 22 Invoking Web Methods Dim obj As Object Dim myTable As Data.DataTable Protected Sub Page_Load(...) Handles Me.Load obj = Session("WS") myTable = obj.WS_GetAllProducts() Session("WS_Table") = myTable GridView1.DataSource = myTable GridView1.DataBind() End Sub

23 Must Select WS first On each of other pages Protected Sub Page_Load(...) Handles Me.Load If Session("WS") Is Nothing Then 'Server.Transfer("~/Prog9/Default.aspx") Response.Redirect("~/Prog9/Default.aspx") Exit Sub End If... End Sub 23

24 Accessing Table From Web Service No Credit if Accessing Database without Web Service 24

25 Session Variables Need to be Created and Updated 25

26 Not Working Delete and Create Service Reference? 26

27 AJAX All Web Pages 27

28 AJAX: Test 3 Page Default (displaying courses) –Two UpdatePanels –Triggers –UpdateMode: Conditional Page Credit –One UpdatePanel –Put a Panel or another container inside UpdatePanel –Add user controls inside the Panel –No Triggers 28


Download ppt "1 CS 3870/CS 5870: Note 20 Web Service. 2 What is Web Service? Providing functionality online to other applications, Web and Windows applications. The."

Similar presentations


Ads by Google