2010-07-01 60 views
4

我試圖在我的網站上實現視圖跟蹤Web服務。我使用的是JavaScript,因爲我想從我的跟蹤視圖中排除任何搜索漫遊器。問題是,當我嘗試使用jQuery發佈到我創建的Web服務時,出現「未知Web方法」錯誤。調用共享WebMethod時未知的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。參數名稱:方​​法名稱

我已經做了幾百次(看似),但我只是不能看到我失蹤。我敢肯定,這是一個小...

+0

我最終刪除了這個Web服務,並開始一個新的,並且該Web服務工作。不過,我仍然對這個爲什麼不起作用感興趣。 – 2010-07-01 14:57:40

回答

7

您不能在Web服務中使用Shared(在C#中static)方法。您可能會考慮在ASPX頁面中將靜態方法用作「頁面方法」。在獨立的ASMX Web服務中,您只能使用實例方法。

相關問題