Introduction
I am creating a web service for performing arithmetic operations or say a
calculator. Then, I will use this service in a windows based application to perform
arithmetic operations like a calculator. So, let's create a web service. Follow
the given steps.
- Create new project
- Select ASP.NET Empty Web Application
- Give a name to your project and click ok button
- Go to Solution Explorer and right click at your project
- Select Add New Item and select Web Service application
- Give it name and click ok button
using
System;
using
System.Collections.Generic;
using
System.Linq;
using System.Web;
using
System.Web.Services;
namespace calc
{
///
<summary>
/// Summary
description for CalcWebService
///
</summary>
[WebService(Namespace =
"mycalculatorexample.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
CalcWebService : System.Web.Services.WebService
{
[WebMethod]
public string
calculate(string first,
string second, char sign)
{
string result;
switch (sign)
{
case
'+':
{
result = (Convert.ToInt32(first)
+ Convert.ToInt32(second)).ToString();
break;
}
case
'-':
{
result = (Convert.ToInt32(first)
- Convert.ToInt32(second)).ToString();
break;
}
case
'*':
{
result = (Convert.ToInt32(first)
* Convert.ToInt32(second)).ToString();
break;
}
case
'/':
{
result = (Convert.ToInt32(first)
/ Convert.ToInt32(second)).ToString();
break;
}
case
'%':
{
result = (Convert.ToInt32(first)
% Convert.ToInt32(second)).ToString();
break;
}
default:
result = "Invalid";
break;
}
return result;
}
}
}
Run the application.
Output:
Go to test page by clicking
at "calculate" -> do the entry and click the "invoke" button.




Digesh ModiPosted Sep 15, 2014, 8:28 AM
error this code
Raju KumarPosted Sep 16, 2012, 11:03 AM
1st check your code then post.Your love calculator is showing error.
Vijay PrativadiPosted Dec 26, 2011, 1:39 PM
Superbbbbb Alok !!! Good Going !!!