【问题标题】:Unknown Web Method Exception when Calling Shared WebMethod调用共享 WebMethod 时出现未知 Web 方法异常
【发布时间】:2011-03-10 16:14:26
【问题描述】:

我正在尝试在我的网站上实施视图跟踪网络服务。我使用 JavaScript 是因为我想从我的跟踪视图中排除任何搜索机器人。问题是当我尝试使用 jQuery 发布到我创建的 Web 服务时遇到“未知的 Web 方法”错误。

$(document).ready(function() {

  $.ajax({
    type: "POST",
    url: '<%=ResolveUrl("~/WS/ItemViewTrackingService.asmx/TrackItemView") %>',
    data: "{'itemType': 'thread', 'itemId':<%=mThread.ThreadID %>}",
    contentType: "application/json; charset=utf-8"
  });

});

这里是网络服务。

Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel

<System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class ItemViewTrackingService
  Inherits System.Web.Services.WebService

  <WebMethod(EnableSession:=True)> _
  Public Shared Sub TrackItemView(ByVal itemType As String, ByVal itemId As Int32)

    If itemType.Equals("column", StringComparison.OrdinalIgnoreCase) Then
      Services.ViewTrackingService.TrackColumnView(itemId)
    ElseIf itemType.Equals("thread", StringComparison.OrdinalIgnoreCase) Then
      Services.ViewTrackingService.TrackThreadView(itemId)
    End If

  End Sub

End Class

错误是 ASP .NET 错误:未知的 Web 方法 TrackItemView。参数名称:方​​法名

我已经这样做了数百次(似乎),但我就是看不出我错过了什么。我敢肯定这是小事......

【问题讨论】:

  • 我最终删除了这个 Web 服务并重新启动了一个新的,并且该 Web 服务正常工作。但是,我仍然对为什么这个不起作用感兴趣......

标签: jquery asp.net web-services asmx


【解决方案1】:

您不能在 Web 服务中使用 Shared(C# 中的 static)方法。您可能正在考虑将静态方法用作 ASPX 页面中的“页面方法”。在独立的 ASMX Web 服务中,您只能使用实例方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多