Buy Questpond's video subscriptions on
huge discount
.
Online: 2043
Home
Articles
Interviews
Forums
For Beginners
Popular Questions
ITIL Career Advice
PMP Career Advice
Career Advices
Codes
Videos
ASP.NET
ASP.NET MVC
Android Intel XDK
Sql Server
AngularJS
Bootstrap
Backbone.JS
MongoDB
LESS (CSS)
jQuery
WPF
WWF
SSIS
LightSwitch
Tutorials
News
ASP.NET MVC
|
Be Interview Ready
|
Top Performers
|
DNF MVP
|
Top Posts
|
Winners
|
Subscribe
|
Catalogs
Welcome Guest !
Register
Login
Home
>
Codes
>
Loading ...
Simple Calculator using Asp.net Web service
Posted by
Geetha.Katneni
under
ASP.NET
category on
4/7/2012
|
Points: 40
| Views : 13306
Post Code
|
Search Codes
|
Code Home
Creating Simple Calculator using Web services[
/B]
1)Go To Visual Studio 2010 -> New Project -> Select Asp.NET Web Service Application -> OK
2) In Service.asmx.cs -put the code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace Session_WebService1
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 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 Service1 : System.Web.Services.WebService
{
// Simple Calculator //
[WebMethod]
public double Add(double x, double y)
{
return x + y;
}
[WebMethod]
public double Sub(double x, double y)
{
return x - y;
}
[WebMethod]
public double Mult(double x, double y)
{
return x * y;
}
[WebMethod]
public double Div(double x, double y)
{
return x / y;
}
[WebMethod]
public double Pow(double x, double y)
{
double PowVal = x;
for (int i = 0; i < y - 1; i++)
{
PowVal *= x;
}
return owVal;
}
}
}
3) a) Add NewCalci.aspx page
Design the form with- 3 TextBoxes with Names TxtValue1,TxtValue2,TxtResult to enter value1,value2 and result.
5 Buttons with Names BtnAdd , BtnSub , BtnMul ,BtnDiv , BtnPow , BtnClear.
4)Write the Following code in NewCalci.aspx.cs file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
namespace Session_WebService1
{
public partial class NewCalci : System.Web.UI.Page
{
// instantiate the web service proxy
Service1 CalciService = new Service1();
protected void BtnAdd_Click(object sender, EventArgs e)
{
double var1 = Convert.ToDouble(TxtValue1.Text);
double var2 = Convert.ToDouble(TxtValue2.Text);
// call the add method
TxtResult.Text = Convert.ToString(CalciService.Add(var1, var2));
}
protected void BtnSub_Click(object sender, EventArgs e)
{
double var1 = Convert.ToDouble(TxtValue1.Text);
double var2 = Convert.ToDouble(TxtValue2.Text);
// call the Sub method
TxtResult.Text = Convert.ToString(CalciService.Sub(var1, var2));
}
protected void BtnMul_Click(object sender, EventArgs e)
{
double var1 = Convert.ToDouble(TxtValue1.Text);
double var2 = Convert.ToDouble(TxtValue2.Text);
// call the Mul method
TxtResult.Text = Convert.ToString(CalciService.Mult(var1, var2));
}
protected void BtnDiv_Click(object sender, EventArgs e)
{
double var1 = Convert.ToDouble(TxtValue1.Text);
double var2 = Convert.ToDouble(TxtValue2.Text);
// call the Div method
TxtResult.Text = Convert.ToString(CalciService.Div(var1, var2));
}
protected void BtnPow_Click(object sender, EventArgs e)
{
double var1 = Convert.ToDouble(TxtValue1.Text);
double var2 = Convert.ToDouble(TxtValue2.Text);
// call the Power method
TxtResult.Text = Convert.ToString(CalciService.Pow(var1, var2));
}
protected void BtnClear_Click(object sender, EventArgs e)
{
TxtValue1.Text = "";
TxtValue2.Text = "";
TxtResult.Text = "";
}
}
}
5) Run the Web service by pressing F5,Check the reult.
Alert Moderator
Bookmark It
Comments or Responses
Login to post response
Latest Code Snipptes
writing Custom pagination html code in python and django
Code snippet for setInterval
Azure Function - Connect to MS Dynamics using application user - .NET core 3.1
MS Dynamics 365- Custom action - Read input parameter values from plugin
MS Dynamics 365- Disassociate record from N-N relationship entity
Search box with icon in Navbar in bootstrap 4
Remove HTML tags using Regular Expression in C#
MS Dynamics 365- Close Quote from C# / Custom action
How to show and hide submenu in tabs using jquery
More ...