Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7613451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:09:30+00:00 2026-05-31T02:09:30+00:00

I’ve a few web methods that I use to call some external services like

  • 0

I’ve a few web methods that I use to call some external services like the Google Calendar API, obviously these can be extremely brittle.

Unfortunately I now realise that any error thrown on these methods are not causing an exception to bubble up to Global.asax which is where errors are getting logged in this application.

I have seen suggestions to wrap the method in a try/catch, which is a stupid way of doing it as there are a variety of errors that ASP.Net will silently swallow still.

In trying to find a solution I’ve seen a lot of references to SoapExtension, which is exactly what I want to do but doesn’t get fired as I’m returning Json. What I really want is a way to catch the error just like that.

Any pointers appreciated, I still can’t understand how the ASP.Net team could have thought that silently swallowing errors like this was a bright idea.

So for example a method like this:

    [WebMethod]
    [ExceptionHandling] //can I write a handler like this to catch exceptions from JSON webservices?
    static public void DeleteItem(string id)
    {
        var api = new GoogleCalendarAPI(User.InternalUser());
        api.DeleteEvent(id);
        return "success";
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T02:09:31+00:00Added an answer on May 31, 2026 at 2:09 am

    There is no equivalent to SoapExtension for JSON WebMethods and having custom errors turned on in your production site will result in a generic error message being returned to the client, no error is ever raised on the server. You cannot circumvent this.

    If you inspect the code using something like ILSpy, there is no way to pass a method or class to page WebMethods like SoapExtension. The error is swallowed by ASP.Net as it invokes the web method, the only notification you will get is a HTTP 500 error sent to the client with a total generic error message.

    In 4.0, WebMethods get called by this:

    // System.Web.Script.Services.RestHandler
    internal static void ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)
    {
        try
        {
            //snip irrelevant code
            RestHandler.InvokeMethod(context, methodData, rawParams);
        }
        catch (Exception ex)
        {
            RestHandler.WriteExceptionJsonString(context, ex);
        }
    }
    

    So if invoking your method throws an error it will call the following code with a statusCode of 500, there’s no re-throw in there and nothing else you can pass in called so unless I’m being blind it just gets swallowed silently. Even worse if you’ve got custom errors turned on, which any sane person will, it’ll completely obfuscate the original cause:

    // System.Web.Script.Services.RestHandler
    internal static void WriteExceptionJsonString(HttpContext context, Exception ex, int statusCode)
    {
        //snip code setting up response
        context.Response.TrySkipIisCustomErrors = true;
        using (StreamWriter streamWriter = new StreamWriter(context.Response.OutputStream, new UTF8Encoding(false)))
        {
            if (ex is TargetInvocationException)
            {
                ex = ex.InnerException;
            }
            if (context.IsCustomErrorEnabled)
            {
                streamWriter.Write(JavaScriptSerializer.SerializeInternal(RestHandler.BuildWebServiceError(AtlasWeb.WebService_Error, string.Empty, string.Empty)));
            }
            else
            {
                streamWriter.Write(JavaScriptSerializer.SerializeInternal(RestHandler.BuildWebServiceError(ex.Message, ex.StackTrace, ex.GetType().FullName)));
            }
            streamWriter.Flush();
        }
    }
    

    I can’t see a way around it, looks like WebMethod is not ready for production code, shame.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.