通过 Javascript 使用 C# 实现 Web 服务方法
我正在尝试通过 javascript & 从 .aspx 页面调用 Web 服务方法我收到此错误,我在 C# 方法的顶部确实有 [WebMethod]。 未知的 Web 方法 [object Object]。
参数名称:methodName
<h2> <i>Unknown web method [object Object].<br>Parameter name: methodName</i> </h2></span>
描述:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。
<br><br>
<b> Exception Details: </b>System.ArgumentException: Unknown web method [object Object].<br>Parameter name: methodName<br><br>
[ArgumentException]: Unknown web method [object Object].
Parameter name: methodName
at System.Web.Script.Services.WebServiceData.GetMethodData(String methodName)
at System.Web.Script.Services.RestHandler.CreateHandler(WebServiceData webServiceData, String methodName)
at System.Web.Script.Services.RestHandler.CreateHandler(HttpContext context)
at System.Web.Script.Services.RestHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated)
at System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated)
at System.Web.HttpApplication.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
I am trying to call a webservice method from .aspx page thro' javascript & i get this error, i do have [WebMethod] on the top of the c# method.
Unknown web method [object Object].
Parameter name: methodName
<h2> <i>Unknown web method [object Object].<br>Parameter name: methodName</i> </h2></span>
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.
<br><br>
<b> Exception Details: </b>System.ArgumentException: Unknown web method [object Object].<br>Parameter name: methodName<br><br>
[ArgumentException]: Unknown web method [object Object].
Parameter name: methodName
at System.Web.Script.Services.WebServiceData.GetMethodData(String methodName)
at System.Web.Script.Services.RestHandler.CreateHandler(WebServiceData webServiceData, String methodName)
at System.Web.Script.Services.RestHandler.CreateHandler(HttpContext context)
at System.Web.Script.Services.RestHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated)
at System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated)
at System.Web.HttpApplication.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1 - 我认为你的答案就在那里:
如何在 Firefox 3.0 的 Javascript 中调用 Web 服务
它说明了 [System.Web.Script.Services.ScriptService()] 的使用
使用非常简单和干净的代码和风格。
2 - 或者,您可以使用 jQuery,如本答案所示:
如何使用 jQuery 调用 ASP.NET网络服务?
1 - I think that your answer is there:
How to call webservice in Javascript for Firefox 3.0
It illustrates the use of [System.Web.Script.Services.ScriptService()]
using a very easy and clean code and style.
2 - Alternativelly, you could use jQuery as illustrated in this answer:
How to use jQuery to call an ASP.NET web service?