web services - jquery invoke 500 InternalServerError -
but on our production server. works great in every other environment. web service runs fine on production, don't understand what's (apparently) corrupting exception throw in production.
first, jquery. when checkbox checked, call web service try call "token assignment":
if (chk.is(":checked")) { chk.invoke('assigntoken', params, function () { //go tree category, down header find count. var spntokencount = $this.closest('.category').find('.tokencount'); var tokencount = 1; if (!isnan(spntokencount.text())) { tokencount = parseint(spntokencount.text()); tokencount--; spntokencount.text(tokencount.tostring()); } if (tokencount == 0) { $this.closest('.category').find('.spnavailable').hide(); $this.closest('.category').find('.spnpurchase').show(); //let's find unchecked elements , not allow them selected. $this.closest('table').find('.tokenassignment').find('input:checkbox').each(function (index, element) { if (!element.checked) { element.disabled = true; } }); } }, function (xhr, textstatus, error) { chk.attr('checked', false); var response = ''; eval('response = ' + xhr.responsetext); if (response.exceptiontype == 'xxx.tokenassignmentexception') { alert('token assignment failed, may out of tokens.'); } else { alert('token assignment error.'); //alert('token unassignment failed\n\n' + response.exceptiontype + '\n' + response.message + ':\n' + response.stacktrace); } } );
in base page, have following webmethod:
[webmethod] public static void assigntoken(int accountid, int courseid, int studentid, string studenttype, guid userid) { try { coursetoken ct = coursetokenfactory.assigntoken(accountid, courseid, studentid, studenttype, userid); if (ct == null) { logger.error("token assignment attempt failed " + accountid.tostring() + ", course " + courseid.tostring() + ", student " + studentid.tostring() + " of type " + studenttype); throw new tokenassignmentexception("token assignment attempt failed."); } } catch (exception ex) { logger.error("failed trying assign token account " + accountid.tostring() + ", course " + courseid.tostring() + ", student " + studentid.tostring() + " of type " + studenttype, ex); throw; } }
we see both log messages getting written, web service acting appropriately (in case. getting null coursetoken factory means didn't find 1 available assigned).
as can see in jquery error handling method, check response's exceptiontype type of exception threw in case, , give little more friendly error.
however, on production, xhr.responsetext turned "there error processing request", exceptiontype of empty string. in other environments, xhr.responsetext expect, exceptiontype being fully-qualified class name ('xxx' anonymousization), , more-friendly error message.
i'm not sure how debug further. i've verified through log messages we're creating , throwing exception type expect, , firebug it's not in xhr object when gets client. (but in 1 environment).
or more fundamental problem approach? should, perhaps, webmethod returning boolean, or coursetoken got assigned, or (false/null indicate non-assignment) instead of specific exception type?
i'm not 100% sure answer, hate can't write paragraphs in response editor.
i can't take credit this, product manager (who likes geeky) found this: https://connect.microsoft.com/visualstudio/feedback/details/290881/exceptions-thrown-from-webmethods-are-swallowed-by-resthandler-when-httpcontext-iscustomerrorenabled-true
the difference is, have customerrors set remoteonly on production webserver, exception throw web service swallowed in environment.
i feel pretty confident being answer; rdp'd webserver, started browser there , hit production app exact same demo account we'd been testing browsers outside server.
got 'friendly' message, means xhr object maintained exceptiontype 1 web method threw because don't have custom errors locally.
so guess lesson here not use exception handle condition. i'll have rewrite service , 2 ajax good/error methods. make web method send bool or object/null or indicate assignment worked/not, , handle true exceptions in error handler.
Comments
Post a Comment