Download presentation
Presentation is loading. Please wait.
1
CS 3870/CS 5870 Web Service
2
Web Service 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
4
SOAP and XML XML: eXtensible Makeup Language SOAP
Simpler version of SGML (Standard Generalized Makeup Language) Best choice for disparate systems for now SOAP Simple Object Access Protocol
5
Previous Attempts DCOM Distributed Component Object Model RMI
Remote Method Invocation CORBA: . . . IIOP: . . . Driven by a single vendor or Very vendor specific
6
Creating Web Service Add New Items Web Service
Specify Name: UWPCSSEWebService2016 File UWPCSSEWebService2016.asmx File UWPCSSEWebService2016.vb under App_Code
7
WebService Page Directive
File UWPCSSEWebService2016.asmx WebService Language="VB" CodeBehind="~/App_Code/ UWPCSSEWebService2016.vb" Class="WebService" %>
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. ‘ <System.Web.Script.Services.ScriptService()> _ <WebService(Namespace:=" _ <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _ <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _ Public Class WebService Inherits System.Web.Services.WebService . . . End Class
9
Web Service Class ScriptService: AJAX Service.Protocols
Web Service Namespace Default : Change to: ScriptService: AJAX Service.Protocols SOAP can be used in VB.NET
10
Web Service Class Public Class UWPCSSEWebService2016
Inherits System.Web.Services.WebService <WebMethod()> _ Public Function HelloWorld() As String Return "Hello, World" End Function Public Function WS_GetAllProducts() As Data.DataTable . . . ‘ Return a datatable End Class
11
Web Service Class Public Class UWPCSSEWebService2016
Inherits System.Web.Services.WebService <WebMethod()> _ Public Function WS_GetAllProducts() As Data.DataTable Public Sub WS_UpdateProduct(. . . Public Sub WS_InsertProduct(. . . Public Sub WS_DeleteProduct(. . . End Class Must have <WebMethod()> Can call methods of SQLDataClass Make sure method setupAdapter is called Prog3
12
Looking at Web Service
13
SOAP SOAP Envelop SOAP Body
14
Consuming Web Service Adding Web Reference
Invoking Web Service from client application
15
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” Namespace Your choice for your program
16
Required Three Web References
Service Reference to the Web Service created on Web site CS3870 Service Reference to the Web Service created on Web site YangQ Service Reference to the Web Service created on your Web site
17
The Web Config file will be updated automatically with the following.
<system.serviceModel> <bindings> <basicHttpBinding> <binding name="UWPCSSEWebService2016Soap"> <security mode="Transport" /> </binding> <binding name="UWPCSSEWebService2016Soap1" /> </basicHttpBinding> </bindings> <client> <endpoint address=" binding="basicHttpBinding" bindingConfiguration="UWPCSSEWebService2016Soap" contract="CS3870.UWPCSSEWebServiceSoap" name="UWPCSSEWebService2016Soap" /> </client> </system.serviceModel>
18
Selecting Web Services on Form Default.aspx
Dim ws As String = DropDownList1.Text Dim obj As Object If ws = "CS3870" Then obj = New CS3870.UWPCSSEWebService2016SoapClient ElseIf ws = “YangQ" Then obj = New MyWebService.UWPCSSEWebService2016SoapClient Else obj = New YourWebService.UWPCSSEWebService2016SoapClient End If Session(“Prog9_WS") = obj
19
Display the selected Web Service name
If ws = "CS3870" Then . . . obj = New YourWebService.UWPCSSEWebService2016SoapClient End If Session(“Prog9_WS") = obj ws = obj.ToString Dim c As Control = Master.Master.FindControl("form1") c = c.FindControl("ContentPlaceHolder1") c = c.FindControl("Label1") CType(c, Label).Text = ws Session("Prog9_WSName") = ws
20
Prog9MasterPage <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <h3>Prog 9: <asp:Label ID="Label1" runat="server" Text=""></asp:Label> </h3> </asp:Content> ws = obj.ToString Dim c As Control = Master.Master.FindControl("form1") c = c.FindControl("ContentPlaceHolder1") c = c.FindControl("Label1") CType(c, Label).Text = ws Session("Prog9_WSName") = ws
21
Invoking Web Methods on Form AllProducts.aspx
Dim obj As Object Dim myTable As Data.DataTable Protected Sub Page_Load(. . .) Handles Me.Load obj = Session(“Prog9_WS") myTable = obj.WS_GetAllProducts() GridView1.DataSource = myTable GridView1.DataBind() End Sub
22
Invoking Web Methods on Form Product.aspx
Protected Sub Page_Load(. . . ) Handles Me.Load If Session("Prog9_WS") Is Nothing Then Response.Redirect("~/Prog9/Default.aspx") End If obj = Session(“Prog9_WS") myTable = obj.WS_GetAllProducts() GridView1.DataSource = myTable GridView1.DataBind() End Sub
23
Try and Catch Protected Sub Button1_Click(. . .) Handles btnUpdate.Click Try obj.WS_UpdateProduct(oldID, txtName.Text, txtPrice.Text, txtDescription.Text) Catch ex As Exception txtMsh.Text = ex.Message End Try End Sub
24
Shopping and Updating Look into Your Prog3
25
Accessing Database Using Web Service
No Credit if Accessing Database without Web Service
26
Session Variables Need to be Created and Updated
Name starting using “Prog9_”
27
Delete and Create Service Reference?
Not Working Delete and Create Service Reference?
28
AJAX All Web Forms except Default.aspx Could have multiple UpdatePanels on one Web form.
29
Bonus Points
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.