调用共享的WebMethod时未知的Web方法异常 [英] Unknown Web Method Exception when Calling Shared WebMethod

查看:1973
本文介绍了调用共享的WebMethod时未知的Web方法异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现我的网站视图跟踪Web服务。我使用JavaScript,因为我想从我的意见跟踪排除任何搜索机器人。现在的问题是,我得到一个未知Web方法的错误,当我尝试使用jQuery张贴到我创建的Web服务。

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"
  });

});

下面是Web服务。

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。参数名:方法名

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

推荐答案

您不能使用共享静态在Web服务在C#)方法。你也许会想使用静态方法作为在ASPX页面页面方法。在一个独立的ASMX Web服务时,您只能使用实例方法。

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.

这篇关于调用共享的WebMethod时未知的Web方法异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆