Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

the type or namespace name 'webmethod' could not be found

I'm using jquery, ajax, & .net to call a method. I see lots of examples on the net saying to put [Webmethod] above the method but I'm keeping getting the error the type or namespace name 'webmethod' could not be found. I have put "using System.Web.Services;" at the top. What else needs to be done?

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

public partial class _Default : System.Web.UI.Page
{

[WebMethod]
public static string GetDate()
{
    return DateTime.Now.ToString();
}
}
like image 625
thegunner Avatar asked Nov 07 '10 14:11

thegunner


People also ask

What is WebMethod in C#?

The WebMethod attribute is added to each method we want to expose as a Web Service. ASP.NET makes it possible to map traditional methods to Web Service operations through the System. Web. Services. WebMethod attribute and it supports a number of properties that control the behavior of the methods.

What is WebMethod attribute?

The WebMethod attribute has properties that are used to configure the behavior of the specific web method. Here is the syntax: [WebMethod(PropertyName=value)] PropertyName is a valid property accepted by the WebMethod attribute (these are described below), and value is the value to be assigned to that property.

What is WebMethod in VB net?

The WebMethod will be called using ASP.Net AJAX PageMethods. ASP.Net AJAX ScriptManager allows you to call Server Side ASP.net methods from client side without any PostBack using PageMethods. Actually it is an AJAX call to the server but it allows us to call the method or function defined server side.


1 Answers

Add a reference to System.Web.Services.dll in your project.

It is most likely missing for you to be getting this error because you already have the correct using statement

like image 60
Jagmag Avatar answered Oct 19 '22 05:10

Jagmag