Introduction: Function overloading means more than one function with same name and different parameters. In this article, I have used the concept of function overloading and created a web service to check the amount of users depending on different parameters. First we create a Database and insert some records in Database table.
Creating Database:
create
table transreport
(
id int,
TranType varchar(10),
TransactionDate date,
Amount money
)
Now insert some values in
transreport table.(I
am executing select command to show some record of my Database table. So that I
have used the record in the code.)
select
* from
transreport
Creating Web Service:
Create ASP.NET Web Service
page and write the following code in the .asmx.cs file.
using
System;
using
System.Collections.Generic;
using System.Linq;
using System.Web;
using
System.Web.Services;
using
System.Data.SqlClient;
using System.Data;
namespace
WebService1
{
///
<summary>
///
Summary description for Service1
///
</summary>
[WebService(Namespace =
"http://tempuri.org/")]
[WebServiceBinding(ConformsTo =
WsiProfiles.None )]
[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
{
//(MessageName = "methodofaddingthreeinteger",Description="bb")
[WebMethod(MessageName="TotalAmount",Description="Know
Yout Total Amount")]
public double
amount(int accno)
{
SqlDataAdapter da=new
SqlDataAdapter("select
sum(Amount) as Total,TranType from transreport where id="+accno+"
group by TranType order
by TranType desc",@"Data
Source=SERVER_NAME;Initial Catalog=EMP;Integrated Security=True");
DataSet ds=new
DataSet();
da.Fill(ds);
double i = double.Parse(ds.Tables[0].Rows[0][0].ToString());
double j =
double.Parse(ds.Tables[0].Rows[1][0].ToString());
return i - j;
}
[WebMethod(MessageName =
"AmountBetweentwoDates",Description="checked
Your Amount Between Dates")]
public DataSet amount(int accno,
string startdate, string enddate)
{
SqlDataAdapter da =
new SqlDataAdapter("select
* from transreport where id="+accno+" and
transactiondate between '"+startdate+"' and
'"+enddate+"' ",
@"Data Source=SERVER_NAME;Initial Catalog=EMP;Integrated
Security=True");
DataSet ds = new
DataSet();
da.Fill(ds);
return ds;
}
}
}
Run the service.
Output:

Click on amount to check it's working. A new page will be open. Write the accno, startdate and end date (It is basically for showing total transaction between two dates). 
Click at Invoke to invoke the method. It will show the record.





Join the conversation! Your thoughts help the community grow.