· web view04/13/2016 16:57:00 last modified by chidakash

12
Practical 13 AIM: Create a web service to add two numbers. Design: WebService.asmx: <%@ WebService Language="C#" CodeBehind="~/App_Code/WebService.cs" Class="WebService" %> WebService.asmx.cs: using System; using System.Web; using System.Web.Services; /// <summary> /// Summary description for WebService /// </summary> [WebService(Namespace = "http://tempuri.org/")] [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 WebService : System.Web.Services.WebService {

Upload: lyphuc

Post on 15-Mar-2018

215 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: · Web view04/13/2016 16:57:00 Last modified by Chidakash

Practical 13AIM: Create a web service to add two numbers.

Design:

WebService.asmx:<%@ WebService Language="C#" CodeBehind="~/App_Code/WebService.cs" Class="WebService" %>

WebService.asmx.cs:using System;using System.Web;using System.Web.Services;

/// <summary>/// Summary description for WebService/// </summary>[WebService(Namespace = "http://tempuri.org/")][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 WebService : System.Web.Services.WebService {

public WebService () {

//Uncomment the following line if using designed components //InitializeComponent();

Page 2: · Web view04/13/2016 16:57:00 Last modified by Chidakash

}

[WebMethod] public string HelloWorld() { return "Hello World"; }

[WebMethod] public int add(int a, int b) { return a + b; }

[WebMethod] public int sub(int a, int b) { return a - b; }

[WebMethod] public int mul(int a, int b) { return a * b; }

[WebMethod] public int div(int a, int b) { return a / b; }

}

Page 3: · Web view04/13/2016 16:57:00 Last modified by Chidakash

Output:

Page 4: · Web view04/13/2016 16:57:00 Last modified by Chidakash
Page 5: · Web view04/13/2016 16:57:00 Last modified by Chidakash

Web Service Description Language:

Page 6: · Web view04/13/2016 16:57:00 Last modified by Chidakash

Design of Webform:

Page 7: · Web view04/13/2016 16:57:00 Last modified by Chidakash

Default.aspx:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title></title></head><body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> <br /> <asp:Button ID="btnAdd" runat="server" Text="Add" onclick="btnAdd_Click" /> <asp:Button ID="btnSub" runat="server" Text="Sub" onclick="btnSub_Click" /> <asp:Button ID="btnMul" runat="server" Text="Mul" onclick="btnMul_Click" /> <asp:Button ID="btnDiv" runat="server" Text="Div" onclick="btnDiv_Click" /> <br /> <br /> Answer:<asp:Label ID="Label1" runat="server"></asp:Label> </div> </form></body></html>

Page 8: · Web view04/13/2016 16:57:00 Last modified by Chidakash

Default.aspx.cs:using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page{ WebService ws = new WebService(); protected void Page_Load(object sender, EventArgs e) {

} protected void btnAdd_Click(object sender, EventArgs e) { Label1.Text = Convert.ToString(ws.add(Convert.ToInt32(TextBox1.Text), Convert.ToInt32(TextBox2.Text))); } protected void btnSub_Click(object sender, EventArgs e) { Label1.Text = Convert.ToString(ws.sub(Convert.ToInt32(TextBox1.Text), Convert.ToInt32(TextBox2.Text))); } protected void btnMul_Click(object sender, EventArgs e) { Label1.Text = Convert.ToString(ws.mul(Convert.ToInt32(TextBox1.Text), Convert.ToInt32(TextBox2.Text))); } protected void btnDiv_Click(object sender, EventArgs e) { Label1.Text = Convert.ToString(ws.div(Convert.ToInt32(TextBox1.Text), Convert.ToInt32(TextBox2.Text))); }}

Page 9: · Web view04/13/2016 16:57:00 Last modified by Chidakash

Output:

Addition

Subtraction

Page 10: · Web view04/13/2016 16:57:00 Last modified by Chidakash

Multiplication

Division