| Previous | Home | Next |
Step 1: Open a new Web Site and click on
ASP.Net Web Services press on OK as shown below in fig.
Step 2: The code (Service.cs) written for Calculating Age , Calculate Factorial and Square Root of a Number.
using System;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{[WebMethod (Description="Calculating Age")]
public string calAge(DateTime date)
{ DateTime nowDate = System.DateTime.Now;
System.TimeSpan span = nowDate - date;
int days = (int)span.TotalDays;
int yea = days / 365;
string age = yea.ToString() + " years ";
return age;}
[WebMethod(Description = "Calculating SquareRoot")]
public double calSquareRoot(int a)
{ double i = 0;
double x1, x2=0;
while ((i * i) <= a)
i += 0.1;
x1 = i;
for (int j = 0; j < 10; j++)
{ x2 = a;
x2 /= x1;
x2 += x1;
x2 /= 2;
x1 = x2;}
return x2;}
[WebMethod(Description = "Calculating Factorial")]
public double calFactorial(int a)
{if (a == 0)return 1;
else return (a*calFactorial(a-1));}}
Step 3: Debug The service

Step 4: To use this service, go to your project solution right click and click on Add Web Reference. A new window open



To know more click Here
using localhost;
Click on Add Reference, The service will be added in your web site. It will be show on your page like below fig.

| Previous | Home | Next |