gpt4 book ai didi

c# - 未知的网络方法。参数名称 : methodName

转载 作者:IT王子 更新时间:2023-10-29 04:22:35 26 4
gpt4 key购买 nike

在研究这个问题时,大多数 SO 问题都是关于作为修复的 static 方法。

因为它不能与真正的(并且有点复杂)WebMethod 一起工作,我只是创建了一个简单的 WebMethod 来检查是否可以到达该方法本身。

[WebMethod]
[ScriptMethod(UseHttpGet = false)]
public static string HelloWorld()
{
return "Hello World!";
}

电话。

<script>
$(document).ready(function () {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "usersWebMethods.aspx/HelloWorld",
dataType: "json",
success: function (data) {
alert(data.d);
}
});
});
</script>

它总是归结为 500(内部服务器错误)

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 .

关于c# - 未知的网络方法。参数名称 : methodName,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20735178/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com