Visit Count using Webservices in Asp.net

Geetha.Katneni
Posted by Geetha.Katneni under ASP.NET category on | Points: 40 | Views : 2091
Creating Simple Visit Count Webservice
1)Go To Visual Studio 2010 -> New Project -> Select Asp.NET Web Service Application -> OK
2) In Service.asmx.cs write the [web method] for Visit Count
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace 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
{


// Application Visit Count //

[WebMethod]
public int VisitCount()
{
if (Application["Visits"] == null)
{
Application["Visits"] = 1;
}
else
{
int i = (int)Application["Visits"];
i++;
Application["Visits"] = i;
}
return (int)Application["Visits"];

}
}
}

3)Run the Webservice by pressing F5 ,VisitCount service will be displayed

4)Click on "Visit Count" webservice and " Invoke " it to get the result
5)As you visited first time "1" will be displayed as Output.
6.When you run the same service again and invoke Visit Count you will get output "2" as you are visited second time.(i.e. when ever you invoke the service visit count get incremented )

Comments or Responses

Login to post response