【问题标题】:The server method 'methodname' failed服务器方法“方法名”失败
【发布时间】:2010-12-20 18:54:24
【问题描述】:

从 javascript 调用 WebService/C# 时出现奇怪的错误。

服务器方法“GetGoogleToken”失败。 没有细节,没有堆栈跟踪。 在服务器上,我设置了断点 - 一切正常,我正在返回字符串(还有什么更简单的?)

此外,当我使用浏览器测试环境调用该方法时,该方法工作正常。

方法如下:

[WebMethod]
public string GetGoogleToken(string login, string password)
{
    try
    {
        string token = string.Empty;
        if (!String.IsNullOrEmpty(login) && !String.IsNullOrEmpty(password))
        {
            ContactsService service = new ContactsService("...");
            service.setUserCredentials(login, password);
            token = service.QueryAuthenticationToken();
        }

        return token;
    }
    catch (Exception ex)
    {
        // no errors happening on server side
        throw new ApplicationException("Error in GetGoogleToken", ex);
    }
}

我的班级属性:

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]

我的javascript:

Namespace.WebServices.ContactsImport.GetGoogleToken(login, password, ImportGoogle.authenticated, OnAjaxRequest_Error);

我还注意到,该错误发生在服务器返回结果之前。 (例如我有断点)

【问题讨论】:

    标签: javascript asp.net-ajax web-services


    【解决方案1】:

    问题的原因很有趣 - html 集成器将 runat="server" 放在按钮上,它正在生成这个 Javascript 调用。 结果,microsoft javascript 正在重新加载页面,并且它不期望来自 web 服务的任何结果。

    【讨论】:

    • 谢谢。我有一个类似的问题。我有一个类型为提交而不是按钮的输入,在 Chrome 上,它正在触发回发。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-18
    • 1970-01-01
    • 1970-01-01
    • 2011-01-14
    • 1970-01-01
    • 2013-10-26
    • 2017-10-05
    相关资源
    最近更新 更多