调用共享WebMethod时出现未知Web方法exception

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

$(document).ready(function() { $.ajax({ type: "POST", url: '', data: "{'itemType': 'thread', 'itemId':}", contentType: "application/json; charset=utf-8" }); }); 

这是Web服务。

 Imports System.Web.Services Imports System.Web.Services.Protocols Imports System.ComponentModel  _  _  _  _ Public Class ItemViewTrackingService Inherits System.Web.Services.WebService  _ 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。 参数名称:methodName

我已经完成了数百次(看似),但我看不出我错过了什么。 我确定它很小……

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