10

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();
}
}
John Saunders
  • 160,644
  • 26
  • 247
  • 397
thegunner
  • 6,883
  • 30
  • 94
  • 143

3 Answers3

16

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

Jagmag
  • 10,283
  • 1
  • 34
  • 58
  • 7
    I believe you mean just write `Using System.Web.Services;` works like a charm for me thanks. – Anicho Oct 21 '11 at 09:35
2

Add the following on top of the page:

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
Shubh
  • 6,693
  • 9
  • 48
  • 83
JCVA
  • 31
  • 1
1

Simple answer to this question is to just Add reference of system.web.services from .net framework folder.

Example:

Consider I have a project which is already referenced system.web.services

Now If I right click on System.web.services

You can see that this assembly is inside .Net Path so you can easily add reference of this assembly in your project from there.

enter image description here

Solution

Just right click on references ,select add reference click browser button of selection manager window go to path and add references like this.

enter image description here