4

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...

1
  • I ended up deleting this web service and starting a new one fresh, and that web service worked. However, I'm still interested in why this one didn't work... Commented Jul 1, 2010 at 14:57

1 Answer 1

7

You cannot use a Shared (static in C#) method in a web service. You may be thinking of the use of static methods as "page methods" in an ASPX page. In a standalone ASMX web service, you can only use instance methods.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.