Download presentation
Presentation is loading. Please wait.
1
CS 3870 Web Service
2
Web Service What is Web Service?
Providing functionality online to other applications, Web or 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
XML and SOAP 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
.NET Framework 4.6 Right click the main Web site Select Property Pages
Build .NET Framework 4.6
7
Creating Web Service Add New Items Web Service (ASMX)
Specify Name: UWPCSSEWebService2018 File UWPCSSEWebService2018.asmx Inside the main Web site File UWPCSSEWebService2018.cs Inside App_Code
8
WebService Page Directive
File UWPCSSEWebService2018.asmx WebService Language=“C#" CodeBehind="~/App_Code/UWPCSSEWebService2018.cs" Class=“UWPCSSEWebService2018" %>
9
Web Service Class (C# File)
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; /// <summary> /// Summary description for UWPCSSEWebWebService2018 /// </summary> [WebService(Namespace = " [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the // following line. // [System.Web.Script.Services.ScriptService] public class UWPCSSEWebWebService2018 : System.Web.Services.WebService { public UWPCSSEWebWebService2018() //Uncomment the following line if using designed components //InitializeComponent(); } [WebMethod] public string HelloWorld() return "Hello World";
10
Web Service Class Web Service Namespace Default : http://tempuri.org/
Change to:
11
Web Service Class public class UWPCSSEWebWebService2018 : System.Web.Services.WebService { //Initialize Products in table. public UWPCSSEWebWebService2018() SQLDataClass.getAllProducts(); } [WebMethod] public string HelloWorld() return "Hello World";
12
Four More Methods [WebMethod]
public System.Data.DataTable WS_GetAllProducts() public void WS_UpdateProduct(string ID, string newName, double newPrice, string newDescription) public void WS_InsertProduct(string ID, string name, double price, string description) public void WS_DeleteProduct(string ID)
13
Looking at Web Service ???
14
SOAP All Web Methods SOAP Envelop SOAP Body
15
Completing Web Methods
public class UWPCSSEWebWebService2018 : System.Web.Services.WebService { [WebMethod] public System.Data.DataTable WS_GetAllProducts() public void WS_UpdateProduct(string ID, string newName, double newPrice, string newDescription) public void WS_InsertProduct(string ID, string name, double price, string description) public void WS_DeleteProduct(string ID) } Call methods of SQLDataClass Make sure method setupAdapter is called
16
Consuming Web Service Adding Web Reference
Invoking Web Service from client application
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” Go Namespace WebServiceCS3870 OK
18
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
19
The Web Config file will be updated automatically with the following.
<system.serviceModel> <bindings> <basicHttpBinding> <binding name="UWPCSSEWebService2018Soap"> <security mode="Transport" /> </binding> <binding name="UWPCSSEWebService2018Soap1" /> </basicHttpBinding> </bindings> <client> <endpoint address=" binding="basicHttpBinding" bindingConfiguration="UWPCSSEWebService2018Soap" contract="CS3870.UWPCSSEWebService2018Soap" name="UWPCSSEWebService2018Soap" /> </client> </system.serviceModel>
20
Selecting Web Services on Form Default.aspx
//Sets the webservice to the selected in the dropdown list. protected void DropDownList1_SelectedIndexChanged(. . .) { var ws = DropDownList1.Text; object obj; if (ws == "CS3870") obj = new WebServiceCS3870.UWPCSSEWebService2018SoapClient(); else if (ws == "YangQ") WebServiceYangQ.UWPCSSEWebService2018SoapClient(); else WebServiceWebSite.UWPCSSEWebService2018SoapClient(); . . . }
21
protected void DropDownList1_SelectedIndexChanged(. . .)
{ var ws = DropDownList1.Text; object obj; if (ws == "CS3870") . . . Session["Prog9_WS"] = obj; Session["Prog9_WSName"] = obj.ToString(); Session["Prog9_PageIndex"] = 0; Session["Prog9_RecordIndex"] = 0; Session["Prog9_UnitPrice"] = 0; Session["Prog9_Index"] = 0; Session["Prog9_ID"] = ""; SetLabelText(); }
22
Prog9MasterPage <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <h3 class="centerAlign">Prog 9: <asp:Label ID="Label1" runat="server" Text=""></asp:Label> </h3> <asp:TreeView ID="TreeView1" runat="server" > </asp:TreeView> <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" /> <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"> </asp:ContentPlaceHolder> </asp:Content>
23
Display the selected Web Service name
Session["Prog9_WS"] = obj; Session["Prog9_WSName"] = obj.ToString(); string ws = Session["Prog9_WSName"].ToString(); Control c = Master.Master.FindControl("form1"); c = c.FindControl("ContentPlaceHolder1"); c = c.FindControl("Label1"); ((Label)c).Text = ws;
24
Invoking Web Methods on Form AllProducts.aspx
protected void Page_Load(object sender, EventArgs e) { var obj = Session["Prog9_WS"]; if (obj == null) Response.Redirect("~/Prog9/Default.aspx"); System.Data.DataTable myTable; if (obj.ToString().Contains("YangQ")) myTable = ((WebServiceYangQ.UWPCSSEWebService2018SoapClient)obj).WS_GetAllProducts(); else if (obj.ToString().Contains(“UserName")) myTable = ((WebServiceUserName.UWPCSSEWebService2018SoapClient)obj).WS_GetAllProducts(); else ((WebServiceCS3870.UWPCSSEWebService2018SoapClient)obj).WS_GetAllProducts(); GridView1.DataSource = myTable; if (!IsPostBack) GridView1.PageIndex = (int)Session["Prog9_PageIndex"]; GridView1.DataBind(); }
25
Must Set to Tls12 protected void Page_Load(object sender, EventArgs e)
{ . . . System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12; ((WebServiceCS3870.UWPCSSEWebService2018SoapClient)obj). WS_GetAllProducts(); }
26
try { var obj = Session["Prog9_WS"]; if (obj. ToString()
try { var obj = Session["Prog9_WS"]; if (obj.ToString().Contains("YangQ")) ((WebServiceYangQ.UWPCSSEWebService2017SoapClient)obj). WS_InsertProduct (ProductID, ProductName, double.Parse(UnitPrice), Description); else if (obj.ToString().Contains("DubielT")) ((WebServiceDubielT.UWPCSSEWebService2017SoapClient)obj). else ((WebServiceCS3870.UWPCSSEWebService2017SoapClient)obj). txtMsg.Text = "Record Inserted"; } catch(Exception ex) txtMsg.Text = ex.Message;
27
Accessing Database Using Web Service
No Credit if Accessing Database without Web Service
28
Session Variables Need to be Created and Updated
Name starting using “Prog9_”
29
Delete and Create Service Reference?
Not Working Delete and Create Service Reference?
30
AJAX All Web Forms except Default.aspx Should have multiple UpdatePanels on one Web form.
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.