Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
when we create [WebMethod] in web services then it should be static or non static what is the concept?
Posted

1 solution

It should be static as the web method is stateless.
 
Share this answer
 
Comments
Member 12060581 9-Dec-15 23:15pm    
This is the example of Code Project.
Static ?????

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

[WebService(Namespace= "http://tempuri.org/")]
[WebServiceBinding(ConformsTo= WsiProfiles.BasicProfile1_1)]
// 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 Service : System.Web.Services.WebService
{
public Service ()
{

//Uncomment the following line if using designed components
//InitializeComponent();
}

[WebMethod]
public int Area(int l, int b)
{
return l * b;
}

[WebMethod]
public int Perimeter(int l, int b)
{
return 2 * (l +b);
}
}
F-ES Sitecore 10-Dec-15 4:00am    
Sorry, my original answer wasn't very accurate, my head was stuck thinking about web sites. If the webmethod is being called by the ajax framework on a webpage as a "page method" it should be static. If the webmethod is part of an asmx web service then it doesn't.
Member 12060581 10-Dec-15 7:04am    
Thanx for your reply

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900