【问题标题】:the type or namespace name 'webmethod' could not be found找不到类型或命名空间名称“webmethod”
【发布时间】:2011-05-06 07:37:53
【问题描述】:

我正在使用 jquery、ajax 和 .net 来调用方法。我在网上看到很多例子说将 [Webmethod] 放在方法之上,但我一直收到错误,找不到类型或命名空间名称“webmethod”。我已经把“使用 System.Web.Services;”在顶部。还需要做什么?

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();
}
}

【问题讨论】:

    标签: web-services jquery asp.net-ajax asmx


    【解决方案1】:

    在您的项目中添加对System.Web.Services.dll 的引用。

    您很可能会收到此错误,因为您已经拥有正确的 using 语句

    【讨论】:

    • 我相信你的意思是写Using System.Web.Services;对我来说就像一个魅力谢谢。
    【解决方案2】:

    在页面顶部添加以下内容:

    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.Services;
    

    【讨论】:

      【解决方案3】:

      这个问题的简单答案是从 .net 框架文件夹中添加 system.web.services 的引用。

      示例:

      假设我有一个已被引用的项目 system.web.services

      现在,如果我右键单击 System.web.services

      您可以看到此程序集位于 .Net Path 中,因此您可以从那里轻松地在您的项目中添加对该程序集的引用。

      解决方案

      只需右键单击引用,选择添加引用单击选择管理器窗口的浏览器按钮转到路径并添加这样的引用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-07-12
        • 2011-05-13
        • 2013-03-25
        • 2012-06-19
        • 2017-11-29
        • 2012-09-27
        • 2013-01-07
        相关资源
        最近更新 更多