在研究这个问题时,大多数SO问题都是关于该static
方法作为修复.
因为它不使用真正的(有点复杂的)WebMethod我刚刚创建了一个简单的,以便检查是否可以达到方法本身.
[WebMethod] [ScriptMethod(UseHttpGet = false)] public static string HelloWorld() { return "Hello World!"; }
电话.
它总是归结为 500 (Internal Server Error)
Unknown web method HelloWorld. Parameter name: methodName Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ArgumentException: Unknown web method HelloWorld. Parameter name: methodName
为什么这会失败?
我也有这个问题,但稍微不同的是我在.asmx文件中使用了这个方法,因此遇到了"静态"问题,但是以不同的方式.
如果你有一个方法作为你的Page类的一部分,它必须是static
.
如果你已经把一个方法的.asmx文件跨页使用,它不能是static
.
我在实际的.aspx文件中遇到了问题
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="xxx.xxx.cs" Inherits="xxx.xxx" %>
代码中没有出现.它是如何改变的?我不知道 :(.