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 7089395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:55:00+00:00 2026-05-28T07:55:00+00:00

I have a asp.NET web service (not WCF but the classic .asmx one with

  • 0

I have a asp.NET web service (not WCF but the classic .asmx one with WebMethods) that throws exceptions. The exceptions all derive from one of two base exception classes (both of which derive from Exception):

public class InputException : Exception
{
   ....
}

public class FatalException : Exception
{
    ....
}

public class NoFilesFound: FatalException
{
   ....
}

....

The webservice right now throws the exception as needed. In my client code I can catch the exceptions and see the message like this:

Server was unable to process request. ---> There were no files found

However the exception is of type FaultException (as seen when I do .GetType() on the caught exception). The calling client needs to be able to differentiate between an InputException and a FatalException (and optimally differentiate between the individual derived ones but that’s not as important). Right now the only way to do so is to parse the message, strip the text before “—>” and switch on the text. That is clearly not optimal.

I know I can throw SoapExceptions with custom Code but I want to avoid that if possible. Furthermore it seems designed for those who deal with XML but all of our webservice code doesn’t touch XML as it’s deserialized for us already.

So in short, is there a way for me to throw custom exceptions from the webservice and for the calling client to be able to differentiate between the exceptions?

  • 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-28T07:55:00+00:00Added an answer on May 28, 2026 at 7:55 am

    The proper way to handle this is to use a SoapException. So you will basically catch all possible exceptions on the service and then translate them to a SoapException (the documentation I have linked to contains an example) and then instead of throwing some custom exception of yours throw this SoapException and include the information you are interested in the Detail XML node of the fault.

    Then when invoking the service on the client you will be able to catch this SoapException and analyze the Detail XML node to gather more details about the exact reason of the fault that occurred on the server.

    All this manual generation of fault nodes has been rendered very easy in WCF where you simply work with data contracts and catch FaultException<SomeFaultContract>.

    Let’s take an example. Suppose you have the following service method which throws a SoapException and provides details about the error in the Details node:

    [WebMethod]
    public string HelloWorld()
    {
        var doc = new XmlDocument();
        var node = doc.CreateNode(
            XmlNodeType.Element, 
            SoapException.DetailElementName.Name, 
            SoapException.DetailElementName.Namespace
        );
        // you could actually use any sub nodes here
        // and pass even complex objects
        node.InnerText = "no files found";
    
        throw new SoapException(
            "Fault occurred", 
            SoapException.ClientFaultCode, 
            Context.Request.Url.AbsoluteUri, 
            node
        );
    }
    

    when consuming it you could catch for this SoapException on the client:

    using (var client = new WebService1())
    {
        try
        {
            var result = client.HelloWorld();
        }
        catch (SoapException ex)
        {
            var detail = ex.Detail;
            // detail.InnerText will contain the detail message
            // as detail is an XmlNode if on the server you have
            // provided a complex XML you would be able to fetch it here
        }
    }
    

    As far as your InputException, FatalException and NoFilesFound exceptions are concerned, they are fine, but they should stay on the server. Catch them in your web method and build a proper SoapException that the client will be able to make sense of when consuming the service.

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

Sidebar

Related Questions

Interesting one here. I have an ASP.NET 1.1 project that contains a web service
I have a WCF web service that uses ASP.NET session state. WCF sets a
i have an ASP.NET web service that returning a custom entity object (Staff): [WebMethod]
I have an ASP.net web service that I'm using for a web application which
I have an ASP.NET web service running that accepts both HTTP POST and SOAP
I have an ASP.NET web service that I can access via a windows program
I have a windows forms client that consumes an ASP.net web service. It's my
I have a asp.net website and I am accessing that web service from my
I have created a WCF web service, i am calling it from ASP.NET 1.1
I have been building a Asp.net WCF web service with json format. Now I

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.