Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The server method 'methodname' failed

I have strange error when calling WebService/C# from javascript.

The server method 'GetGoogleToken' failed. No details, no stacktrace. On server, I set breakpoint - everything works smoothly and I am returing string (what could be simpler?)

Also, method works fine when i call it using browser test environment.

Here is method:

[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);
    }
}

My Class attributes:

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

my javascript:

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

I also noticed, that error happens BEFORE server returned result. (e.g. i have breakpoint)

like image 630
st78 Avatar asked Sep 07 '25 08:09

st78


1 Answers

Cause of problem was very funny - html integrator put runat="server" on button, which was generating this Javascript call. As a result, microsoft javascript was in process of page reload, and it wasn't expecting any results from webservices.

like image 126
st78 Avatar answered Sep 09 '25 05:09

st78