【问题标题】:Service method name is not valid. from Hosted server服务方法名称无效。从托管服务器
【发布时间】:2014-09-28 22:45:46
【问题描述】:

我收到了这个错误

System.InvalidOperationException:ManageUser Web 服务方法名称 无效。在 System.Web.Services.Protocols.HttpServerProtocol.Initialize() 在 System.Web.Services.Protocols.ServerProtocolFactory.Create(类型类型, HttpContext 上下文,HttpRequest 请求,HttpResponse 响应, 布尔值&中止处理)

当我尝试使用 ajaxcall 从按钮单击事件中调用 Web 服务方法时

$.ajax() {
    type: "POST",
    url: "RechargeService.asmx/ManageUser",
    //data: "{objUser: " + JSON.stringify(objUsers) + "}",
    data: "{Name:'" + Name + "',Address:'" + Address + "',City:'" + City + "',State:'" + State + "',Pincode:'" + Pincode + "',MobileNo:'" + MobileNo + "',Email:'" + Email + "',Password:'" + Password + "',Parameter:'" + Parameter + "',UserRole:'" + UserRole + "',UserStatus:'" + UserStatus + "'}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    async: false,
    cache: false,
    success: function (data) {
        data = JSON.parse(data.d);
        if (data.Sucess) {
            $("#lblMsg").html('Registration done successfully');
            $("#txtEmail").val('');
            $("#txtPassword").val('');
            $("#txtMobileNo").val('');
            $("#txtConfirmPassword").val('');
            $('#myModal1').hide();
            alert("Your registration completed successfully");
        } else {
            alert("Already registered with this email id");
            $("#txtEmail").val("");
        }
    },
    error: function (xhr, status, error) {
        alert(xhr.responseText + " \n " + status + " \n " + error);

        alert("There was an error while processing. Please try again after some time.");
    }
}

方法

[WebMethod] 
Public string ManageUser()
{

}

此代码在托管后在本地运行良好,只有我得到上述错误请帮助我解决这个问题.. 提前致谢

【问题讨论】:

  • jquery ajax 括号无效。检查jquery ajax
  • 在本地查看它的工作正常我的意思是开发环境括号很好我检查了......只有在托管后我才得到上述错误..我们需要对托管服务器进行任何更改

标签: c# jquery ajax web-services


【解决方案1】:

这可能是由于您的 WebMethod 中有 null 值参数。

例如:

public string GetDocument(int templateId, int? loginId = null)

...应该改成这样:

public string GetDocument(int templateId, int loginId)

【讨论】:

  • 但您没有为您的主张提供任何支持。这是为什么?你能链接一个来源吗?
  • @MMalke 来自个人经验。我总是对我个人遇到并解决的问题给出答案。
【解决方案2】:

可能的原因 1: 你有没有在服务类上面添加这个

[System.Web.Script.Services.ScriptService]

可能的原因 2: 数据也应该有参数名称的单引号

data:{'Name':'" + Name + "','Address':'" + Address + "'}

【讨论】:

    【解决方案3】:

    ajax 函数中缺少括号() 应该是这样的

    $.ajax({ 
         //Your Code...
    });
    

    试试这个...

    【讨论】:

    • 我检查过...仍然面临同样的问题
    • 我检查了同样的问题..我在 webconfig 中添加了协议,所有来自网络的东西,但仍然面临错误
    • @Muthu 检查 web.config 中的有效处理程序映射
    • @Muthu 你可以参考这里:asp.net/ajax/documentation/live/…
    • httphandlers 和 httpmodules 都很好。我在我的本地 iis 中托管它的工作正常。但是当我只在我的域服务器中托管时,我收到了这个错误。。
    猜你喜欢
    • 2012-08-06
    • 2017-04-07
    • 1970-01-01
    • 2014-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-02
    • 1970-01-01
    相关资源
    最近更新 更多