I'm trying to implement a view tracking web service on my website. I'm using JavaScript because I want to exclude any search bots from my tracked views. The problem is I'm getting a "Unknown web method" error when I try to use jQuery to post to the web service I've created.
$(document).ready(function() {
$.ajax({
type: "POST",
url: '<%=ResolveUrl("~/WS/ItemViewTrackingService.asmx/TrackItemView") %>',
data: "{'itemType': 'thread', 'itemId':<%=mThread.ThreadID %>}",
contentType: "application/json; charset=utf-8"
});
});
Here is the web service.
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
The error is an ASP .NET error: Unknown web method TrackItemView. Parameter name: methodName
I've done this hundreds of times (seemingly), but I just can't see what I'm missing. I'm sure it's something small...