【问题标题】:How to solve Web Service method name is not valid.?如何解决 Web Service 方法名无效。?
【发布时间】:2021-04-01 19:27:45
【问题描述】:

我收到以下错误

System.InvalidOperationException: CheckPageAccess Web 服务方法名称无效。 在 System.Web.Services.Protocols.HttpServerProtocol.Initialize() 在 System.Web.Services.Protocols.ServerProtocolFactory.Create(类型类型,HttpContext 上下文,HttpRequest 请求,HttpResponse 响应,Boolean& abortProcessing)

我的网络方法

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public void CheckPageAccess(string userid, Pages PageNo, bool IsPresentApprover = false)
{

Ajax 请求

this.CheckPageAccess = function (UserID) {                         
    var response = $http({
        url: "WebServicenName.asmx/CheckPageAccess",
        dataType: 'json',
        params: { 'userid': UserID, 'PageNo': PageNo, 'IsPresentApprover': IsPresentApprover},
        contentType: 'application/json;charset=utf-8',
        method: 'GET',
        async: true,
        cache: false,
        headers: { 'Accept': 'application/json', 'Pragma': 'no-cache' },
    });
    return response;
}

这在调试模式下工作正常,但是当我发布上面的 web 方法时不会显示在托管链接中。

【问题讨论】:

  • 不要粘贴错误图片。
  • 听起来好像没有上传文件,App_Code 文件夹中的 .asmx 或 .cs 文件。上面的名字改了吗?如果你没有,看起来像一个错字。 (WebServicenName 中的 2 个 n。)
  • $http 有效吗?尝试使用$.ajax({...

标签: c# asp.net ajax asmx


【解决方案1】:

从命令行运行aspnet_regiis -i

C:\Windows\Microsoft.NET\Framework64\v4.0.30319>aspnet_regiis -i

如果问题仍然存在,请将以下代码添加到system.webServer > handlers下的第一行

<add name="ScriptHandlerFactory" path="*.asmx" verb="*" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" modules="ManagedPipelineHandler" scriptProcessor="" resourceType="Unspecified" requireAccess="Script" allowPathInfo="false" preCondition="integratedMode" responseBufferLimit="4194304"/>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-01
    • 1970-01-01
    • 2018-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-06
    • 2013-05-08
    相关资源
    最近更新 更多