views:

104

answers:

1

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)

A: 

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.

Sergey Osypchuk